mirror of https://github.com/apache/lucene.git
LUCENE-4333: Fixed NPE in TermGroupFacetCollector when faceting on mv fields.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1378077 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d8f36a22b1
commit
31c9cede9a
|
@ -113,6 +113,9 @@ Bug Fixes
|
|||
* LUCENE-4224: Add in-order scorer to query time joining and the
|
||||
out-of-order scorer throws an UOE. (Martijn van Groningen, Robert Muir)
|
||||
|
||||
* LUCENE-4333: Fixed NPE in TermGroupFacetCollector when faceting on mv fields.
|
||||
(Jesse MacVicar, Martijn van Groningen)
|
||||
|
||||
Optimizations
|
||||
|
||||
* LUCENE-4317: Improve reuse of internal TokenStreams and StringReader
|
||||
|
|
|
@ -186,6 +186,10 @@ public abstract class TermGroupFacetCollector extends AbstractGroupFacetCollecto
|
|||
}
|
||||
|
||||
public void collect(int doc) throws IOException {
|
||||
if (facetFieldDocTermOrds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int groupOrd = groupFieldTermsIndex.getOrd(doc);
|
||||
if (facetOrdTermsEnum != null) {
|
||||
reuse = facetFieldDocTermOrds.lookup(doc, reuse);
|
||||
|
@ -240,6 +244,9 @@ public abstract class TermGroupFacetCollector extends AbstractGroupFacetCollecto
|
|||
segmentTotalCount = 0;
|
||||
|
||||
segmentGroupedFacetHits.clear();
|
||||
if (facetFieldDocTermOrds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (GroupedFacetHit groupedFacetHit : groupedFacetHits) {
|
||||
int groupOrd = groupFieldTermsIndex.binarySearchLookup(groupedFacetHit.groupValue, spare);
|
||||
if (groupOrd < 0) {
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.apache.lucene.analysis.MockAnalyzer;
|
|||
import org.apache.lucene.document.*;
|
||||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.DocValues;
|
||||
import org.apache.lucene.index.NoMergePolicy;
|
||||
import org.apache.lucene.index.RandomIndexWriter;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
|
@ -217,6 +218,82 @@ public class GroupFacetCollectorTest extends AbstractGroupingTestCase {
|
|||
dir.close();
|
||||
}
|
||||
|
||||
public void testMVGroupedFacetingWithDeletes() throws Exception {
|
||||
final String groupField = "hotel";
|
||||
FieldType customType = new FieldType();
|
||||
customType.setStored(true);
|
||||
|
||||
Directory dir = newDirectory();
|
||||
RandomIndexWriter w = new RandomIndexWriter(
|
||||
random(),
|
||||
dir,
|
||||
newIndexWriterConfig(TEST_VERSION_CURRENT,
|
||||
new MockAnalyzer(random())).setMergePolicy(NoMergePolicy.COMPOUND_FILES));
|
||||
boolean useDv = false;
|
||||
|
||||
// 0
|
||||
Document doc = new Document();
|
||||
addField(doc, "x", "x", useDv);
|
||||
w.addDocument(doc);
|
||||
|
||||
doc = new Document();
|
||||
addField(doc, groupField, "a", useDv);
|
||||
addField(doc, "airport", "ams", useDv);
|
||||
w.addDocument(doc);
|
||||
|
||||
w.commit();
|
||||
w.deleteDocuments(new TermQuery(new Term("airport", "ams")));
|
||||
|
||||
// 0
|
||||
doc = new Document();
|
||||
addField(doc, groupField, "a", useDv);
|
||||
addField(doc, "airport", "ams", useDv);
|
||||
w.addDocument(doc);
|
||||
|
||||
// 1
|
||||
doc = new Document();
|
||||
addField(doc, groupField, "a", useDv);
|
||||
addField(doc, "airport", "dus", useDv);
|
||||
w.addDocument(doc);
|
||||
|
||||
// 2
|
||||
doc = new Document();
|
||||
addField(doc, groupField, "b", useDv);
|
||||
addField(doc, "airport", "ams", useDv);
|
||||
w.addDocument(doc);
|
||||
|
||||
// 3
|
||||
doc = new Document();
|
||||
addField(doc, groupField, "b", useDv);
|
||||
addField(doc, "airport", "ams", useDv);
|
||||
w.addDocument(doc);
|
||||
|
||||
// 4
|
||||
doc = new Document();
|
||||
addField(doc, groupField, "b", useDv);
|
||||
addField(doc, "airport", "ams", useDv);
|
||||
w.addDocument(doc);
|
||||
|
||||
w.commit();
|
||||
w.close();
|
||||
IndexSearcher indexSearcher = new IndexSearcher(DirectoryReader.open(dir));
|
||||
AbstractGroupFacetCollector groupedAirportFacetCollector = createRandomCollector(groupField, "airport", null, true, useDv);
|
||||
indexSearcher.search(new MatchAllDocsQuery(), groupedAirportFacetCollector);
|
||||
TermGroupFacetCollector.GroupedFacetResult airportResult = groupedAirportFacetCollector.mergeSegmentResults(10, 0, false);
|
||||
assertEquals(3, airportResult.getTotalCount());
|
||||
assertEquals(0, airportResult.getTotalMissingCount());
|
||||
|
||||
List<TermGroupFacetCollector.FacetEntry> entries = airportResult.getFacetEntries(0, 10);
|
||||
assertEquals(2, entries.size());
|
||||
assertEquals("ams", entries.get(0).getValue().utf8ToString());
|
||||
assertEquals(2, entries.get(0).getCount());
|
||||
assertEquals("dus", entries.get(1).getValue().utf8ToString());
|
||||
assertEquals(1, entries.get(1).getCount());
|
||||
|
||||
indexSearcher.getIndexReader().close();
|
||||
dir.close();
|
||||
}
|
||||
|
||||
private void addField(Document doc, String field, String value, boolean canUseIDV) {
|
||||
doc.add(new StringField(field, value, Field.Store.NO));
|
||||
if (canUseIDV) {
|
||||
|
|
Loading…
Reference in New Issue