From 2bf04d03083f9e8ec2db8c5c516c1b2de19e1d30 Mon Sep 17 00:00:00 2001 From: Shai Erera Date: Mon, 21 Jul 2014 07:07:42 +0000 Subject: [PATCH] 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 --- .../taxonomy/OrdinalMappingAtomicReader.java | 4 ++++ .../TestOrdinalMappingAtomicReader.java | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/OrdinalMappingAtomicReader.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/OrdinalMappingAtomicReader.java index 9936748097a..7fb67426586 100644 --- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/OrdinalMappingAtomicReader.java +++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/OrdinalMappingAtomicReader.java @@ -125,6 +125,10 @@ public class OrdinalMappingAtomicReader extends FilterAtomicReader { for (DimConfig dc : srcConfig.getDimConfigs().values()) { 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); } /** diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestOrdinalMappingAtomicReader.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestOrdinalMappingAtomicReader.java index 662fbc52b86..51a08aa6988 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestOrdinalMappingAtomicReader.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestOrdinalMappingAtomicReader.java @@ -55,6 +55,7 @@ public class TestOrdinalMappingAtomicReader extends FacetTestCase { public void setUp() throws Exception { super.setUp(); facetConfig.setMultiValued("tag", true); + facetConfig.setIndexFieldName("tag", "$tags"); // add custom index field name } @Test @@ -86,9 +87,10 @@ public class TestOrdinalMappingAtomicReader extends FacetTestCase { FacetsCollector collector = new FacetsCollector(); 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) { if (VERBOSE) { System.out.println(lv); @@ -96,6 +98,12 @@ public class TestOrdinalMappingAtomicReader extends FacetTestCase { 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 cbdv = MultiDocValues.getBinaryValues(indexReader, "cbdv"); for (int i = 0; i < indexReader.maxDoc(); i++) { @@ -115,7 +123,10 @@ public class TestOrdinalMappingAtomicReader extends FacetTestCase { int facetValue = asc ? j: NUM_DOCS - j; 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("cbdv", new BytesRef(Integer.toString(i*2)))); writer.addDocument(facetConfig.build(taxonomyWriter, doc));