Index: lucene/CHANGES.txt =================================================================== --- lucene/CHANGES.txt (revision 1419397) +++ lucene/CHANGES.txt (working copy) @@ -74,7 +74,13 @@ re-index is not done, then an indexed point is ~1/2 the smallest grid cell larger and as such is slightly more likely to match a query shape. (David Smiley) - + +* LUCENE-4604: DefaultOrdinalPolicy removed in favor of OrdinalPolicy.ALL_PARENTS. + Same for DefaultPathPolicy (now PathPolicy.ALL_CATEGORIES). In addition, you + can use OrdinalPolicy.NO_PARENTS to never write any parent category ordinal + to the fulltree posting payload (but note that you need a special + FacetsAccumulator - see javadocs). (Shai Erera) + New Features * LUCENE-4226: New experimental StoredFieldsFormat that compresses chunks of Index: lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/DefaultOrdinalPolicy.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/DefaultOrdinalPolicy.java (revision 1419397) +++ lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/DefaultOrdinalPolicy.java (working copy) @@ -1,43 +0,0 @@ -package org.apache.lucene.facet.index.categorypolicy; - -import org.apache.lucene.facet.taxonomy.TaxonomyReader; -import org.apache.lucene.facet.taxonomy.TaxonomyWriter; - -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * This class filters our the ROOT category ID. For more information see - * {@link OrdinalPolicy}. - * - * @lucene.experimental - */ -public class DefaultOrdinalPolicy implements OrdinalPolicy { - - /** - * Filters out (returns false) ordinals equal or less than - * {@link TaxonomyReader#ROOT_ORDINAL}. true otherwise. - */ - public boolean shouldAdd(int ordinal) { - return ordinal > TaxonomyReader.ROOT_ORDINAL; - } - - /** - * Implemented as NO-OP as the default is not taxonomy dependent - */ - public void init(TaxonomyWriter taxonomyWriter) { } -} Index: lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/DefaultPathPolicy.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/DefaultPathPolicy.java (revision 1419397) +++ lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/DefaultPathPolicy.java (working copy) @@ -1,38 +0,0 @@ -package org.apache.lucene.facet.index.categorypolicy; - -import org.apache.lucene.facet.taxonomy.CategoryPath; -import org.apache.lucene.facet.taxonomy.TaxonomyReader; - -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * This class filters our the ROOT category path. For more information see - * {@link PathPolicy}. - * - * @lucene.experimental - */ -public class DefaultPathPolicy implements PathPolicy { - - /** - * Filters out (returns false) CategoryPaths equal or less than - * {@link TaxonomyReader#ROOT_ORDINAL}. true otherwise. - */ - public boolean shouldAdd(CategoryPath categoryPath) { - return categoryPath.length() > 0; - } -} Index: lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicy.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicy.java (revision 1419397) +++ lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicy.java (working copy) @@ -3,6 +3,8 @@ import java.io.Serializable; import org.apache.lucene.facet.index.streaming.CategoryParentsStream; +import org.apache.lucene.facet.search.FacetsAccumulator; +import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyWriter; /* @@ -27,13 +29,41 @@ * category ordinal is added to the stream, and than its parents are being added * one after the other using {@link TaxonomyWriter#getParent(int)}.
* That loop should have a stop point - the default approach (excluding the - * ROOT) is implemented in {@link DefaultOrdinalPolicy}. + * ROOT) is implemented in {@link OrdinalPolicy#ALL_PARENTS}. * * @lucene.experimental */ public interface OrdinalPolicy extends Serializable { /** + * An {@link OrdinalPolicy} which never stores parent ordinals. Useful if you + * only want to store the exact categories that were added to the document. + * Note that this is a rather expert policy, which requires a matching + * {@link FacetsAccumulator} that computes the weight of the parent categories + * on-the-fly. + */ + public static final OrdinalPolicy NO_PARENTS = new OrdinalPolicy() { + @Override + public boolean shouldAdd(int ordinal) { return false; } + + @Override + public void init(TaxonomyWriter taxonomyWriter) {} + }; + + /** + * An {@link OrdinalPolicy} which stores all parent ordinals, except + * {@link TaxonomyReader#ROOT_ORDINAL}. This is the default + * {@link OrdinalPolicy} and works with the default {@link FacetsAccumulator}. + */ + public static final OrdinalPolicy ALL_PARENTS = new OrdinalPolicy() { + @Override + public boolean shouldAdd(int ordinal) { return ordinal > TaxonomyReader.ROOT_ORDINAL; } + + @Override + public void init(TaxonomyWriter taxonomyWriter) {} + }; + + /** * Check whether a given category ordinal should be added to the stream. * * @param ordinal Index: lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/PathPolicy.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/PathPolicy.java (revision 1419397) +++ lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/PathPolicy.java (working copy) @@ -23,17 +23,25 @@ */ /** - * Filtering category paths in {@link CategoryParentsStream}, where a given - * category is added to the stream, and than all its parents are being - * added one after the other by successively removing the last component.
- * That loop should have a stop point - the default approach (excluding the - * ROOT) is implemented in {@link DefaultOrdinalPolicy}. + * Determines which {@link CategoryPath categories} should be added as terms to + * the {@link CategoryParentsStream}. The default approach is implemented by + * {@link #ALL_CATEGORIES}. * * @lucene.experimental */ public interface PathPolicy extends Serializable { /** + * A {@link PathPolicy} which adds all {@link CategoryPath} that have at least + * one component (i.e. {@link CategoryPath#length()} > 0) to the categories + * stream. + */ + public static final PathPolicy ALL_CATEGORIES = new PathPolicy() { + @Override + public boolean shouldAdd(CategoryPath categoryPath) { return categoryPath.length() > 0; } + }; + + /** * Check whether a given category path should be added to the stream. * * @param categoryPath Index: lucene/facet/src/java/org/apache/lucene/facet/index/params/DefaultFacetIndexingParams.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/index/params/DefaultFacetIndexingParams.java (revision 1419397) +++ lucene/facet/src/java/org/apache/lucene/facet/index/params/DefaultFacetIndexingParams.java (working copy) @@ -3,8 +3,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.lucene.facet.index.categorypolicy.DefaultOrdinalPolicy; -import org.apache.lucene.facet.index.categorypolicy.DefaultPathPolicy; import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy; import org.apache.lucene.facet.index.categorypolicy.PathPolicy; import org.apache.lucene.facet.taxonomy.CategoryPath; @@ -82,7 +80,7 @@ * @see #getOrdinalPolicy() */ protected OrdinalPolicy fixedOrdinalPolicy() { - return new DefaultOrdinalPolicy(); + return OrdinalPolicy.ALL_PARENTS; } /** @@ -90,7 +88,7 @@ * @see #getPathPolicy() */ protected PathPolicy fixedPathPolicy() { - return new DefaultPathPolicy(); + return PathPolicy.ALL_CATEGORIES; } public final int getPartitionSize() { Index: lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicyTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicyTest.java (revision 1419397) +++ lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicyTest.java (working copy) @@ -1,16 +1,12 @@ package org.apache.lucene.facet.index.categorypolicy; -import org.apache.lucene.store.Directory; -import org.junit.Test; - -import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.facet.index.categorypolicy.DefaultOrdinalPolicy; -import org.apache.lucene.facet.index.categorypolicy.NonTopLevelOrdinalPolicy; -import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy; import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; +import org.apache.lucene.store.Directory; +import org.apache.lucene.util.LuceneTestCase; +import org.junit.Test; /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -34,7 +30,7 @@ @Test public void testDefaultOrdinalPolicy() { // check ordinal policy - OrdinalPolicy ordinalPolicy = new DefaultOrdinalPolicy(); + OrdinalPolicy ordinalPolicy = OrdinalPolicy.ALL_PARENTS; assertFalse("default ordinal policy should not match root", ordinalPolicy .shouldAdd(TaxonomyReader.ROOT_ORDINAL)); for (int i = 0; i < 300; i++) { Index: lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/PathPolicyTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/PathPolicyTest.java (revision 1419397) +++ lucene/facet/src/test/org/apache/lucene/facet/index/categorypolicy/PathPolicyTest.java (working copy) @@ -1,15 +1,11 @@ package org.apache.lucene.facet.index.categorypolicy; -import org.apache.lucene.store.Directory; -import org.junit.Test; - -import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.facet.index.categorypolicy.DefaultPathPolicy; -import org.apache.lucene.facet.index.categorypolicy.NonTopLevelPathPolicy; -import org.apache.lucene.facet.index.categorypolicy.PathPolicy; import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; +import org.apache.lucene.store.Directory; +import org.apache.lucene.util.LuceneTestCase; +import org.junit.Test; /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -34,7 +30,7 @@ public void testDefaultPathPolicy() { // check path policy CategoryPath cp = new CategoryPath(); - PathPolicy pathPolicy = new DefaultPathPolicy(); + PathPolicy pathPolicy = PathPolicy.ALL_CATEGORIES; assertFalse("default path policy should not accept root", pathPolicy.shouldAdd(cp)); for (int i = 0; i < 300; i++) { Index: lucene/facet/src/test/org/apache/lucene/facet/index/params/DefaultFacetIndexingParamsTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/index/params/DefaultFacetIndexingParamsTest.java (revision 1419397) +++ lucene/facet/src/test/org/apache/lucene/facet/index/params/DefaultFacetIndexingParamsTest.java (working copy) @@ -1,20 +1,14 @@ package org.apache.lucene.facet.index.params; -import org.apache.lucene.index.Term; -import org.junit.Test; - -import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.facet.index.categorypolicy.DefaultOrdinalPolicy; -import org.apache.lucene.facet.index.categorypolicy.DefaultPathPolicy; import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy; import org.apache.lucene.facet.index.categorypolicy.PathPolicy; -import org.apache.lucene.facet.index.params.CategoryListParams; -import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams; -import org.apache.lucene.facet.index.params.FacetIndexingParams; import org.apache.lucene.facet.search.DrillDown; import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.util.PartitionsUtils; +import org.apache.lucene.index.Term; +import org.apache.lucene.util.LuceneTestCase; +import org.junit.Test; /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -84,13 +78,10 @@ @Test public void testCategoryPolicies() { FacetIndexingParams dfip = new DefaultFacetIndexingParams(); - long seed = System.currentTimeMillis(); // check path policy CategoryPath cp = new CategoryPath(); - PathPolicy pathPolicy = new DefaultPathPolicy(); - assertEquals("path policy does not match default for root" + "(seed " - + seed + ")", pathPolicy.shouldAdd(cp), dfip.getPathPolicy() - .shouldAdd(cp)); + PathPolicy pathPolicy = PathPolicy.ALL_CATEGORIES; + assertEquals("path policy does not match default for root", pathPolicy.shouldAdd(cp), dfip.getPathPolicy().shouldAdd(cp)); for (int i = 0; i < 30; i++) { int nComponents = random().nextInt(10); String[] components = new String[nComponents]; @@ -98,21 +89,19 @@ components[j] = (Integer.valueOf(random().nextInt(30))).toString(); } cp = new CategoryPath(components); - assertEquals("path policy does not match default for " - + cp.toString('/') + "(seed " + seed + ")", pathPolicy - .shouldAdd(cp), dfip.getPathPolicy().shouldAdd(cp)); + assertEquals("path policy does not match default for " + cp.toString('/'), + pathPolicy.shouldAdd(cp), dfip.getPathPolicy().shouldAdd(cp)); } // check ordinal policy - OrdinalPolicy ordinalPolicy = new DefaultOrdinalPolicy(); - assertEquals("ordinal policy does not match default for root" - + "(seed " + seed + ")", ordinalPolicy - .shouldAdd(TaxonomyReader.ROOT_ORDINAL), dfip - .getOrdinalPolicy().shouldAdd(TaxonomyReader.ROOT_ORDINAL)); + OrdinalPolicy ordinalPolicy = OrdinalPolicy.ALL_PARENTS; + assertEquals("ordinal policy does not match default for root", + ordinalPolicy.shouldAdd(TaxonomyReader.ROOT_ORDINAL), + dfip.getOrdinalPolicy().shouldAdd(TaxonomyReader.ROOT_ORDINAL)); for (int i = 0; i < 30; i++) { int ordinal = random().nextInt(); - assertEquals("ordinal policy does not match default for " + ordinal - + "(seed " + seed + ")", ordinalPolicy.shouldAdd(ordinal), + assertEquals("ordinal policy does not match default for " + ordinal, + ordinalPolicy.shouldAdd(ordinal), dfip.getOrdinalPolicy().shouldAdd(ordinal)); } }