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

Serialized queries function unreliably

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • None
    • None
    • Current trunk, standard .NET environment, Visual Studio 2008.

    Description

      I've just tried slotting in current trunk in place of 2.3.1 we were using previously. Everything appears to compile and work OK, but the results are not correct when we introduce query serialization.

      Executing a simple BooleanQuery: +titling:Russia

      Results returned from query when not serialised: 3878 (correct)

      Results returned when query serialised deserialized and run with same Searcher: 3879

      Results returned when query serialised deserialized and run with new Searcher: 3

      Last time we had an issue with serialized queries and filed a bug report (https://issues.apache.org/jira/browse/LUCENENET-170), it was an issue with the serialization of Parameter on which Occur depends, but Parameter looks still to have the patch in as far as I can tell.

      Test code

      string IndexPath=@"C:\SourceSafeWork\OxanOxweb\LuceneAndSearch\TEST\LuceneIndexWithFullTextSince2004";

      //setup first query

      BooleanQuery lucQuery = new BooleanQuery();
      lucQuery.Add(new BooleanClause(new TermQuery(new Lucene.Net.Index.Term("titling","russia")),BooleanClause.Occur.MUST));

      //serialize and deserialize
      BinaryFormatter bf = new BinaryFormatter();
      System.IO.MemoryStream ms = new System.IO.MemoryStream();
      bf.Serialize(ms, lucQuery);
      ms.Seek(0, System.IO.SeekOrigin.Begin);
      Query lucQuery2 = (Query)bf.Deserialize(ms);
      ms.Close();

      //get hit counts for 2 searches

      IndexSearcher searcher = new IndexSearcher();
      int hitCount = searcher.Search(lucQuery, 20).totalHits; //3878 hits

      //bizarrely if I do not close the searcher and reopen the hit count is only 1 different i.e. 3879
      searcher.Close();
      searcher = new IndexSearcher(@IndexPath);

      int hitCount2 = searcher.Search(lucQuery2, 20).totalHits; //3 hits

      if (hitCount != hitCount2)
      MessageBox.Show("Error in serialisation - different hit count");

      Attachments

        1. Term.patch
          2 kB
          Digy
        2. TestSupportClass.patch
          3 kB
          Digy
        3. TestSupportClass.patch
          3 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: