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

NullReferenceException in DrillSideways.Search - ReqExclScorer.GetCost

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • Lucene.Net 4.8.0
    • None
    • Lucene.Net.Facet
    • None

    Description

      We have migrated all our Lucene 3.0 code to Lucene 4.8. However
      when searching with DrillSideways.Search we sometimes get a NullReferenceException with this stacktrace:

      System.NullReferenceException: Object reference not set to an instance of an object.
      at Lucene.Net.Search.ReqExclScorer.GetCost() in C:\BuildAgent\work\b1b63ca15b99dddb\src\Lucene.Net\Search\ReqExclScorer.cs:line 148
      at Lucene.Net.Facet.DrillSidewaysScorer.Score(ICollector collector, Int32 maxDoc) in C:\BuildAgent\work\b1b63ca15b99dddb\src\Lucene.Net.Facet\DrillSidewaysScorer.cs:line 139
      at Lucene.Net.Search.IndexSearcher.Search(IList`1 leaves, Weight weight, ICollector collector) in C:\BuildAgent\work\b1b63ca15b99dddb\src\Lucene.Net\Search\IndexSearcher.cs:line 649
      at Lucene.Net.Facet.DrillSideways.Search(DrillDownQuery query, ICollector hitCollector) in C:\BuildAgent\work\b1b63ca15b99dddb\src\Lucene.Net.Facet\DrillSideways.cs:line 194
      at Lucene.Net.Facet.DrillSideways.Search(ScoreDoc after, DrillDownQuery query, Int32 topN) in C:\BuildAgent\work\b1b63ca15b99dddb\src\Lucene.Net.Facet\DrillSideways.cs:line 249

      I managed to reproduce this in an unit test. If you add this unit test for example to TestDrillSideways.cs it will throw a NullReferenceException when running. This unit test should give 0 results because the criteria "Age != 23 AND Name == e" matches nothing. However I sometimes have the same issue when the query returns multiple results but that is currently a bit harder to reproduce in a unit test.

              [Test]
              public virtual void TestFacetNRE()
              {
                  Directory dir = NewDirectory();
                  Directory taxoDir = NewDirectory();
      
                  // Writes facet ords to a separate directory from the
                  // main index:
                  var taxoWriter = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
      
                  FacetsConfig config = new FacetsConfig();
      
                  RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, Similarity, TimeZone);
      
                  Document doc = new Document();
                  doc.Add(new Field("Name", "John", Documents.StringField.TYPE_STORED));
                  doc.Add(new Field("Age", "19", Documents.StringField.TYPE_STORED));
                  doc.Add(new FacetField("Function", "Developer"));
                  writer.AddDocument(config.Build(taxoWriter, doc));
      
                  doc = new Document();
                  doc.Add(new Field("Name", "Steven", Documents.StringField.TYPE_STORED));
                  doc.Add(new Field("Age", "23", Documents.StringField.TYPE_STORED));
                  doc.Add(new FacetField("Function", "Sales"));
                  writer.AddDocument(config.Build(taxoWriter, doc));
      
                  // NRT open
                  IndexSearcher searcher = NewSearcher(writer.Reader);
      
                  // NRT open
                  var taxoReader = new DirectoryTaxonomyReader(taxoWriter);
      
                  DrillSideways ds = new DrillSideways(searcher, config, taxoReader);
      
                  var query = new BooleanQuery(true);
                  query.Add(new TermQuery(new Term("Age", "23")), Occur.MUST_NOT);
                  query.Add(new WildcardQuery(new Term("Name", "*e*")), Occur.MUST);
      
                  var mydrillDownQuery = new DrillDownQuery(config, query);
                  mydrillDownQuery.Add("Function", "Developer");
      
                  var z = ds.Search(mydrillDownQuery, null, null, 10, null, false, false);
      
                  IOUtils.Dispose(searcher.IndexReader, taxoReader, writer, taxoWriter, dir, taxoDir);
              }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            harold.harkema Harold Harkema
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: