mirror of https://github.com/apache/lucene.git
Fix NPE in StringValueFacetCounts over empty match-set (#13494)
This commit is contained in:
parent
ab291210db
commit
c7f4b8dee2
|
@ -283,6 +283,9 @@ Bug Fixes
|
||||||
* GITHUB#13463: Address bug in MultiLeafKnnCollector causing #minCompetitiveSimilarity to stay artificially low in
|
* GITHUB#13463: Address bug in MultiLeafKnnCollector causing #minCompetitiveSimilarity to stay artificially low in
|
||||||
some corner cases. (Greg Miller)
|
some corner cases. (Greg Miller)
|
||||||
|
|
||||||
|
* GITHUB#13493: StringValueFacetCunts stops throwing NPE when faceting over an empty match-set. (Grebennikov Roman,
|
||||||
|
Stefan Vodita)
|
||||||
|
|
||||||
Other
|
Other
|
||||||
--------------------
|
--------------------
|
||||||
(No changes)
|
(No changes)
|
||||||
|
|
|
@ -154,7 +154,7 @@ public class StringValueFacetCounts extends Facets {
|
||||||
final BytesRef term = docValues.lookupOrd(sparseCount.key);
|
final BytesRef term = docValues.lookupOrd(sparseCount.key);
|
||||||
labelValues.add(new LabelAndValue(term.utf8ToString(), count));
|
labelValues.add(new LabelAndValue(term.utf8ToString(), count));
|
||||||
}
|
}
|
||||||
} else {
|
} else if (denseCounts != null) {
|
||||||
for (int i = 0; i < denseCounts.length; i++) {
|
for (int i = 0; i < denseCounts.length; i++) {
|
||||||
int count = denseCounts[i];
|
int count = denseCounts[i];
|
||||||
if (count != 0) {
|
if (count != 0) {
|
||||||
|
@ -206,7 +206,7 @@ public class StringValueFacetCounts extends Facets {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (denseCounts != null) {
|
||||||
for (int i = 0; i < denseCounts.length; i++) {
|
for (int i = 0; i < denseCounts.length; i++) {
|
||||||
int count = denseCounts[i];
|
int count = denseCounts[i];
|
||||||
if (count != 0) {
|
if (count != 0) {
|
||||||
|
@ -256,7 +256,13 @@ public class StringValueFacetCounts extends Facets {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sparseCounts != null ? sparseCounts.get(ord) : denseCounts[ord];
|
if (sparseCounts != null) {
|
||||||
|
return sparseCounts.get(ord);
|
||||||
|
}
|
||||||
|
if (denseCounts != null) {
|
||||||
|
return denseCounts[ord];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.search.IndexSearcher;
|
import org.apache.lucene.search.IndexSearcher;
|
||||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||||
|
import org.apache.lucene.search.MatchNoDocsQuery;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
import org.apache.lucene.tests.index.RandomIndexWriter;
|
import org.apache.lucene.tests.index.RandomIndexWriter;
|
||||||
import org.apache.lucene.tests.util.LuceneTestCase;
|
import org.apache.lucene.tests.util.LuceneTestCase;
|
||||||
|
@ -80,6 +81,42 @@ public class TestStringValueFacetCounts extends FacetTestCase {
|
||||||
IOUtils.close(searcher.getIndexReader(), dir);
|
IOUtils.close(searcher.getIndexReader(), dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertEmptyFacetResult(FacetResult result) {
|
||||||
|
assertEquals(0, result.path.length);
|
||||||
|
assertEquals(0, result.value);
|
||||||
|
assertEquals(0, result.childCount);
|
||||||
|
assertEquals(0, result.labelValues.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testEmptyMatchset() throws Exception {
|
||||||
|
Directory dir = newDirectory();
|
||||||
|
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||||
|
|
||||||
|
Document doc = new Document();
|
||||||
|
doc.add(new SortedSetDocValuesField("field", new BytesRef("foo")));
|
||||||
|
writer.addDocument(doc);
|
||||||
|
|
||||||
|
IndexSearcher searcher = newSearcher(writer.getReader());
|
||||||
|
writer.close();
|
||||||
|
|
||||||
|
FacetsCollector facetsCollector =
|
||||||
|
searcher.search(new MatchNoDocsQuery(), new FacetsCollectorManager());
|
||||||
|
StringDocValuesReaderState state =
|
||||||
|
new StringDocValuesReaderState(searcher.getIndexReader(), "field");
|
||||||
|
|
||||||
|
StringValueFacetCounts counts = new StringValueFacetCounts(state, facetsCollector);
|
||||||
|
|
||||||
|
FacetResult top = counts.getTopChildren(10, "field");
|
||||||
|
assertEmptyFacetResult(top);
|
||||||
|
|
||||||
|
FacetResult all = counts.getAllChildren("field");
|
||||||
|
assertEmptyFacetResult(all);
|
||||||
|
|
||||||
|
assertEquals(0, counts.getSpecificValue("field", "foo"));
|
||||||
|
|
||||||
|
IOUtils.close(searcher.getIndexReader(), dir);
|
||||||
|
}
|
||||||
|
|
||||||
// See: LUCENE-10070
|
// See: LUCENE-10070
|
||||||
public void testCountAll() throws Exception {
|
public void testCountAll() throws Exception {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue