Uploaded image for project: 'Lucene.Net'
  1. Lucene.Net
  2. LUCENENET-170

BooleanClause serialization fails owing to issues with serializing Occur object

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • None
    • None

    Description

      Essentially when you serialize a BooleanClause you lose all Occurs objects, so you cannot meaningfully serialize and deserialize BooleanQuery s with multiple clauses unless they all use the default Occur.SHOULD

      I suspect this bug extends to all objects depending on Parameter object, making it impossible to serialize and deserialize objects which include members inheriting from Parameter.

      I don't know enough about how the Parameter object ought to work or is used elsewhere to attempt a fix. I have a hack which works for my app by intercepting Serialize and Deserialize and serializing the occur member of BooleanClause to a string and Deserializing it the same way, but this is deeply suboptimal.

      Here is some test code for a Console application. Sorry about the formatting, this bug tracker seems not to like it too much.

      If the two queries don't match the bug is still in evidence.


      {{
      using System;
      using System.Collections.Generic;
      using System.IO;
      using System.Linq;
      using System.Runtime.Serialization.Formatters.Binary;
      using System.Text;
      using Lucene.Net.Search;

      namespace TestSerialization

      {

      class Program
      {
      static void Main(string[] args)

      { //build our sample query BooleanQuery queryPreSerialized = new BooleanQuery(); queryPreSerialized.Add(new TermQuery(new Lucene.Net.Index.Term("country","Russia")),BooleanClause.Occur.MUST); queryPreSerialized.Add(new TermQuery(new Lucene.Net.Index.Term("country","France")),BooleanClause.Occur.MUST); Console.WriteLine("Query pre serialisation: " + queryPreSerialized.ToString()); //now serialize it BinaryFormatter serializer = new BinaryFormatter(); MemoryStream memoryStream = new MemoryStream(); serializer.Serialize(memoryStream, queryPreSerialized); //now deserialize memoryStream.Seek(0, SeekOrigin.Begin); BooleanQuery queryPostSerialized = (BooleanQuery)serializer.Deserialize(memoryStream); Console.WriteLine("Query post deserialization: "+ queryPostSerialized.ToString()); if (!queryPreSerialized.Equals(queryPostSerialized)) Console.WriteLine("Serialized and deserialized do not match - down to issues with the way Parameter objects (in BooleanClause.Occur are maintained"); memoryStream.Close(); Console.WriteLine("press enter to close"); Console.Read(); }


      }
      }
      }}

      Attachments

        1. Parameter v2.patch
          0.8 kB
          Digy
        2. Parameter.patch
          0.6 kB
          Digy

        Activity

          People

            digydigy Digy
            rmcubed Moray McConnachie
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: