mirror of https://github.com/apache/lucene.git
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:
parent
810f740409
commit
915d9a3d11
|
@ -121,6 +121,11 @@ API Changes
|
||||||
* LUCENE-4844: removed TaxonomyReader.getParent(), you should use
|
* LUCENE-4844: removed TaxonomyReader.getParent(), you should use
|
||||||
TaxonomyReader.getParallelArrays().parents() instead. (Shai Erera)
|
TaxonomyReader.getParallelArrays().parents() instead. (Shai Erera)
|
||||||
|
|
||||||
|
Bug Fixes
|
||||||
|
|
||||||
|
* LUCENE-4868: SumScoreFacetsAggregator used an incorrect index into
|
||||||
|
the scores array. (Shai Erera)
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
|
|
||||||
* LUCENE-4841: Added example SimpleSortedSetFacetsExample to show how
|
* LUCENE-4841: Added example SimpleSortedSetFacetsExample to show how
|
||||||
|
|
|
@ -42,11 +42,13 @@ public class SumScoreFacetsAggregator implements FacetsAggregator {
|
||||||
int doc = 0;
|
int doc = 0;
|
||||||
int length = matchingDocs.bits.length();
|
int length = matchingDocs.bits.length();
|
||||||
float[] scores = facetArrays.getFloatArray();
|
float[] scores = facetArrays.getFloatArray();
|
||||||
|
int scoresIdx = 0;
|
||||||
while (doc < length && (doc = matchingDocs.bits.nextSetBit(doc)) != -1) {
|
while (doc < length && (doc = matchingDocs.bits.nextSetBit(doc)) != -1) {
|
||||||
cli.getOrdinals(doc, ordinals);
|
cli.getOrdinals(doc, ordinals);
|
||||||
int upto = ordinals.offset + ordinals.length;
|
int upto = ordinals.offset + ordinals.length;
|
||||||
|
final float score = matchingDocs.scores[scoresIdx++];
|
||||||
for (int i = ordinals.offset; i < upto; i++) {
|
for (int i = ordinals.offset; i < upto; i++) {
|
||||||
scores[ordinals.ints[i]] += matchingDocs.scores[doc];
|
scores[ordinals.ints[i]] += score;
|
||||||
}
|
}
|
||||||
++doc;
|
++doc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,12 @@ import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
|
||||||
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
|
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
|
||||||
import org.apache.lucene.index.DirectoryReader;
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.index.IndexWriter;
|
import org.apache.lucene.index.IndexWriter;
|
||||||
|
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.MultiCollector;
|
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.search.TopScoreDocCollector;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
import org.apache.lucene.util.IOUtils;
|
import org.apache.lucene.util.IOUtils;
|
||||||
|
@ -60,7 +63,9 @@ public class TestFacetsCollector extends FacetTestCase {
|
||||||
FacetFields facetFields = new FacetFields(taxonomyWriter);
|
FacetFields facetFields = new FacetFields(taxonomyWriter);
|
||||||
for(int i = atLeast(30); i > 0; --i) {
|
for(int i = atLeast(30); i > 0; --i) {
|
||||||
Document doc = new Document();
|
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")));
|
facetFields.addFields(doc, Collections.singletonList(new CategoryPath("a")));
|
||||||
iw.addDocument(doc);
|
iw.addDocument(doc);
|
||||||
}
|
}
|
||||||
|
@ -80,12 +85,13 @@ public class TestFacetsCollector extends FacetTestCase {
|
||||||
};
|
};
|
||||||
FacetsCollector fc = FacetsCollector.create(fa);
|
FacetsCollector fc = FacetsCollector.create(fa);
|
||||||
TopScoreDocCollector topDocs = TopScoreDocCollector.create(10, false);
|
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();
|
List<FacetResult> res = fc.getFacetResults();
|
||||||
double value = res.get(0).getFacetResultNode().value;
|
float value = (float) res.get(0).getFacetResultNode().value;
|
||||||
double expected = topDocs.topDocs().getMaxScore() * r.numDocs();
|
TopDocs td = topDocs.topDocs();
|
||||||
assertEquals(expected, value, 1E-10);
|
float expected = td.getMaxScore() * td.totalHits;
|
||||||
|
assertEquals(expected, value, 1E-4);
|
||||||
|
|
||||||
IOUtils.close(taxo, taxoDir, r, indexDir);
|
IOUtils.close(taxo, taxoDir, r, indexDir);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue