LUCENE-5801: add default indexFieldName to facetFields

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1612197 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2014-07-21 07:07:42 +00:00
parent adaaaf041a
commit 2bf04d0308
2 changed files with 19 additions and 4 deletions

View File

@ -125,6 +125,10 @@ public class OrdinalMappingAtomicReader extends FilterAtomicReader {
for (DimConfig dc : srcConfig.getDimConfigs().values()) { for (DimConfig dc : srcConfig.getDimConfigs().values()) {
facetFields.add(dc.indexFieldName); facetFields.add(dc.indexFieldName);
} }
// always add the default indexFieldName. This is because FacetsConfig does
// not explicitly record dimensions that were indexed under the default
// DimConfig, unless they have a custome DimConfig.
facetFields.add(FacetsConfig.DEFAULT_DIM_CONFIG.indexFieldName);
} }
/** /**

View File

@ -55,6 +55,7 @@ public class TestOrdinalMappingAtomicReader extends FacetTestCase {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
facetConfig.setMultiValued("tag", true); facetConfig.setMultiValued("tag", true);
facetConfig.setIndexFieldName("tag", "$tags"); // add custom index field name
} }
@Test @Test
@ -86,9 +87,10 @@ public class TestOrdinalMappingAtomicReader extends FacetTestCase {
FacetsCollector collector = new FacetsCollector(); FacetsCollector collector = new FacetsCollector();
FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, collector); FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, collector);
Facets facets = new FastTaxonomyFacetCounts(taxoReader, facetConfig, collector);
FacetResult result = facets.getTopChildren(10, "tag"); // tag facets
Facets tagFacets = new FastTaxonomyFacetCounts("$tags", taxoReader, facetConfig, collector);
FacetResult result = tagFacets.getTopChildren(10, "tag");
for (LabelAndValue lv: result.labelValues) { for (LabelAndValue lv: result.labelValues) {
if (VERBOSE) { if (VERBOSE) {
System.out.println(lv); System.out.println(lv);
@ -96,6 +98,12 @@ public class TestOrdinalMappingAtomicReader extends FacetTestCase {
assertEquals(NUM_DOCS, lv.value.intValue()); assertEquals(NUM_DOCS, lv.value.intValue());
} }
// id facets
Facets idFacets = new FastTaxonomyFacetCounts(taxoReader, facetConfig, collector);
FacetResult idResult = idFacets.getTopChildren(10, "id");
assertEquals(NUM_DOCS, idResult.childCount);
assertEquals(NUM_DOCS * 2, idResult.value); // each "id" appears twice
BinaryDocValues bdv = MultiDocValues.getBinaryValues(indexReader, "bdv"); BinaryDocValues bdv = MultiDocValues.getBinaryValues(indexReader, "bdv");
BinaryDocValues cbdv = MultiDocValues.getBinaryValues(indexReader, "cbdv"); BinaryDocValues cbdv = MultiDocValues.getBinaryValues(indexReader, "cbdv");
for (int i = 0; i < indexReader.maxDoc(); i++) { for (int i = 0; i < indexReader.maxDoc(); i++) {
@ -115,7 +123,10 @@ public class TestOrdinalMappingAtomicReader extends FacetTestCase {
int facetValue = asc ? j: NUM_DOCS - j; int facetValue = asc ? j: NUM_DOCS - j;
doc.add(new FacetField("tag", Integer.toString(facetValue))); doc.add(new FacetField("tag", Integer.toString(facetValue)));
} }
// make sure OrdinalMappingAtomicReader ignores non-facet fields // add a facet under default dim config
doc.add(new FacetField("id", Integer.toString(i)));
// make sure OrdinalMappingAtomicReader ignores non-facet BinaryDocValues fields
doc.add(new BinaryDocValuesField("bdv", new BytesRef(Integer.toString(i)))); doc.add(new BinaryDocValuesField("bdv", new BytesRef(Integer.toString(i))));
doc.add(new BinaryDocValuesField("cbdv", new BytesRef(Integer.toString(i*2)))); doc.add(new BinaryDocValuesField("cbdv", new BytesRef(Integer.toString(i*2))));
writer.addDocument(facetConfig.build(taxonomyWriter, doc)); writer.addDocument(facetConfig.build(taxonomyWriter, doc));