LUCENE-10046: Fix counting bug in StringValueFacetCounts (#236)

This commit is contained in:
Greg Miller 2021-08-07 07:32:50 -07:00 committed by GitHub
parent 3037e33025
commit e937e739f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 1 deletions

View File

@ -433,6 +433,8 @@ Bug Fixes
* LUCENE-10039: Correct CombinedFieldQuery scoring when there is a single
field. (Julie Tibshirani)
* LUCENE-10046: Counting bug fixed in StringValueFacetCounts. (Greg Miller)
Other
---------------------
(No changes)

View File

@ -375,7 +375,7 @@ public class StringValueFacetCounts extends Facets {
int term = (int) segValues.nextOrd();
boolean countedDocInTotal = false;
while (term != SortedSetDocValues.NO_MORE_ORDS) {
increment(term);
increment((int) ordMap.get(term));
if (countedDocInTotal == false) {
totalDocCount++;
}

View File

@ -140,6 +140,40 @@ public class TestStringValueFacetCounts extends FacetTestCase {
IOUtils.close(searcher.getIndexReader(), dir);
}
public void testSparseMultiSegmentCase() throws Exception {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Map<String, Integer> expectedCounts = new HashMap<>();
// Create two segments, each with only one doc that has a large number of SSDV field values.
// This ensures "sparse" counting will occur in StringValueFacetCounts (i.e., small number
// of hits relative to the field cardinality):
Document doc = new Document();
for (int i = 0; i < 100; i++) {
doc.add(new SortedSetDocValuesField("field", new BytesRef("foo_" + i)));
expectedCounts.put("foo_" + i, 1);
}
writer.addDocument(doc);
writer.commit();
doc = new Document();
for (int i = 0; i < 100; i++) {
doc.add(new SortedSetDocValuesField("field", new BytesRef("bar_" + i)));
expectedCounts.put("bar_" + i, 1);
}
writer.addDocument(doc);
int expectedTotalDocCount = 2;
IndexSearcher searcher = newSearcher(writer.getReader());
writer.close();
checkFacetResult(expectedCounts, expectedTotalDocCount, searcher, 10, 2, 1, 0);
IOUtils.close(searcher.getIndexReader(), dir);
}
public void testMissingSegment() throws Exception {
Directory dir = newDirectory();