mirror of https://github.com/apache/lucene.git
LUCENE-5522: FacetConfig doesn't add drill-down terms for facet associations
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1576790 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3b67b17493
commit
938d06854f
|
@ -169,6 +169,9 @@ Bug fixes
|
|||
* LUCENE-5502: Fixed TermsFilter.equals that could return true for different
|
||||
filters. (Igor Motov via Adrien Grand)
|
||||
|
||||
* LUCENE-5522: FacetsConfig didn't add drill-down terms for association facet
|
||||
fields labels. (Shai Erera)
|
||||
|
||||
Test Framework
|
||||
|
||||
* LUCENE-5449: Rename _TestUtil and _TestHelper to remove the leading _.
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.List;
|
|||
|
||||
import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.facet.DrillDownQuery;
|
||||
import org.apache.lucene.facet.FacetResult;
|
||||
import org.apache.lucene.facet.Facets;
|
||||
import org.apache.lucene.facet.FacetsCollector;
|
||||
|
@ -116,12 +117,43 @@ public class AssociationsFacetsExample {
|
|||
return results;
|
||||
}
|
||||
|
||||
/** User drills down on 'tags/solr'. */
|
||||
private FacetResult drillDown() throws IOException {
|
||||
DirectoryReader indexReader = DirectoryReader.open(indexDir);
|
||||
IndexSearcher searcher = new IndexSearcher(indexReader);
|
||||
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
|
||||
|
||||
// Passing no baseQuery means we drill down on all
|
||||
// documents ("browse only"):
|
||||
DrillDownQuery q = new DrillDownQuery(config);
|
||||
|
||||
// Now user drills down on Publish Date/2010:
|
||||
q.add("tags", "solr");
|
||||
FacetsCollector fc = new FacetsCollector();
|
||||
FacetsCollector.search(searcher, q, 10, fc);
|
||||
|
||||
// Retrieve results
|
||||
Facets facets = new TaxonomyFacetSumFloatAssociations("$genre", taxoReader, config, fc);
|
||||
FacetResult result = facets.getTopChildren(10, "genre");
|
||||
|
||||
indexReader.close();
|
||||
taxoReader.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Runs summing association example. */
|
||||
public List<FacetResult> runSumAssociations() throws IOException {
|
||||
index();
|
||||
return sumAssociations();
|
||||
}
|
||||
|
||||
/** Runs the drill-down example. */
|
||||
public FacetResult runDrillDown() throws IOException {
|
||||
index();
|
||||
return drillDown();
|
||||
}
|
||||
|
||||
/** Runs the sum int/float associations examples and prints the results. */
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("Sum associations example:");
|
||||
|
|
|
@ -32,4 +32,11 @@ public class TestAssociationsFacetsExample extends LuceneTestCase {
|
|||
assertEquals("dim=tags path=[] value=-1 childCount=2\n lucene (4)\n solr (2)\n", res.get(0).toString());
|
||||
assertEquals("dim=genre path=[] value=-1.0 childCount=2\n computing (1.62)\n software (0.34)\n", res.get(1).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDrillDown() throws Exception {
|
||||
FacetResult result = new AssociationsFacetsExample().runDrillDown();
|
||||
assertEquals("dim=genre path=[] value=-1.0 childCount=2\n computing (0.75)\n software (0.34)\n", result.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -403,6 +403,12 @@ public class FacetsConfig {
|
|||
}
|
||||
System.arraycopy(field.assoc.bytes, field.assoc.offset, bytes, upto, field.assoc.length);
|
||||
upto += field.assoc.length;
|
||||
|
||||
// Drill down:
|
||||
FacetLabel cp = new FacetLabel(field.dim, field.path);
|
||||
for (int i = 1; i <= cp.length; i++) {
|
||||
doc.add(new StringField(indexFieldName, pathToString(cp.components, i), Field.Store.NO));
|
||||
}
|
||||
}
|
||||
doc.add(new BinaryDocValuesField(indexFieldName, new BytesRef(bytes, 0, upto)));
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.lucene.facet.taxonomy;
|
|||
|
||||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.facet.DrillDownQuery;
|
||||
import org.apache.lucene.facet.FacetTestCase;
|
||||
import org.apache.lucene.facet.Facets;
|
||||
import org.apache.lucene.facet.FacetsCollector;
|
||||
|
@ -223,4 +224,19 @@ public class TestTaxonomyFacetAssociations extends FacetTestCase {
|
|||
}
|
||||
IOUtils.close(writer, taxoWriter, dir, taxoDir);
|
||||
}
|
||||
|
||||
public void testIntSumAssociationDrillDown() throws Exception {
|
||||
FacetsCollector fc = new FacetsCollector();
|
||||
|
||||
IndexSearcher searcher = newSearcher(reader);
|
||||
DrillDownQuery q = new DrillDownQuery(config);
|
||||
q.add("int", "b");
|
||||
searcher.search(q, fc);
|
||||
|
||||
Facets facets = new TaxonomyFacetSumIntAssociations("$facets.int", taxoReader, config, fc);
|
||||
assertEquals("dim=int path=[] value=-1 childCount=2\n b (150)\n a (100)\n", facets.getTopChildren(10, "int").toString());
|
||||
assertEquals("Wrong count for category 'a'!", 100, facets.getSpecificValue("int", "a").intValue());
|
||||
assertEquals("Wrong count for category 'b'!", 150, facets.getSpecificValue("int", "b").intValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue