Skip to content

Commit

Permalink
LUCENE-10046: Fix counting bug in StringValueFacetCounts (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmiller committed Aug 7, 2021
1 parent 3037e33 commit e937e73
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private void countOneSegment(
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++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,40 @@ public void testBasicMultiValued() throws Exception {
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();
Expand Down

0 comments on commit e937e73

Please sign in to comment.