lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Moray McConnachie (JIRA)" <>
Subject [jira] Created: (LUCENENET-170) BooleanClause serialization fails owing to issues with serializing Occur object
Date Fri, 23 Jan 2009 20:59:59 GMT
BooleanClause serialization fails owing to issues with serializing Occur object

                 Key: LUCENENET-170
             Project: Lucene.Net
          Issue Type: Bug
            Reporter: Moray McConnachie

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");


            Console.WriteLine("press enter to close");

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message