LUCENE-4868: SumScoreFacetsAggregator used an incorrect index into the scores array

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1459304 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2013-03-21 13:35:42 +00:00
parent 810f740409
commit 915d9a3d11
3 changed files with 19 additions and 6 deletions

View File

@ -121,6 +121,11 @@ API Changes
* LUCENE-4844: removed TaxonomyReader.getParent(), you should use
TaxonomyReader.getParallelArrays().parents() instead. (Shai Erera)
Bug Fixes
* LUCENE-4868: SumScoreFacetsAggregator used an incorrect index into
the scores array. (Shai Erera)
Documentation
* LUCENE-4841: Added example SimpleSortedSetFacetsExample to show how

View File

@ -42,11 +42,13 @@ public class SumScoreFacetsAggregator implements FacetsAggregator {
int doc = 0;
int length = matchingDocs.bits.length();
float[] scores = facetArrays.getFloatArray();
int scoresIdx = 0;
while (doc < length && (doc = matchingDocs.bits.nextSetBit(doc)) != -1) {
cli.getOrdinals(doc, ordinals);
int upto = ordinals.offset + ordinals.length;
final float score = matchingDocs.scores[scoresIdx++];
for (int i = ordinals.offset; i < upto; i++) {
scores[ordinals.ints[i]] += matchingDocs.scores[doc];
scores[ordinals.ints[i]] += score;
}
++doc;
}

View File

@ -22,9 +22,12 @@ import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.MultiCollector;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.IOUtils;
@ -60,7 +63,9 @@ public class TestFacetsCollector extends FacetTestCase {
FacetFields facetFields = new FacetFields(taxonomyWriter);
for(int i = atLeast(30); i > 0; --i) {
Document doc = new Document();
doc.add(new StringField("f", "v", Store.NO));
if (random().nextBoolean()) { // don't match all documents
doc.add(new StringField("f", "v", Store.NO));
}
facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a")));
iw.addDocument(doc);
}
@ -80,12 +85,13 @@ public class TestFacetsCollector extends FacetTestCase {
};
FacetsCollector fc = FacetsCollector.create(fa);
TopScoreDocCollector topDocs = TopScoreDocCollector.create(10, false);
new IndexSearcher(r).search(new MatchAllDocsQuery(), MultiCollector.wrap(fc, topDocs));
new IndexSearcher(r).search(new TermQuery(new Term("f", "v")), MultiCollector.wrap(fc, topDocs));
List<FacetResult> res = fc.getFacetResults();
double value = res.get(0).getFacetResultNode().value;
double expected = topDocs.topDocs().getMaxScore() * r.numDocs();
assertEquals(expected, value, 1E-10);
float value = (float) res.get(0).getFacetResultNode().value;
TopDocs td = topDocs.topDocs();
float expected = td.getMaxScore() * td.totalHits;
assertEquals(expected, value, 1E-4);
IOUtils.close(taxo, taxoDir, r, indexDir);
}