Index: lucene/CHANGES.txt =================================================================== --- lucene/CHANGES.txt (revision 1420923) +++ lucene/CHANGES.txt (working copy) @@ -90,6 +90,10 @@ FacetArrays no longer takes those allocators; if you need to reuse the arrays, you should use ReusingFacetArrays. (Shai Erera, Gilad Barkai) +* LUCENE-4621: FacetIndexingParams is now a concrete class (instead of DefaultFIP). + Also, the entire IndexingParams chain is now immutable. If you need to override + a setting, you should extend the relevant class. (Shai Erera) + New Features * LUCENE-4226: New experimental StoredFieldsFormat that compresses chunks of Index: lucene/facet/src/examples/org/apache/lucene/facet/example/association/AssociationUtils.java =================================================================== --- lucene/facet/src/examples/org/apache/lucene/facet/example/association/AssociationUtils.java (revision 1420923) +++ lucene/facet/src/examples/org/apache/lucene/facet/example/association/AssociationUtils.java (working copy) @@ -4,7 +4,7 @@ import org.apache.lucene.facet.enhancements.association.AssociationFloatProperty; import org.apache.lucene.facet.enhancements.association.AssociationIntProperty; import org.apache.lucene.facet.enhancements.association.AssociationProperty; -import org.apache.lucene.facet.enhancements.params.DefaultEnhancementsIndexingParams; +import org.apache.lucene.facet.enhancements.params.EnhancementsIndexingParams; import org.apache.lucene.facet.taxonomy.CategoryPath; /* @@ -73,7 +73,7 @@ * Indexing Params: the indexing params to use when dealing with * associations. */ - public static final DefaultEnhancementsIndexingParams assocIndexingParams = - new DefaultEnhancementsIndexingParams(new AssociationEnhancement()); + public static final EnhancementsIndexingParams assocIndexingParams = new EnhancementsIndexingParams( + new AssociationEnhancement()); } Index: lucene/facet/src/examples/org/apache/lucene/facet/example/merge/TaxonomyMergeUtils.java =================================================================== --- lucene/facet/src/examples/org/apache/lucene/facet/example/merge/TaxonomyMergeUtils.java (revision 1420923) +++ lucene/facet/src/examples/org/apache/lucene/facet/example/merge/TaxonomyMergeUtils.java (working copy) @@ -3,6 +3,13 @@ import java.io.IOException; import java.util.List; +import org.apache.lucene.facet.example.ExampleUtils; +import org.apache.lucene.facet.index.OrdinalMappingAtomicReader; +import org.apache.lucene.facet.index.params.FacetIndexingParams; +import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; +import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.DiskOrdinalMap; +import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.MemoryOrdinalMap; +import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.OrdinalMap; import org.apache.lucene.index.AtomicReader; import org.apache.lucene.index.AtomicReaderContext; import org.apache.lucene.index.DirectoryReader; @@ -11,15 +18,6 @@ import org.apache.lucene.index.MultiReader; import org.apache.lucene.store.Directory; -import org.apache.lucene.facet.example.ExampleUtils; -import org.apache.lucene.facet.index.OrdinalMappingAtomicReader; -import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams; -import org.apache.lucene.facet.index.params.FacetIndexingParams; -import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; -import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.DiskOrdinalMap; -import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.MemoryOrdinalMap; -import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.OrdinalMap; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -88,7 +86,7 @@ destTaxWriter.addTaxonomy(srcTaxDir, map); int ordinalMap[] = map.getMap(); - FacetIndexingParams params = new DefaultFacetIndexingParams(); + FacetIndexingParams params = FacetIndexingParams.ALL_PARENTS; DirectoryReader reader = DirectoryReader.open(srcIndexDir, -1); List leaves = reader.leaves(); Index: lucene/facet/src/examples/org/apache/lucene/facet/example/multiCL/MultiCLIndexer.java =================================================================== --- lucene/facet/src/examples/org/apache/lucene/facet/example/multiCL/MultiCLIndexer.java (revision 1420923) +++ lucene/facet/src/examples/org/apache/lucene/facet/example/multiCL/MultiCLIndexer.java (working copy) @@ -1,7 +1,9 @@ package org.apache.lucene.facet.example.multiCL; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Random; import org.apache.lucene.document.Document; @@ -74,22 +76,18 @@ + "reprehenderit qui in ea voluptate velit esse quam nihil molestiae " + "consequatur vel illum qui dolorem eum fugiat quo voluptas nulla pariatur"; // PerDimensionIndexingParams for multiple category lists - public static PerDimensionIndexingParams MULTI_IPARAMS = new PerDimensionIndexingParams(); + public static final PerDimensionIndexingParams MULTI_IPARAMS; // Initialize PerDimensionIndexingParams static { - MULTI_IPARAMS.addCategoryListParams(new CategoryPath("0"), - new CategoryListParams(new Term("$Digits", "Zero"))); - MULTI_IPARAMS.addCategoryListParams(new CategoryPath("1"), - new CategoryListParams(new Term("$Digits", "One"))); - MULTI_IPARAMS.addCategoryListParams(new CategoryPath("2"), - new CategoryListParams(new Term("$Digits", "Two"))); - MULTI_IPARAMS.addCategoryListParams(new CategoryPath("3"), - new CategoryListParams(new Term("$Digits", "Three"))); - MULTI_IPARAMS.addCategoryListParams(new CategoryPath("4"), - new CategoryListParams(new Term("$Digits", "Four"))); - MULTI_IPARAMS.addCategoryListParams(new CategoryPath("5"), - new CategoryListParams(new Term("$Digits", "Five"))); + Map paramsMap = new HashMap(); + paramsMap.put(new CategoryPath("0"), new CategoryListParams(new Term("$Digits", "Zero"))); + paramsMap.put(new CategoryPath("1"), new CategoryListParams(new Term("$Digits", "One"))); + paramsMap.put(new CategoryPath("2"), new CategoryListParams(new Term("$Digits", "Two"))); + paramsMap.put(new CategoryPath("3"), new CategoryListParams(new Term("$Digits", "Three"))); + paramsMap.put(new CategoryPath("4"), new CategoryListParams(new Term("$Digits", "Four"))); + paramsMap.put(new CategoryPath("5"), new CategoryListParams(new Term("$Digits", "Five"))); + MULTI_IPARAMS = new PerDimensionIndexingParams(paramsMap); } /** Index: lucene/facet/src/examples/org/apache/lucene/facet/example/simple/SimpleSearcher.java =================================================================== --- lucene/facet/src/examples/org/apache/lucene/facet/example/simple/SimpleSearcher.java (revision 1420923) +++ lucene/facet/src/examples/org/apache/lucene/facet/example/simple/SimpleSearcher.java (working copy) @@ -3,16 +3,7 @@ import java.util.Iterator; import java.util.List; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TermQuery; -import org.apache.lucene.search.TopScoreDocCollector; - -import org.apache.lucene.search.MultiCollector; import org.apache.lucene.facet.example.ExampleUtils; -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.search.FacetsCollector; @@ -23,6 +14,13 @@ import org.apache.lucene.facet.search.results.FacetResultNode; import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.TaxonomyReader; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.MultiCollector; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.TermQuery; +import org.apache.lucene.search.TopScoreDocCollector; /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -101,7 +99,7 @@ TopScoreDocCollector topDocsCollector = TopScoreDocCollector.create(10, true); if (indexingParams == null) { - indexingParams = new DefaultFacetIndexingParams(); + indexingParams = FacetIndexingParams.ALL_PARENTS; } // Faceted search parameters indicate which facets are we interested in @@ -138,7 +136,7 @@ public static List searchWithDrillDown(IndexReader indexReader, TaxonomyReader taxoReader) throws Exception { - final FacetIndexingParams indexingParams = new DefaultFacetIndexingParams(); + final FacetIndexingParams indexingParams = FacetIndexingParams.ALL_PARENTS; // base query the user is interested in Query baseQuery = new TermQuery(new Term(SimpleUtils.TEXT, "white")); Index: lucene/facet/src/java/org/apache/lucene/facet/doc-files/userguide.html =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/doc-files/userguide.html (revision 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/doc-files/userguide.html (working copy) @@ -538,7 +538,7 @@ forms: category-tokens (for drill-down) and category-list-tokens (for accumulation). This parameter allows to specify, for each category, the Lucene term used for maintaining the category-list-tokens for that category. -The default implementation in DefaultFacetIndexingParams maintains +The default implementation in FacetIndexingParams maintains this information for all categories under the same special dedicated term. One case where it is needed to maintain two categories in separate category lists, is when it is known that at search time it would be required to use @@ -548,7 +548,7 @@ for example, the partition size is set to 1000, a distinct sub-term is used for maintaining each 1000 categories, e.g. term1 for categories 0 to 999, term2 for categories 1000 to 1999, etc. The default implementation in -DefaultFacetIndexingParams maintains category lists in a single +FacetIndexingParams maintains category lists in a single partition, hence it defines the partition size as Integer.MAX_VALUE. The importance of this parameter is on allowing to handle very large taxonomies without exhausting RAM resources. This is because at facet Index: lucene/facet/src/java/org/apache/lucene/facet/enhancements/CategoryEnhancement.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/enhancements/CategoryEnhancement.java (revision 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/enhancements/CategoryEnhancement.java (working copy) @@ -121,7 +121,7 @@ * {@link CategoryParentsStream}, or {@code null} if there is no such * property. */ - Class getRetainableProperty(); + CategoryProperty getRetainableProperty(); /** * Category enhancements must override {@link Object#equals(Object)}, as it is Index: lucene/facet/src/java/org/apache/lucene/facet/enhancements/EnhancementsDocumentBuilder.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/enhancements/EnhancementsDocumentBuilder.java (revision 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/enhancements/EnhancementsDocumentBuilder.java (working copy) @@ -53,13 +53,12 @@ @Override protected TokenStream getParentsStream(CategoryAttributesStream categoryAttributesStream) { - List> toRetainList = ((EnhancementsIndexingParams) indexingParams) - .getRetainableProperties(); + List toRetainList = ((EnhancementsIndexingParams) indexingParams).getRetainableProperties(); if (toRetainList != null) { CategoryParentsStream categoryParentsStream = new CategoryParentsStream( categoryAttributesStream, taxonomyWriter, indexingParams); - for (Class toRetain : toRetainList) { - categoryParentsStream.addRetainableProperty(toRetain); + for (CategoryProperty toRetain : toRetainList) { + categoryParentsStream.addRetainableProperty(toRetain.getClass()); } return categoryParentsStream; } Index: lucene/facet/src/java/org/apache/lucene/facet/enhancements/association/AssociationEnhancement.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/enhancements/association/AssociationEnhancement.java (revision 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/enhancements/association/AssociationEnhancement.java (working copy) @@ -152,7 +152,7 @@ } @Override - public Class getRetainableProperty() { + public CategoryProperty getRetainableProperty() { return null; } Index: lucene/facet/src/java/org/apache/lucene/facet/enhancements/params/DefaultEnhancementsIndexingParams.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/enhancements/params/DefaultEnhancementsIndexingParams.java (revision 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/enhancements/params/DefaultEnhancementsIndexingParams.java (working copy) @@ -1,101 +0,0 @@ -package org.apache.lucene.facet.enhancements.params; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.lucene.facet.enhancements.CategoryEnhancement; -import org.apache.lucene.facet.index.attributes.CategoryProperty; -import org.apache.lucene.facet.index.params.CategoryListParams; -import org.apache.lucene.facet.index.params.PerDimensionIndexingParams; - -/* - * 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. - */ - -/** - * Default implementation of {@link EnhancementsIndexingParams} - * - * @lucene.experimental - */ -public class DefaultEnhancementsIndexingParams extends - PerDimensionIndexingParams implements EnhancementsIndexingParams { - - private List enhancedCategories; - - /** - * Construct with a certain {@link CategoryEnhancement enhancement} - * @throws IllegalArgumentException if no enhancements are provided - */ - public DefaultEnhancementsIndexingParams(CategoryEnhancement... enhancements) { - super(); - validateparams(enhancements); - addCategoryEnhancements(enhancements); - } - - private void validateparams(CategoryEnhancement... enhancements) { - if (enhancements==null || enhancements.length<1) { - throw new IllegalArgumentException("at least one enhancement is required"); - } - } - - /** - * Construct with certain {@link CategoryEnhancement enhancements} - * and {@link CategoryListParams} - * @throws IllegalArgumentException if no enhancements are provided - */ - public DefaultEnhancementsIndexingParams( - CategoryListParams categoryListParams, - CategoryEnhancement... enhancements) { - super(categoryListParams); - validateparams(enhancements); - addCategoryEnhancements(enhancements); - } - - @Override - public void addCategoryEnhancements(CategoryEnhancement... enhancements) { - if (enhancedCategories == null) { - enhancedCategories = new ArrayList(); - } - for (CategoryEnhancement categoryEnhancement : enhancements) { - enhancedCategories.add(categoryEnhancement); - } - } - - @Override - public List getCategoryEnhancements() { - if (enhancedCategories == null || enhancedCategories.isEmpty()) { - return null; - } - return enhancedCategories; - } - - @Override - public List> getRetainableProperties() { - if (enhancedCategories == null) { - return null; - } - List> retainableProperties = new ArrayList>(); - for (CategoryEnhancement enhancement : enhancedCategories) { - if (enhancement.getRetainableProperty() != null) { - retainableProperties.add(enhancement.getRetainableProperty()); - } - } - if (retainableProperties.isEmpty()) { - return null; - } - return retainableProperties; - } -} Index: lucene/facet/src/java/org/apache/lucene/facet/enhancements/params/EnhancementsIndexingParams.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/enhancements/params/EnhancementsIndexingParams.java (revision 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/enhancements/params/EnhancementsIndexingParams.java (working copy) @@ -1,12 +1,18 @@ package org.apache.lucene.facet.enhancements.params; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.Map; import org.apache.lucene.facet.enhancements.CategoryEnhancement; import org.apache.lucene.facet.enhancements.EnhancementsDocumentBuilder; import org.apache.lucene.facet.index.attributes.CategoryProperty; -import org.apache.lucene.facet.index.params.FacetIndexingParams; +import org.apache.lucene.facet.index.params.CategoryListParams; +import org.apache.lucene.facet.index.params.PerDimensionIndexingParams; import org.apache.lucene.facet.index.streaming.CategoryParentsStream; +import org.apache.lucene.facet.taxonomy.CategoryPath; /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -26,41 +32,76 @@ */ /** - * {@link FacetIndexingParams Facet indexing parameters} for defining - * {@link CategoryEnhancement category enhancements}. It must contain at least - * one enhancement, otherwise nothing is "enhanced" about it. When there are - * more than one, the order matters - see {@link #getCategoryEnhancements()}. + * A {@link PerDimensionIndexingParams} for defining {@link CategoryEnhancement + * category enhancements}. Must contain at least one enhancement, and when there + * are more than one, their order matters. * + * @see #getCategoryEnhancements() * @see EnhancementsDocumentBuilder + * @lucene.experimental */ -public interface EnhancementsIndexingParams extends FacetIndexingParams { +public class EnhancementsIndexingParams extends PerDimensionIndexingParams { + private final List enhancements; + /** - * Add {@link CategoryEnhancement}s to the indexing parameters - * @param enhancements enhancements to add + * Initializes with the given enhancements + * + * @throws IllegalArgumentException + * if no enhancements are provided */ - public void addCategoryEnhancements(CategoryEnhancement... enhancements); + public EnhancementsIndexingParams(CategoryEnhancement... enhancements) { + this(DEFAULT_CATEGORY_LIST_PARAMS, Collections. emptyMap(), enhancements); + } /** - * Get a list of the active category enhancements. If no enhancements exist - * return {@code null}. The order of enhancements in the returned list - * dictates the order in which the enhancements data appear in the category - * tokens payload. + * Initializes with the given enhancements and category list params mappings. * - * @return A list of the active category enhancements, or {@code null} if - * there are no enhancements. + * @see PerDimensionIndexingParams#PerDimensionIndexingParams(Map, CategoryListParams) + * @throws IllegalArgumentException + * if no enhancements are provided */ - public List getCategoryEnhancements(); + public EnhancementsIndexingParams(CategoryListParams categoryListParams, + Map paramsMap, CategoryEnhancement... enhancements) { + super(paramsMap, categoryListParams); + validateparams(enhancements); + this.enhancements = Arrays.asList(enhancements); + } + private void validateparams(CategoryEnhancement... enhancements) { + if (enhancements == null || enhancements.length < 1) { + throw new IllegalArgumentException("at least one enhancement is required"); + } + } + /** - * Get a list of {@link CategoryProperty} classes to be retained when - * creating {@link CategoryParentsStream}. - * - * @return the list of {@link CategoryProperty} classes to be retained when - * creating {@link CategoryParentsStream}, or {@code null} if there - * are no such properties. + * Returns the list of {@link CategoryEnhancement} as were given at + * intialization time. You are not expected to modify the list. The order of + * the enhancements dictates the order in which they are written in the + * document. */ - public List> getRetainableProperties(); + public List getCategoryEnhancements() { + return enhancements; + } + /** + * Returns a list of {@link CategoryProperty} which should be retained when + * creating {@link CategoryParentsStream}, or {@code null} if there are no + * such properties. + */ + public List getRetainableProperties() { + List props = new ArrayList(); + for (CategoryEnhancement enhancement : enhancements) { + CategoryProperty prop = enhancement.getRetainableProperty(); + if (prop != null) { + props.add(prop); + } + } + if (props.isEmpty()) { + return null; + } + return props; + } + } Index: lucene/facet/src/java/org/apache/lucene/facet/index/CategoryDocumentBuilder.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/index/CategoryDocumentBuilder.java (revision 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/index/CategoryDocumentBuilder.java (working copy) @@ -12,12 +12,10 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; import org.apache.lucene.document.TextField; - import org.apache.lucene.facet.index.attributes.CategoryAttribute; import org.apache.lucene.facet.index.attributes.CategoryAttributesIterable; import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy; import org.apache.lucene.facet.index.categorypolicy.PathPolicy; -import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams; import org.apache.lucene.facet.index.params.FacetIndexingParams; import org.apache.lucene.facet.index.streaming.CategoryAttributesStream; import org.apache.lucene.facet.index.streaming.CategoryListTokenizer; @@ -48,7 +46,7 @@ * A utility class which allows attachment of {@link CategoryPath}s or * {@link CategoryAttribute}s to a given document using a taxonomy.
* Construction could be done with either a given {@link FacetIndexingParams} or - * the default implementation {@link DefaultFacetIndexingParams}.
+ * the default implementation {@link FacetIndexingParams}.
* A CategoryDocumentBuilder can be reused by repeatedly setting the categories * and building the document. Categories are provided either as * {@link CategoryAttribute} elements through {@link #setCategories(Iterable)}, @@ -85,18 +83,16 @@ protected Map> categoriesMap; /** - * Creating a facets document builder with default facet indexing - * parameters.
- * See: - * {@link #CategoryDocumentBuilder(TaxonomyWriter, FacetIndexingParams)} + * Creating a facets document builder with default facet indexing parameters. * * @param taxonomyWriter - * to which new categories will be added, as well as translating - * known categories to ordinals - * + * to which new categories will be added, as well as translating + * known categories to ordinals + * + * @see #CategoryDocumentBuilder(TaxonomyWriter, FacetIndexingParams) */ public CategoryDocumentBuilder(TaxonomyWriter taxonomyWriter) { - this(taxonomyWriter, new DefaultFacetIndexingParams()); + this(taxonomyWriter, FacetIndexingParams.ALL_PARENTS); } /** Index: lucene/facet/src/java/org/apache/lucene/facet/index/OrdinalMappingAtomicReader.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/index/OrdinalMappingAtomicReader.java (revision 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/index/OrdinalMappingAtomicReader.java (working copy) @@ -25,7 +25,6 @@ import java.util.Map; 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.taxonomy.directory.DirectoryTaxonomyWriter.OrdinalMap; import org.apache.lucene.index.AtomicReader; @@ -71,6 +70,7 @@ * @lucene.experimental */ public class OrdinalMappingAtomicReader extends FilterAtomicReader { + private final int[] ordinalMap; // a little obtuse: but we dont need to create Term objects this way private final Map> termMap = @@ -82,7 +82,7 @@ * OrdinalMappingAtomicReader(in, ordinalMap, new DefaultFacetIndexingParams())} */ public OrdinalMappingAtomicReader(AtomicReader in, int[] ordinalMap) { - this(in, ordinalMap, new DefaultFacetIndexingParams()); + this(in, ordinalMap, FacetIndexingParams.ALL_PARENTS); } /** 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 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/index/categorypolicy/OrdinalPolicy.java (working copy) @@ -2,7 +2,6 @@ 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; @@ -25,11 +24,9 @@ */ /** - * Filtering category ordinals in {@link CategoryParentsStream}, where a given - * 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 OrdinalPolicy#ALL_PARENTS}. + * A policy for adding category parent ordinals to the list of ordinals that are + * encoded for a given document. The default {@link #ALL_PARENTS} policy always + * adds all parents, where {@link #NO_PARENTS} never adds any parents. * * @lucene.experimental */ 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 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/index/params/DefaultFacetIndexingParams.java (working copy) @@ -1,201 +0,0 @@ -package org.apache.lucene.facet.index.params; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy; -import org.apache.lucene.facet.index.categorypolicy.PathPolicy; -import org.apache.lucene.facet.taxonomy.CategoryPath; - -/* - * 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. - */ - -/** - * Default implementation for {@link FacetIndexingParams}. - *

- * Getters for partition-size, {@link OrdinalPolicy} and - * {@link PathPolicy} are all final, and so the proper way to modify them when - * extending this class is through {@link #fixedPartitionSize()}, - * {@link #fixedOrdinalPolicy()} or {@link #fixedPathPolicy()} accordingly. - * - * @lucene.experimental - */ -public class DefaultFacetIndexingParams implements FacetIndexingParams { - - /** - * delimiter between a categories in a path, e.g. Products FACET_DELIM - * Consumer FACET_DELIM Tv. This should be a character not found in any path - * component - */ - public static final char DEFAULT_FACET_DELIM_CHAR = '\uF749'; - - private final CategoryListParams clpParams; - private final OrdinalPolicy ordinalPolicy; - private final PathPolicy pathPolicy; - private final int partitionSize; - - public DefaultFacetIndexingParams() { - this(new CategoryListParams()); - } - - public DefaultFacetIndexingParams(CategoryListParams categoryListParams) { - clpParams = categoryListParams; - ordinalPolicy = fixedOrdinalPolicy(); - pathPolicy = fixedPathPolicy(); - partitionSize = fixedPartitionSize(); - } - - @Override - public CategoryListParams getCategoryListParams(CategoryPath category) { - return clpParams; - } - - @Override - public int drillDownTermText(CategoryPath path, char[] buffer) { - return path.copyToCharArray(buffer, 0, -1, getFacetDelimChar()); - } - - /** - * "fixed" partition size. - * @see #getPartitionSize() - */ - protected int fixedPartitionSize() { - return Integer.MAX_VALUE; - } - - /** - * "fixed" ordinal policy. - * @see #getOrdinalPolicy() - */ - protected OrdinalPolicy fixedOrdinalPolicy() { - return OrdinalPolicy.ALL_PARENTS; - } - - /** - * "fixed" path policy. - * @see #getPathPolicy() - */ - protected PathPolicy fixedPathPolicy() { - return PathPolicy.ALL_CATEGORIES; - } - - @Override - public final int getPartitionSize() { - return partitionSize; - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.lucene.facet.index.params.FacetIndexingParams#getAllCategoryListParams - * () - */ - @Override - public Iterable getAllCategoryListParams() { - List res = new ArrayList(); - res.add(clpParams); - return res; - } - - @Override - public final OrdinalPolicy getOrdinalPolicy() { - return ordinalPolicy; - } - - @Override - public final PathPolicy getPathPolicy() { - return pathPolicy; - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((clpParams == null) ? 0 : clpParams.hashCode()); - result = prime * result - + ((ordinalPolicy == null) ? 0 : ordinalPolicy.hashCode()); - result = prime * result + partitionSize; - result = prime * result - + ((pathPolicy == null) ? 0 : pathPolicy.hashCode()); - - for (CategoryListParams clp: getAllCategoryListParams()) { - result ^= clp.hashCode(); - } - - return result; - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof DefaultFacetIndexingParams)) { - return false; - } - DefaultFacetIndexingParams other = (DefaultFacetIndexingParams) obj; - if (clpParams == null) { - if (other.clpParams != null) { - return false; - } - } else if (!clpParams.equals(other.clpParams)) { - return false; - } - if (ordinalPolicy == null) { - if (other.ordinalPolicy != null) { - return false; - } - } else if (!ordinalPolicy.equals(other.ordinalPolicy)) { - return false; - } - if (partitionSize != other.partitionSize) { - return false; - } - if (pathPolicy == null) { - if (other.pathPolicy != null) { - return false; - } - } else if (!pathPolicy.equals(other.pathPolicy)) { - return false; - } - - Iterable cLs = getAllCategoryListParams(); - Iterable otherCLs = other.getAllCategoryListParams(); - - return cLs.equals(otherCLs); - } - - /** - * Use {@link #DEFAULT_FACET_DELIM_CHAR} as the delimiter. - */ - @Override - public char getFacetDelimChar() { - return DEFAULT_FACET_DELIM_CHAR; - } - -} Index: lucene/facet/src/java/org/apache/lucene/facet/index/params/FacetIndexingParams.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/index/params/FacetIndexingParams.java (revision 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/index/params/FacetIndexingParams.java (working copy) @@ -1,9 +1,11 @@ package org.apache.lucene.facet.index.params; -import java.io.Serializable; +import java.util.Collections; +import java.util.List; import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy; import org.apache.lucene.facet.index.categorypolicy.PathPolicy; +import org.apache.lucene.facet.search.FacetArrays; import org.apache.lucene.facet.taxonomy.CategoryPath; /* @@ -24,75 +26,198 @@ */ /** - * Parameters on how facets are to be written to the index. - * For example, which fields and terms are used to refer to the indexed posting list. - *

- * If non-default parameters were used during indexing, the same parameters - * must also be passed during faceted search. This requirement is analogous - * to the requirement during search to know which fields were indexed, and which - * Analyzer was used on the text. + * Defines parameters that are needed for facets indexing. Note that this class + * does not have any setters. That's because overriding the default parameters + * is considered expert. If you wish to override them, simply extend this class + * and override the relevant getter. * + *

+ * NOTE: This class is also used during faceted search in order to e.g. + * know which field holds the drill-down terms or the fulltree posting. + * Therefore this class should be initialized once and you should refrain from + * changing it. Also note that if you make any changes to it (e.g. suddenly + * deciding that drill-down terms should be read from a different field) and use + * it on an existing index, things may not work as expected. + * * @lucene.experimental */ -public interface FacetIndexingParams extends Serializable { +public class FacetIndexingParams { + + // the default CLP, can be a singleton + protected static final CategoryListParams DEFAULT_CATEGORY_LIST_PARAMS = new CategoryListParams(); /** - * The name of the category-list to put this category in, or null if this - * category should not be aggregatable. - *

+ * A {@link FacetIndexingParams} which fixes {@link OrdinalPolicy} to + * {@link OrdinalPolicy#NO_PARENTS}. This is a singleton equivalent to new + * {@link #FacetIndexingParams()}. + */ + public static final FacetIndexingParams ALL_PARENTS = new FacetIndexingParams(); + + /** + * The default delimiter with which {@link CategoryPath#getComponent(int) + * components} are concatenated when written to the index, e.g. as drill-down + * terms. If you choose to override it by overiding + * {@link #getFacetDelimChar()}, you should make sure that you return a + * character that's not found in any path component. + */ + public static final char DEFAULT_FACET_DELIM_CHAR = '\uF749'; + + private final OrdinalPolicy ordinalPolicy = OrdinalPolicy.ALL_PARENTS; + private final PathPolicy pathPolicy = PathPolicy.ALL_CATEGORIES; + private final int partitionSize = Integer.MAX_VALUE; + + protected final CategoryListParams clParams; + + /** Initializes new default params. */ + public FacetIndexingParams() { + this(DEFAULT_CATEGORY_LIST_PARAMS); + } + + /** Initializes new params with the given {@link CategoryListParams}. */ + public FacetIndexingParams(CategoryListParams categoryListParams) { + clParams = categoryListParams; + } + + /** + * The name of the category list to put this category in, or {@code null} if + * this category should not be aggregatable. + *

* By default, all categories are written to the same category list, but - * applications which know in advance that in some situations only parts - * of the category hierarchy needs to be counted can divide the categories - * into two or more different category lists. - *

- * If null is returned for a category, it means that this category should - * not appear in any category list, and thus counts for it cannot be - * aggregated. This category can still be used for drill-down, even though - * the count for it is not known. + * applications which know in advance that in some situations only parts of + * the category hierarchy needs to be counted can divide the categories into + * two or more different category lists. + *

+ * If {@code null} is returned for a category, it means that this category + * should not appear in any category list, and thus weights for it cannot be + * aggregated. This category can still be used for drill-down, even though the + * its weight is unknown. + * + * @see PerDimensionIndexingParams */ - public CategoryListParams getCategoryListParams(CategoryPath category); + public CategoryListParams getCategoryListParams(CategoryPath category) { + return clParams; + } /** - * Return info about all category lists in the index. + * Copies the text required to execute a drill-down query on the given + * category to the given {@code char[]}, and returns the number of characters + * that were written. + *

+ * NOTE: You should make sure that the {@code char[]} is large enough, + * by e.g. calling {@link CategoryPath#charsNeededForFullPath()}. + */ + public int drillDownTermText(CategoryPath path, char[] buffer) { + return path.copyToCharArray(buffer, 0, -1, getFacetDelimChar()); + } + + /** + * Returns the size of a partition. Partitions allow you to divide + * (hence, partition) the categories space into small sets to e.g. improve RAM + * consumption during faceted search. For instance, {@code partitionSize=100K} + * would mean that if your taxonomy index contains 420K categories, they will + * be divided into 5 groups and at search time a {@link FacetArrays} will be + * allocated at the size of the partition. * - * @see #getCategoryListParams(CategoryPath) + *

+ * This is real advanced setting and should be changed with care. By default, + * all categories are put in one partition. You should modify this setting if + * you have really large taxonomies (e.g. 1M+ nodes). */ - public Iterable getAllCategoryListParams(); + public int getPartitionSize() { + return partitionSize; + } - // TODO (Facet): Add special cases of exact/non-exact category term-text + /** + * Returns a list of all {@link CategoryListParams categoryListParams} that + * are used for facets indexing. + */ + public List getAllCategoryListParams() { + return Collections.singletonList(clParams); + } /** - * Return the drilldown Term-Text which does not need to do any allocations. - * The number of chars set is returned. - *

- * Note: Make sure buffer is large enough. - * @see CategoryPath#charsNeededForFullPath() + * Returns the {@link OrdinalPolicy} that is used during indexing. By default + * returns {@link OrdinalPolicy#ALL_PARENTS} which means that the full + * hierarchy will be stored for every document. */ - public int drillDownTermText(CategoryPath path, char[] buffer); + public OrdinalPolicy getOrdinalPolicy() { + return ordinalPolicy; + } /** - * Get the partition size. - * Same value should be used during the life time of an index. - * At search time this value is compared with actual taxonomy size and their minimum is used. + * Returns the {@link PathPolicy} that is used during indexing. By default + * returns {@link PathPolicy#ALL_CATEGORIES} which means that the full + * hierarchy is added as drill-down terms for every document. */ - public int getPartitionSize(); + public PathPolicy getPathPolicy() { + return pathPolicy; + } - /** - * Get the policy for indexing category paths, - * used for deciding how "high" to climb in taxonomy - * from a category when ingesting its category paths. + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((clParams == null) ? 0 : clParams.hashCode()); + result = prime * result + ((ordinalPolicy == null) ? 0 : ordinalPolicy.hashCode()); + result = prime * result + partitionSize; + result = prime * result + ((pathPolicy == null) ? 0 : pathPolicy.hashCode()); + + for (CategoryListParams clp : getAllCategoryListParams()) { + result ^= clp.hashCode(); + } + + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof FacetIndexingParams)) { + return false; + } + FacetIndexingParams other = (FacetIndexingParams) obj; + if (clParams == null) { + if (other.clParams != null) { + return false; + } + } else if (!clParams.equals(other.clParams)) { + return false; + } + if (ordinalPolicy == null) { + if (other.ordinalPolicy != null) { + return false; + } + } else if (!ordinalPolicy.equals(other.ordinalPolicy)) { + return false; + } + if (partitionSize != other.partitionSize) { + return false; + } + if (pathPolicy == null) { + if (other.pathPolicy != null) { + return false; + } + } else if (!pathPolicy.equals(other.pathPolicy)) { + return false; + } + + Iterable cLs = getAllCategoryListParams(); + Iterable otherCLs = other.getAllCategoryListParams(); + + return cLs.equals(otherCLs); + } + + /** + * Returns the delimiter character used internally for concatenating category + * path components, e.g. for drill-down terms. */ - public PathPolicy getPathPolicy(); + public char getFacetDelimChar() { + return DEFAULT_FACET_DELIM_CHAR; + } - /** - * Get the policy for indexing category ordinals, - * used for deciding how "high" to climb in taxonomy - * from a category when ingesting its ordinals - */ - public OrdinalPolicy getOrdinalPolicy(); - - /** - * Get the delimiter character used internally for drill-down terms - */ - public char getFacetDelimChar(); } Index: lucene/facet/src/java/org/apache/lucene/facet/index/params/PerDimensionIndexingParams.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/index/params/PerDimensionIndexingParams.java (revision 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/index/params/PerDimensionIndexingParams.java (working copy) @@ -2,7 +2,9 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; import org.apache.lucene.facet.taxonomy.CategoryPath; @@ -24,62 +26,59 @@ */ /** - * A FacetIndexingParams that utilizes different category lists, defined by the - * dimension specified CategoryPaths (see - * {@link PerDimensionIndexingParams#addCategoryListParams(CategoryPath, CategoryListParams)} + * A {@link FacetIndexingParams} that utilizes different category lists, defined + * by the dimension specified by a {@link CategoryPath category} (see + * {@link #PerDimensionIndexingParams(Map, CategoryListParams)}. *

* A 'dimension' is defined as the first or "zero-th" component in a - * CategoryPath. For example, if a CategoryPath is defined as - * "/Author/American/Mark Twain", then the dimension is "Author". - *

- * This class also uses the 'default' CategoryListParams (as specified by - * {@link CategoryListParams#CategoryListParams()} when - * {@link #getCategoryListParams(CategoryPath)} is called for a CategoryPath - * whose dimension component has not been specifically defined. + * {@link CategoryPath}. For example, if a category is defined as + * "Author/American/Mark Twain", then the dimension would be "Author". * * @lucene.experimental */ -public class PerDimensionIndexingParams extends DefaultFacetIndexingParams { +public class PerDimensionIndexingParams extends FacetIndexingParams { - // "Root" or "first component" of a Category Path maps to a - // CategoryListParams - private final Map clParamsMap = new HashMap(); + private final Map clParamsMap; /** - * Construct with the default {@link CategoryListParams} as the default - * CategoryListParams for unspecified CategoryPaths. + * Initializes a new instance with the given dimension-to-params mapping. The + * dimension is considered as what's returned by + * {@link CategoryPath#getComponent(int) cp.getComponent(0)}. + * + *

+ * NOTE: for any dimension whose {@link CategoryListParams} is not + * defined in the mapping, a default {@link CategoryListParams} will be used. + * + * @see #PerDimensionIndexingParams(Map, CategoryListParams) */ - public PerDimensionIndexingParams() { - this(new CategoryListParams()); + public PerDimensionIndexingParams(Map paramsMap) { + this(paramsMap, DEFAULT_CATEGORY_LIST_PARAMS); } /** - * Construct with the included categoryListParams as the default - * CategoryListParams for unspecified CategoryPaths. - * - * @param categoryListParams - * the default categoryListParams to use + * Same as {@link #PerDimensionIndexingParams(Map)}, only the given + * {@link CategoryListParams} will be used for any dimension that is not + * specified in the given mapping. */ - public PerDimensionIndexingParams(CategoryListParams categoryListParams) { + public PerDimensionIndexingParams(Map paramsMap, + CategoryListParams categoryListParams) { super(categoryListParams); + clParamsMap = new HashMap(); + for (Entry e : paramsMap.entrySet()) { + clParamsMap.put(e.getKey().getComponent(0), e.getValue()); + } } - /** - * Get all the categoryListParams, including the default. - */ @Override - public Iterable getAllCategoryListParams() { - ArrayList vals = - new ArrayList(clParamsMap.values()); - for (CategoryListParams clp : super.getAllCategoryListParams()) { - vals.add(clp); - } + public List getAllCategoryListParams() { + ArrayList vals = new ArrayList(clParamsMap.values()); + vals.add(clParams); // add the default too return vals; } /** - * Get the CategoryListParams based on the dimension or "zero-th category" - * of the specified CategoryPath. + * Returns the {@link CategoryListParams} for the corresponding dimension + * which is returned by {@code category.getComponent(0)}. */ @Override public CategoryListParams getCategoryListParams(CategoryPath category) { @@ -89,14 +88,7 @@ return clParams; } } - return super.getCategoryListParams(category); + return clParams; } - /** - * Add a CategoryListParams for a given CategoryPath's dimension or - * "zero-th" category. - */ - public void addCategoryListParams(CategoryPath category, CategoryListParams clParams) { - clParamsMap.put(category.getComponent(0), clParams); - } } Index: lucene/facet/src/java/org/apache/lucene/facet/index/streaming/CategoryParentsStream.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/index/streaming/CategoryParentsStream.java (revision 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/index/streaming/CategoryParentsStream.java (working copy) @@ -154,20 +154,17 @@ * using {@link #addRetainableProperty(Class)}. */ protected void clearCategoryProperties() { - if (this.retainableProperties == null - || this.retainableProperties.isEmpty()) { - this.categoryAttribute.clearProperties(); + if (retainableProperties == null || retainableProperties.isEmpty()) { + categoryAttribute.clearProperties(); } else { - List> propertyClassesToRemove = - new LinkedList>(); - for (Class propertyClass : this.categoryAttribute - .getPropertyClasses()) { - if (!this.retainableProperties.contains(propertyClass)) { - propertyClassesToRemove.add(propertyClass); + List> propsToRemove = new LinkedList>(); + for (Class propertyClass : categoryAttribute.getPropertyClasses()) { + if (!retainableProperties.contains(propertyClass)) { + propsToRemove.add(propertyClass); } } - for (Class propertyClass : propertyClassesToRemove) { - this.categoryAttribute.remove(propertyClass); + for (Class propertyClass : propsToRemove) { + categoryAttribute.remove(propertyClass); } } } Index: lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java =================================================================== --- lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java (revision 1420923) +++ lucene/facet/src/java/org/apache/lucene/facet/search/params/FacetSearchParams.java (working copy) @@ -3,7 +3,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams; import org.apache.lucene.facet.index.params.FacetIndexingParams; import org.apache.lucene.facet.search.cache.CategoryListCache; import org.apache.lucene.facet.search.results.FacetResult; @@ -64,7 +63,7 @@ * @see #addFacetRequest(FacetRequest) */ public FacetSearchParams() { - this(new DefaultFacetIndexingParams()); + this(FacetIndexingParams.ALL_PARENTS); } /** Index: lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/FacetTestBase.java (working copy) @@ -15,6 +15,18 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.TextField; +import org.apache.lucene.facet.index.CategoryDocumentBuilder; +import org.apache.lucene.facet.index.params.CategoryListParams; +import org.apache.lucene.facet.index.params.FacetIndexingParams; +import org.apache.lucene.facet.search.params.FacetRequest; +import org.apache.lucene.facet.search.params.FacetSearchParams; +import org.apache.lucene.facet.search.results.FacetResult; +import org.apache.lucene.facet.search.results.FacetResultNode; +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.DirectoryTaxonomyReader; +import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.DocsEnum; import org.apache.lucene.index.IndexReader; @@ -28,24 +40,10 @@ import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.store.Directory; - import org.apache.lucene.util.Bits; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util._TestUtil; -import org.apache.lucene.facet.index.CategoryDocumentBuilder; -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.params.FacetRequest; -import org.apache.lucene.facet.search.params.FacetSearchParams; -import org.apache.lucene.facet.search.results.FacetResult; -import org.apache.lucene.facet.search.results.FacetResultNode; -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.DirectoryTaxonomyReader; -import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -184,9 +182,9 @@ /** Returns a default facet indexing params */ protected FacetIndexingParams getFacetIndexingParams(final int partSize) { - return new DefaultFacetIndexingParams() { + return new FacetIndexingParams() { @Override - protected int fixedPartitionSize() { + public int getPartitionSize() { return partSize; } }; Index: lucene/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/FacetTestUtils.java (working copy) @@ -8,20 +8,7 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.TextField; -import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.index.RandomIndexWriter; -import org.apache.lucene.search.Collector; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.TopScoreDocCollector; -import org.apache.lucene.store.Directory; - -import org.apache.lucene.search.MultiCollector; -import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.facet.index.CategoryDocumentBuilder; -import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams; import org.apache.lucene.facet.index.params.FacetIndexingParams; import org.apache.lucene.facet.search.FacetsCollector; import org.apache.lucene.facet.search.params.CountFacetRequest; @@ -32,6 +19,17 @@ import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; +import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.search.Collector; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.MatchAllDocsQuery; +import org.apache.lucene.search.MultiCollector; +import org.apache.lucene.search.TopScoreDocCollector; +import org.apache.lucene.store.Directory; +import org.apache.lucene.util.LuceneTestCase; /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -91,8 +89,8 @@ } public static Collector[] search(IndexSearcher searcher, - TaxonomyReader taxonomyReader, DefaultFacetIndexingParams iParams, - int k, String... facetNames) throws IOException { + TaxonomyReader taxonomyReader, FacetIndexingParams iParams, int k, + String... facetNames) throws IOException { Collector[] collectors = new Collector[2]; Index: lucene/facet/src/test/org/apache/lucene/facet/enhancements/CategoryEnhancementDummy1.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/enhancements/CategoryEnhancementDummy1.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/enhancements/CategoryEnhancementDummy1.java (working copy) @@ -56,7 +56,7 @@ } @Override - public Class getRetainableProperty() { + public CategoryProperty getRetainableProperty() { return null; } Index: lucene/facet/src/test/org/apache/lucene/facet/enhancements/CategoryEnhancementDummy2.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/enhancements/CategoryEnhancementDummy2.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/enhancements/CategoryEnhancementDummy2.java (working copy) @@ -65,8 +65,8 @@ } @Override - public Class getRetainableProperty() { - return DummyProperty.class; + public CategoryProperty getRetainableProperty() { + return DummyProperty.INSTANCE; } @Override Index: lucene/facet/src/test/org/apache/lucene/facet/enhancements/CategoryEnhancementDummy3.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/enhancements/CategoryEnhancementDummy3.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/enhancements/CategoryEnhancementDummy3.java (working copy) @@ -64,7 +64,7 @@ } @Override - public Class getRetainableProperty() { + public CategoryProperty getRetainableProperty() { return null; } Index: lucene/facet/src/test/org/apache/lucene/facet/enhancements/TwoEnhancementsTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/enhancements/TwoEnhancementsTest.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/enhancements/TwoEnhancementsTest.java (working copy) @@ -7,22 +7,18 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; +import org.apache.lucene.facet.enhancements.params.EnhancementsIndexingParams; +import org.apache.lucene.facet.search.DrillDown; +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.index.IndexReader; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; +import org.apache.lucene.util.LuceneTestCase; import org.junit.Test; -import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.facet.enhancements.EnhancementsDocumentBuilder; -import org.apache.lucene.facet.enhancements.EnhancementsPayloadIterator; -import org.apache.lucene.facet.enhancements.params.DefaultEnhancementsIndexingParams; -import org.apache.lucene.facet.enhancements.params.EnhancementsIndexingParams; -import org.apache.lucene.facet.search.DrillDown; -import org.apache.lucene.facet.taxonomy.CategoryPath; -import org.apache.lucene.facet.taxonomy.TaxonomyWriter; -import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -47,10 +43,8 @@ Directory indexDir = newDirectory(); Directory taxoDir = newDirectory(); - EnhancementsIndexingParams indexingParams = - new DefaultEnhancementsIndexingParams( - new CategoryEnhancementDummy1(), - new CategoryEnhancementDummy3()); + EnhancementsIndexingParams indexingParams = new EnhancementsIndexingParams( + new CategoryEnhancementDummy1(), new CategoryEnhancementDummy3()); // add document with a category containing data for both enhancements List categoryPaths = new ArrayList(); @@ -93,10 +87,8 @@ Directory indexDir = newDirectory(); Directory taxoDir = newDirectory(); - EnhancementsIndexingParams indexingParams = - new DefaultEnhancementsIndexingParams( - new CategoryEnhancementDummy2(), - new CategoryEnhancementDummy3()); + EnhancementsIndexingParams indexingParams = new EnhancementsIndexingParams( + new CategoryEnhancementDummy2(), new CategoryEnhancementDummy3()); List categoryPaths = new ArrayList(); categoryPaths.add(new CategoryPath("a", "b")); Index: lucene/facet/src/test/org/apache/lucene/facet/enhancements/association/CustomAssociationPropertyTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/enhancements/association/CustomAssociationPropertyTest.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/enhancements/association/CustomAssociationPropertyTest.java (working copy) @@ -3,14 +3,7 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.RandomIndexWriter; -import org.apache.lucene.store.Directory; -import org.junit.Test; - -import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.facet.enhancements.EnhancementsDocumentBuilder; -import org.apache.lucene.facet.enhancements.params.DefaultEnhancementsIndexingParams; import org.apache.lucene.facet.enhancements.params.EnhancementsIndexingParams; import org.apache.lucene.facet.index.CategoryContainer; import org.apache.lucene.facet.index.attributes.CategoryAttributeImpl; @@ -18,6 +11,11 @@ import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.RandomIndexWriter; +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 @@ -51,8 +49,7 @@ } final int NUM_CATEGORIES = 10; - EnhancementsIndexingParams iParams = new DefaultEnhancementsIndexingParams( - new AssociationEnhancement()); + EnhancementsIndexingParams iParams = new EnhancementsIndexingParams(new AssociationEnhancement()); Directory iDir = newDirectory(); Directory tDir = newDirectory(); Index: lucene/facet/src/test/org/apache/lucene/facet/enhancements/params/DefaultEnhancementsIndexingParamsTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/enhancements/params/DefaultEnhancementsIndexingParamsTest.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/enhancements/params/DefaultEnhancementsIndexingParamsTest.java (working copy) @@ -1,67 +0,0 @@ -package org.apache.lucene.facet.enhancements.params; - -import java.util.List; - -import org.junit.Test; - -import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.facet.enhancements.CategoryEnhancement; -import org.apache.lucene.facet.enhancements.CategoryEnhancementDummy1; -import org.apache.lucene.facet.enhancements.CategoryEnhancementDummy2; -import org.apache.lucene.facet.enhancements.params.DefaultEnhancementsIndexingParams; -import org.apache.lucene.facet.enhancements.params.EnhancementsIndexingParams; -import org.apache.lucene.facet.index.DummyProperty; -import org.apache.lucene.facet.index.attributes.CategoryProperty; - -/* - * 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. - */ - -public class DefaultEnhancementsIndexingParamsTest extends LuceneTestCase { - - @Test - public void testCategoryEnhancements() { - EnhancementsIndexingParams params = - new DefaultEnhancementsIndexingParams( - new CategoryEnhancementDummy1()); - - // check retainable properties - List> retainableProps = params - .getRetainableProperties(); - assertNull("Unexpected content in retainable list", retainableProps); - - params.addCategoryEnhancements(new CategoryEnhancementDummy2()); - - List enhancements = params - .getCategoryEnhancements(); - - assertEquals("Wrong number of enhancements", 2, enhancements.size()); - - assertTrue("Wrong first enhancement", - enhancements.get(0) instanceof CategoryEnhancementDummy1); - assertTrue("Wrong second enhancement", - enhancements.get(1) instanceof CategoryEnhancementDummy2); - - // re-check retainable properties - retainableProps = params.getRetainableProperties(); - assertNotNull("Unexpected empty retainable list", retainableProps); - assertEquals("Unexpected size of retainable list", 1, retainableProps - .size()); - assertEquals("Wrong property in retainable list", DummyProperty.class, - retainableProps.get(0)); - - } -} Index: lucene/facet/src/test/org/apache/lucene/facet/enhancements/params/EnhancementsIndexingParamsTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/enhancements/params/EnhancementsIndexingParamsTest.java (working copy) +++ lucene/facet/src/test/org/apache/lucene/facet/enhancements/params/EnhancementsIndexingParamsTest.java (working copy) @@ -2,16 +2,13 @@ import java.util.List; -import org.junit.Test; - -import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.facet.enhancements.CategoryEnhancement; import org.apache.lucene.facet.enhancements.CategoryEnhancementDummy1; import org.apache.lucene.facet.enhancements.CategoryEnhancementDummy2; -import org.apache.lucene.facet.enhancements.params.DefaultEnhancementsIndexingParams; -import org.apache.lucene.facet.enhancements.params.EnhancementsIndexingParams; import org.apache.lucene.facet.index.DummyProperty; import org.apache.lucene.facet.index.attributes.CategoryProperty; +import org.apache.lucene.util.LuceneTestCase; +import org.junit.Test; /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -30,38 +27,25 @@ * limitations under the License. */ -public class DefaultEnhancementsIndexingParamsTest extends LuceneTestCase { +public class EnhancementsIndexingParamsTest extends LuceneTestCase { @Test public void testCategoryEnhancements() { - EnhancementsIndexingParams params = - new DefaultEnhancementsIndexingParams( - new CategoryEnhancementDummy1()); + EnhancementsIndexingParams params = new EnhancementsIndexingParams( + new CategoryEnhancementDummy1(), new CategoryEnhancementDummy2()); - // check retainable properties - List> retainableProps = params - .getRetainableProperties(); - assertNull("Unexpected content in retainable list", retainableProps); - - params.addCategoryEnhancements(new CategoryEnhancementDummy2()); - - List enhancements = params - .getCategoryEnhancements(); - + List enhancements = params.getCategoryEnhancements(); assertEquals("Wrong number of enhancements", 2, enhancements.size()); - assertTrue("Wrong first enhancement", - enhancements.get(0) instanceof CategoryEnhancementDummy1); - assertTrue("Wrong second enhancement", - enhancements.get(1) instanceof CategoryEnhancementDummy2); + // check order + assertTrue("Wrong first enhancement", enhancements.get(0) instanceof CategoryEnhancementDummy1); + assertTrue("Wrong second enhancement", enhancements.get(1) instanceof CategoryEnhancementDummy2); - // re-check retainable properties - retainableProps = params.getRetainableProperties(); + // check retainable properties + List retainableProps = params.getRetainableProperties(); assertNotNull("Unexpected empty retainable list", retainableProps); - assertEquals("Unexpected size of retainable list", 1, retainableProps - .size()); - assertEquals("Wrong property in retainable list", DummyProperty.class, - retainableProps.get(0)); - + assertEquals("Unexpected size of retainable list", 1, retainableProps.size()); + assertSame("Wrong property in retainable list", DummyProperty.INSTANCE, retainableProps.get(0)); } + } Index: lucene/facet/src/test/org/apache/lucene/facet/index/CategoryContainerTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/index/CategoryContainerTest.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/index/CategoryContainerTest.java (working copy) @@ -62,7 +62,7 @@ @Test public void testExistingNewCategoryWithProperty() throws FacetException { categoryContainer.addCategory(new CategoryPath("five", "six"), - new DummyProperty()); + DummyProperty.INSTANCE); Iterator iterator = categoryContainer.iterator(); // count the number of tokens, and check there is one DummyAttribute @@ -83,12 +83,12 @@ AssociationProperty associationProperty = new AssociationIntProperty( 49); categoryContainer.addCategory(new CategoryPath("five", "six"), - new DummyProperty(), associationProperty); + DummyProperty.INSTANCE, associationProperty); categoryContainer.addCategory(new CategoryPath("seven", "eight"), - new DummyProperty()); + DummyProperty.INSTANCE); associationProperty = new AssociationIntProperty(123); categoryContainer.addCategory(new CategoryPath("nine"), - associationProperty, new DummyProperty()); + associationProperty, DummyProperty.INSTANCE); Iterator iterator = categoryContainer.iterator(); // count the number of tokens, and check there is one DummyAttribute @@ -114,7 +114,7 @@ @Test public void testAddNewCategoryWithProperty() throws FacetException { categoryContainer.addCategory(new CategoryPath("seven", "eight"), - new DummyProperty()); + DummyProperty.INSTANCE); Iterator iterator = categoryContainer.iterator(); // count the number of tokens, and check there is one DummyAttribute @@ -150,7 +150,7 @@ public void testAddCategoryAttributeWithProperty() throws FacetException { CategoryAttribute newCA = new CategoryAttributeImpl(new CategoryPath( "seven", "eight")); - newCA.addProperty(new DummyProperty()); + newCA.addProperty(DummyProperty.INSTANCE); categoryContainer.addCategory(newCA); Iterator iterator = categoryContainer.iterator(); @@ -215,12 +215,12 @@ AssociationProperty associationProperty = new AssociationIntProperty( 49); categoryContainer.addCategory(new CategoryPath("five", "six"), - new DummyProperty(), associationProperty); + DummyProperty.INSTANCE, associationProperty); categoryContainer.addCategory(new CategoryPath("seven", "eight"), - new DummyProperty()); + DummyProperty.INSTANCE); associationProperty = new AssociationIntProperty(123); categoryContainer.addCategory(new CategoryPath("nine"), - associationProperty, new DummyProperty()); + associationProperty, DummyProperty.INSTANCE); ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); ObjectOutputStream out = new ObjectOutputStream(baos); Index: lucene/facet/src/test/org/apache/lucene/facet/index/DummyProperty.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/index/DummyProperty.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/index/DummyProperty.java (working copy) @@ -24,6 +24,10 @@ */ public class DummyProperty implements CategoryProperty { + public static final DummyProperty INSTANCE = new DummyProperty(); + + private DummyProperty() {} + @Override public boolean equals(Object o) { if (o instanceof DummyProperty) { Index: lucene/facet/src/test/org/apache/lucene/facet/index/attributes/CategoryAttributeImplTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/index/attributes/CategoryAttributeImplTest.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/index/attributes/CategoryAttributeImplTest.java (working copy) @@ -57,15 +57,15 @@ .getProperty(DummyProperty.class)); assertNull("Attribute classes should be null", ca.getPropertyClasses()); - ca.addProperty(new DummyProperty()); + ca.addProperty(DummyProperty.INSTANCE); assertEquals("DummyProperty should be in properties", - new DummyProperty(), ca.getProperty(DummyProperty.class)); + DummyProperty.INSTANCE, ca.getProperty(DummyProperty.class)); assertEquals("Attribute classes should contain 1 element", 1, ca .getPropertyClasses().size()); boolean failed = false; try { - ca.addProperty(new DummyProperty()); + ca.addProperty(DummyProperty.INSTANCE); } catch (UnsupportedOperationException e) { failed = true; } @@ -77,24 +77,24 @@ ca.clearProperties(); assertNull("Attribute classes should be null", ca.getPropertyClasses()); - ca.addProperty(new DummyProperty()); + ca.addProperty(DummyProperty.INSTANCE); assertEquals("DummyProperty should be in properties", - new DummyProperty(), ca.getProperty(DummyProperty.class)); + DummyProperty.INSTANCE, ca.getProperty(DummyProperty.class)); ca.remove(DummyProperty.class); assertEquals("DummyProperty should not be in properties", null, ca .getProperty(DummyProperty.class)); assertNull("Attribute classes should be null", ca.getPropertyClasses()); - ca.addProperty(new DummyProperty()); + ca.addProperty(DummyProperty.INSTANCE); List> propertyClasses = new ArrayList>(); assertEquals("No property expected when no classes given", null, ca .getProperty(propertyClasses)); propertyClasses.add(DummyProperty.class); assertEquals("DummyProperty should be in properties", - new DummyProperty(), ca.getProperty(propertyClasses)); + DummyProperty.INSTANCE, ca.getProperty(propertyClasses)); propertyClasses.add(OrdinalProperty.class); assertEquals("DummyProperty should be in properties", - new DummyProperty(), ca.getProperty(propertyClasses)); + DummyProperty.INSTANCE, ca.getProperty(propertyClasses)); propertyClasses.clear(); propertyClasses.add(OrdinalProperty.class); assertEquals("No ordinal property expected", null, ca @@ -107,7 +107,7 @@ CategoryPath cp = new CategoryPath("a", "b"); ca1.setCategoryPath(cp); - ca1.addProperty(new DummyProperty()); + ca1.addProperty(DummyProperty.INSTANCE); CategoryAttribute ca2 = ca1.clone(); assertEquals("Error in cloning", ca1, ca2); 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 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/index/params/DefaultFacetIndexingParamsTest.java (working copy) @@ -1,109 +0,0 @@ -package org.apache.lucene.facet.index.params; - -import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy; -import org.apache.lucene.facet.index.categorypolicy.PathPolicy; -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 - * 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. - */ - -public class DefaultFacetIndexingParamsTest extends LuceneTestCase { - - @Test - public void testDefaultSettings() { - FacetIndexingParams dfip = new DefaultFacetIndexingParams(); - assertNotNull("Missing default category list", dfip - .getAllCategoryListParams()); - assertEquals( - "all categories have the same CategoryListParams by default", - dfip.getCategoryListParams(null), dfip - .getCategoryListParams(new CategoryPath("a"))); - assertEquals( - "Expected default category list term is $facets:$fulltree$", - new Term("$facets", "$fulltree$"), dfip.getCategoryListParams( - null).getTerm()); - String expectedDDText = "a" - + dfip.getFacetDelimChar() + "b"; - CategoryPath cp = new CategoryPath("a", "b"); - assertEquals("wrong drill-down term", new Term("$facets", - expectedDDText), DrillDown.term(dfip,cp)); - char[] buf = new char[20]; - int numchars = dfip.drillDownTermText(cp, buf); - assertEquals("3 characters should be written", 3, numchars); - assertEquals("wrong drill-down term text", expectedDDText, new String( - buf, 0, numchars)); - CategoryListParams clParams = dfip.getCategoryListParams(null); - assertEquals("partition for all ordinals is the first", "$fulltree$", - PartitionsUtils.partitionNameByOrdinal(dfip, clParams , 250)); - assertEquals("for partition 0, the same name should be returned", - "$fulltree$", PartitionsUtils.partitionName(clParams, 0)); - assertEquals( - "for any other, it's the concatenation of name + partition", - "$fulltree$1", PartitionsUtils.partitionName(clParams, 1)); - assertEquals("default partition number is always 0", 0, - PartitionsUtils.partitionNumber(dfip,100)); - assertEquals("default partition size is unbounded", Integer.MAX_VALUE, - dfip.getPartitionSize()); - } - - @Test - public void testCategoryListParamsWithDefaultIndexingParams() { - CategoryListParams clp = new CategoryListParams( - new Term("clp", "value")); - FacetIndexingParams dfip = new DefaultFacetIndexingParams(clp); - assertEquals("Expected default category list term is " + clp.getTerm(), - clp.getTerm(), dfip.getCategoryListParams(null).getTerm()); - } - - @Test - public void testCategoryPolicies() { - FacetIndexingParams dfip = new DefaultFacetIndexingParams(); - // check path policy - CategoryPath cp = new CategoryPath(); - 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]; - for (int j = 0; j < components.length; j++) { - components[j] = (Integer.valueOf(random().nextInt(30))).toString(); - } - cp = new CategoryPath(components); - assertEquals("path policy does not match default for " + cp.toString('/'), - pathPolicy.shouldAdd(cp), dfip.getPathPolicy().shouldAdd(cp)); - } - - // check ordinal policy - 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, - ordinalPolicy.shouldAdd(ordinal), - dfip.getOrdinalPolicy().shouldAdd(ordinal)); - } - } - -} \ No newline at end of file Index: lucene/facet/src/test/org/apache/lucene/facet/index/params/FacetIndexingParamsTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/index/params/FacetIndexingParamsTest.java (working copy) +++ lucene/facet/src/test/org/apache/lucene/facet/index/params/FacetIndexingParamsTest.java (working copy) @@ -27,21 +27,16 @@ * limitations under the License. */ -public class DefaultFacetIndexingParamsTest extends LuceneTestCase { +public class FacetIndexingParamsTest extends LuceneTestCase { @Test public void testDefaultSettings() { - FacetIndexingParams dfip = new DefaultFacetIndexingParams(); - assertNotNull("Missing default category list", dfip - .getAllCategoryListParams()); - assertEquals( - "all categories have the same CategoryListParams by default", - dfip.getCategoryListParams(null), dfip - .getCategoryListParams(new CategoryPath("a"))); - assertEquals( - "Expected default category list term is $facets:$fulltree$", - new Term("$facets", "$fulltree$"), dfip.getCategoryListParams( - null).getTerm()); + FacetIndexingParams dfip = FacetIndexingParams.ALL_PARENTS; + assertNotNull("Missing default category list", dfip.getAllCategoryListParams()); + assertEquals("all categories have the same CategoryListParams by default", + dfip.getCategoryListParams(null), dfip.getCategoryListParams(new CategoryPath("a"))); + assertEquals("Expected default category list term is $facets:$fulltree$", + new Term("$facets", "$fulltree$"), dfip.getCategoryListParams(null).getTerm()); String expectedDDText = "a" + dfip.getFacetDelimChar() + "b"; CategoryPath cp = new CategoryPath("a", "b"); @@ -70,14 +65,14 @@ public void testCategoryListParamsWithDefaultIndexingParams() { CategoryListParams clp = new CategoryListParams( new Term("clp", "value")); - FacetIndexingParams dfip = new DefaultFacetIndexingParams(clp); + FacetIndexingParams dfip = new FacetIndexingParams(clp); assertEquals("Expected default category list term is " + clp.getTerm(), clp.getTerm(), dfip.getCategoryListParams(null).getTerm()); } @Test public void testCategoryPolicies() { - FacetIndexingParams dfip = new DefaultFacetIndexingParams(); + FacetIndexingParams dfip = FacetIndexingParams.ALL_PARENTS; // check path policy CategoryPath cp = new CategoryPath(); PathPolicy pathPolicy = PathPolicy.ALL_CATEGORIES; Index: lucene/facet/src/test/org/apache/lucene/facet/index/params/PerDimensionIndexingParamsTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/index/params/PerDimensionIndexingParamsTest.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/index/params/PerDimensionIndexingParamsTest.java (working copy) @@ -1,15 +1,13 @@ package org.apache.lucene.facet.index.params; -import org.apache.lucene.index.Term; -import org.junit.Test; +import java.util.Collections; -import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.facet.index.params.CategoryListParams; -import org.apache.lucene.facet.index.params.FacetIndexingParams; -import org.apache.lucene.facet.index.params.PerDimensionIndexingParams; import org.apache.lucene.facet.search.DrillDown; import org.apache.lucene.facet.taxonomy.CategoryPath; 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 @@ -32,9 +30,8 @@ @Test public void testTopLevelSettings() { - FacetIndexingParams ifip = new PerDimensionIndexingParams(); - assertNotNull("Missing default category list", ifip - .getAllCategoryListParams()); + FacetIndexingParams ifip = new PerDimensionIndexingParams(Collections.emptyMap()); + assertNotNull("Missing default category list", ifip.getAllCategoryListParams()); assertEquals( "Expected default category list term is $facets:$fulltree$", new Term("$facets", "$fulltree$"), ifip.getCategoryListParams( @@ -67,15 +64,12 @@ @Test public void testCategoryListParamsAddition() { - PerDimensionIndexingParams tlfip = new PerDimensionIndexingParams(); - CategoryListParams clp = new CategoryListParams( - new Term("clp", "value")); - tlfip.addCategoryListParams(new CategoryPath("a"), clp); - assertEquals("Expected category list term is " + clp.getTerm(), clp - .getTerm(), tlfip.getCategoryListParams(new CategoryPath("a")) - .getTerm()); - assertNotSame("Unexpected default category list " + clp.getTerm(), clp, - tlfip.getCategoryListParams(null)); + CategoryListParams clp = new CategoryListParams(new Term("clp", "value")); + PerDimensionIndexingParams tlfip = new PerDimensionIndexingParams( + Collections. singletonMap(new CategoryPath("a"), clp)); + assertEquals("Expected category list term is " + clp.getTerm(), + clp.getTerm(), tlfip.getCategoryListParams(new CategoryPath("a")).getTerm()); + assertNotSame("Unexpected default category list " + clp.getTerm(), clp, tlfip.getCategoryListParams(null)); } } \ No newline at end of file Index: lucene/facet/src/test/org/apache/lucene/facet/index/streaming/CategoryParentsStreamTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/index/streaming/CategoryParentsStreamTest.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/index/streaming/CategoryParentsStreamTest.java (working copy) @@ -3,20 +3,17 @@ import java.io.IOException; import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.store.Directory; -import org.junit.Test; - -import org.apache.lucene.facet.FacetException; import org.apache.lucene.facet.index.CategoryContainerTestBase; import org.apache.lucene.facet.index.DummyProperty; import org.apache.lucene.facet.index.categorypolicy.NonTopLevelOrdinalPolicy; import org.apache.lucene.facet.index.categorypolicy.NonTopLevelPathPolicy; import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy; import org.apache.lucene.facet.index.categorypolicy.PathPolicy; -import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams; import org.apache.lucene.facet.index.params.FacetIndexingParams; import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; +import org.apache.lucene.store.Directory; +import org.junit.Test; /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -49,7 +46,7 @@ directory); CategoryParentsStream stream = new CategoryParentsStream( new CategoryAttributesStream(categoryContainer), - taxonomyWriter, new DefaultFacetIndexingParams()); + taxonomyWriter, FacetIndexingParams.ALL_PARENTS); // count the number of tokens int nTokens; @@ -72,13 +69,13 @@ Directory directory = newDirectory(); final TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter( directory); - FacetIndexingParams indexingParams = new DefaultFacetIndexingParams() { + FacetIndexingParams indexingParams = new FacetIndexingParams() { @Override - protected OrdinalPolicy fixedOrdinalPolicy() { + public OrdinalPolicy getOrdinalPolicy() { return new NonTopLevelOrdinalPolicy(); } @Override - protected PathPolicy fixedPathPolicy() { + public PathPolicy getPathPolicy() { return new NonTopLevelPathPolicy(); } }; @@ -110,15 +107,14 @@ Directory directory = newDirectory(); TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(directory); - new CategoryParentsStream(new CategoryAttributesStream(categoryContainer), - taxonomyWriter, new DefaultFacetIndexingParams()); + assertNotNull(new CategoryParentsStream(new CategoryAttributesStream(categoryContainer), + taxonomyWriter, FacetIndexingParams.ALL_PARENTS)); // add DummyAttribute, but do not retain, only one expected - categoryContainer.addCategory(initialCatgeories[0], new DummyProperty()); + categoryContainer.addCategory(initialCatgeories[0], DummyProperty.INSTANCE); CategoryParentsStream stream = new CategoryParentsStream(new CategoryAttributesStream( - categoryContainer), taxonomyWriter, - new DefaultFacetIndexingParams()); + categoryContainer), taxonomyWriter, FacetIndexingParams.ALL_PARENTS); int nAttributes = 0; while (stream.incrementToken()) { @@ -139,24 +135,21 @@ @Test public void testRetainableAttributes() throws IOException { Directory directory = newDirectory(); - TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter( - directory); + TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(directory); - FacetIndexingParams indexingParams = new DefaultFacetIndexingParams(); - new CategoryParentsStream(new CategoryAttributesStream( - categoryContainer), taxonomyWriter, indexingParams); + FacetIndexingParams indexingParams = FacetIndexingParams.ALL_PARENTS; + assertNotNull(new CategoryParentsStream(new CategoryAttributesStream( + categoryContainer), taxonomyWriter, indexingParams)); // add DummyAttribute and retain it, three expected categoryContainer.clear(); - categoryContainer - .addCategory(initialCatgeories[0], new DummyProperty()); + categoryContainer.addCategory(initialCatgeories[0], DummyProperty.INSTANCE); CategoryParentsStream stream = new CategoryParentsStream( new CategoryAttributesStream(categoryContainer), - taxonomyWriter, new DefaultFacetIndexingParams()); + taxonomyWriter, FacetIndexingParams.ALL_PARENTS); stream.addRetainableProperty(DummyProperty.class); - MyCategoryListTokenizer tokenizer = new MyCategoryListTokenizer(stream, - indexingParams); + MyCategoryListTokenizer tokenizer = new MyCategoryListTokenizer(stream, indexingParams); int nAttributes = 0; try { Index: lucene/facet/src/test/org/apache/lucene/facet/index/streaming/CategoryTokenizerTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/index/streaming/CategoryTokenizerTest.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/index/streaming/CategoryTokenizerTest.java (working copy) @@ -7,17 +7,14 @@ import java.util.Set; import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; -import org.apache.lucene.store.Directory; -import org.junit.Test; - import org.apache.lucene.facet.index.CategoryContainerTestBase; import org.apache.lucene.facet.index.attributes.CategoryAttributesIterable; -import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams; -import org.apache.lucene.facet.index.streaming.CategoryAttributesStream; -import org.apache.lucene.facet.index.streaming.CategoryTokenizer; +import org.apache.lucene.facet.index.params.FacetIndexingParams; 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.junit.Test; /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -47,7 +44,7 @@ Directory directory = newDirectory(); TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter( directory); - DefaultFacetIndexingParams indexingParams = new DefaultFacetIndexingParams(); + FacetIndexingParams indexingParams = FacetIndexingParams.ALL_PARENTS; CategoryTokenizer tokenizer = new CategoryTokenizer( new CategoryAttributesStream(categoryContainer), indexingParams); @@ -89,7 +86,7 @@ longCategory.add(new CategoryPath("one", "two", "three", "four", "five", "six", "seven")); - DefaultFacetIndexingParams indexingParams = new DefaultFacetIndexingParams(); + FacetIndexingParams indexingParams = FacetIndexingParams.ALL_PARENTS; CategoryTokenizer tokenizer = new CategoryTokenizer( new CategoryAttributesStream(new CategoryAttributesIterable( longCategory)), indexingParams); Index: lucene/facet/src/test/org/apache/lucene/facet/search/DrillDownTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/search/DrillDownTest.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/search/DrillDownTest.java (working copy) @@ -2,6 +2,8 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; @@ -57,13 +59,10 @@ private static Directory taxoDir; public DrillDownTest() { - PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(); - CategoryListParams aClParams = new CategoryListParams(new Term("testing_facets_a", "a")); - CategoryListParams bClParams = new CategoryListParams(new Term("testing_facets_b", "b")); - - iParams.addCategoryListParams(new CategoryPath("a"), aClParams); - iParams.addCategoryListParams(new CategoryPath("b"), bClParams); - + Map paramsMap = new HashMap(); + paramsMap.put(new CategoryPath("a"), new CategoryListParams(new Term("testing_facets_a", "a"))); + paramsMap.put(new CategoryPath("b"), new CategoryListParams(new Term("testing_facets_b", "b"))); + PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(paramsMap); nonDefaultParams = new FacetSearchParams(iParams); } Index: lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/search/TestMultipleCategoryLists.java (working copy) @@ -1,8 +1,11 @@ package org.apache.lucene.facet.search; import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; @@ -70,7 +73,7 @@ /** * Configure with no custom counting lists */ - PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(); + PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(Collections.emptyMap()); seedIndex(iw, tw, iParams); @@ -109,9 +112,9 @@ TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE); - PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(); - iParams.addCategoryListParams(new CategoryPath("Author"), - new CategoryListParams(new Term("$author", "Authors"))); + PerDimensionIndexingParams iParams = new PerDimensionIndexingParams( + Collections.singletonMap(new CategoryPath("Author"), + new CategoryListParams(new Term("$author", "Authors")))); seedIndex(iw, tw, iParams); IndexReader ir = iw.getReader(); @@ -148,11 +151,10 @@ TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE); - PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(); - iParams.addCategoryListParams(new CategoryPath("Band"), - new CategoryListParams(new Term("$music", "Bands"))); - iParams.addCategoryListParams(new CategoryPath("Composer"), - new CategoryListParams(new Term("$music", "Composers"))); + Map paramsMap = new HashMap(); + paramsMap.put(new CategoryPath("Band"), new CategoryListParams(new Term("$music", "Bands"))); + paramsMap.put(new CategoryPath("Composer"), new CategoryListParams(new Term("$music", "Composers"))); + PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(paramsMap); seedIndex(iw, tw, iParams); IndexReader ir = iw.getReader(); @@ -195,11 +197,10 @@ // create and open a taxonomy writer TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE); - PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(); - iParams.addCategoryListParams(new CategoryPath("Band"), - new CategoryListParams(new Term("$bands", "Bands"))); - iParams.addCategoryListParams(new CategoryPath("Composer"), - new CategoryListParams(new Term("$composers", "Composers"))); + Map paramsMap = new HashMap(); + paramsMap.put(new CategoryPath("Band"), new CategoryListParams(new Term("$bands", "Bands"))); + paramsMap.put(new CategoryPath("Composer"), new CategoryListParams(new Term("$composers", "Composers"))); + PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(paramsMap); seedIndex(iw, tw, iParams); IndexReader ir = iw.getReader(); @@ -236,13 +237,11 @@ TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE); - PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(); - iParams.addCategoryListParams(new CategoryPath("Band"), - new CategoryListParams(new Term("$music", "music"))); - iParams.addCategoryListParams(new CategoryPath("Composer"), - new CategoryListParams(new Term("$music", "music"))); - iParams.addCategoryListParams(new CategoryPath("Author"), - new CategoryListParams(new Term("$literature", "Authors"))); + Map paramsMap = new HashMap(); + paramsMap.put(new CategoryPath("Band"), new CategoryListParams(new Term("$music", "music"))); + paramsMap.put(new CategoryPath("Composer"), new CategoryListParams(new Term("$music", "music"))); + paramsMap.put(new CategoryPath("Author"), new CategoryListParams(new Term("$literature", "Authors"))); + PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(paramsMap); seedIndex(iw, tw, iParams); Index: lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/search/TestTopKInEachNodeResultHandler.java (working copy) @@ -8,22 +8,11 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.TextField; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriterConfig.OpenMode; -import org.apache.lucene.index.RandomIndexWriter; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TermQuery; -import org.apache.lucene.store.Directory; -import org.junit.Test; - -import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.facet.index.CategoryDocumentBuilder; -import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams; +import org.apache.lucene.facet.index.params.FacetIndexingParams; import org.apache.lucene.facet.search.params.CountFacetRequest; +import org.apache.lucene.facet.search.params.FacetRequest.ResultMode; import org.apache.lucene.facet.search.params.FacetSearchParams; -import org.apache.lucene.facet.search.params.FacetRequest.ResultMode; import org.apache.lucene.facet.search.results.FacetResult; import org.apache.lucene.facet.search.results.FacetResultNode; import org.apache.lucene.facet.taxonomy.CategoryPath; @@ -31,6 +20,16 @@ import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; import org.apache.lucene.facet.util.PartitionsUtils; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriterConfig.OpenMode; +import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.TermQuery; +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 @@ -69,9 +68,9 @@ } final int pSize = partitionSize; - DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams() { + FacetIndexingParams iParams = new FacetIndexingParams() { @Override - protected int fixedPartitionSize() { + public int getPartitionSize() { return pSize; } }; @@ -318,8 +317,8 @@ } - private void prvt_add(DefaultFacetIndexingParams iParams, RandomIndexWriter iw, - TaxonomyWriter tw, String... strings) throws IOException { + private void prvt_add(FacetIndexingParams iParams, RandomIndexWriter iw, + TaxonomyWriter tw, String... strings) throws IOException { ArrayList cps = new ArrayList(); CategoryPath cp = new CategoryPath(strings); cps.add(cp); Index: lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCounts.java (working copy) @@ -4,17 +4,16 @@ import java.io.IOException; import java.util.Arrays; +import org.apache.lucene.facet.FacetTestUtils; +import org.apache.lucene.facet.FacetTestUtils.IndexTaxonomyReaderPair; +import org.apache.lucene.facet.FacetTestUtils.IndexTaxonomyWriterPair; +import org.apache.lucene.facet.index.params.FacetIndexingParams; import org.apache.lucene.store.Directory; import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util._TestUtil; import org.junit.Test; -import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.facet.FacetTestUtils; -import org.apache.lucene.facet.FacetTestUtils.IndexTaxonomyReaderPair; -import org.apache.lucene.facet.FacetTestUtils.IndexTaxonomyWriterPair; -import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams; - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -56,9 +55,9 @@ // Create our index/taxonomy writers IndexTaxonomyWriterPair[] writers = FacetTestUtils .createIndexTaxonomyWriterPair(dirs); - DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams() { + FacetIndexingParams iParams = new FacetIndexingParams() { @Override - protected int fixedPartitionSize() { + public int getPartitionSize() { return partitionSize; } }; Index: lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/search/TestTotalFacetCountsCache.java (working copy) @@ -8,16 +8,6 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; -import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.store.Directory; -import org.apache.lucene.store.MockDirectoryWrapper; -import org.junit.Before; -import org.junit.Test; - -import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.facet.FacetTestUtils; import org.apache.lucene.facet.FacetTestUtils.IndexTaxonomyReaderPair; import org.apache.lucene.facet.FacetTestUtils.IndexTaxonomyWriterPair; @@ -26,7 +16,6 @@ import org.apache.lucene.facet.example.multiCL.MultiCLIndexer; import org.apache.lucene.facet.example.multiCL.MultiCLSearcher; import org.apache.lucene.facet.index.CategoryDocumentBuilder; -import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams; import org.apache.lucene.facet.index.params.FacetIndexingParams; import org.apache.lucene.facet.search.TotalFacetCounts.CreationType; import org.apache.lucene.facet.search.results.FacetResult; @@ -36,9 +25,18 @@ import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; +import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.SlowRAMDirectory; import org.apache.lucene.util._TestUtil; +import org.junit.Before; +import org.junit.Test; /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -196,7 +194,7 @@ // it references a different TFC cache. This will still result // in valid results, but will only search one of the category lists // instead of all of them. - multis[numThreads - 1] = new Multi(slowIndexReader, slowTaxoReader, new DefaultFacetIndexingParams()); + multis[numThreads - 1] = new Multi(slowIndexReader, slowTaxoReader, FacetIndexingParams.ALL_PARENTS); // Gentleman, start your engines for (Multi m : multis) { @@ -252,7 +250,7 @@ // Create our index/taxonomy writers IndexTaxonomyWriterPair[] writers = FacetTestUtils.createIndexTaxonomyWriterPair(dirs); - DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams(); + FacetIndexingParams iParams = FacetIndexingParams.ALL_PARENTS; // Add a facet to the index addFacets(iParams, writers[0].indexWriter, writers[0].taxWriter, "a", "b"); @@ -347,11 +345,10 @@ // Create temporary RAMDirectories Directory[][] dirs = FacetTestUtils.createIndexTaxonomyDirs(1); // Create our index/taxonomy writers - IndexTaxonomyWriterPair[] writers = FacetTestUtils - .createIndexTaxonomyWriterPair(dirs); - DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams() { + IndexTaxonomyWriterPair[] writers = FacetTestUtils.createIndexTaxonomyWriterPair(dirs); + FacetIndexingParams iParams = new FacetIndexingParams() { @Override - protected int fixedPartitionSize() { + public int getPartitionSize() { return 2; } }; @@ -403,7 +400,7 @@ IndexWriter w = new IndexWriter(indexDir, new IndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false))); DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir); - DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams(); + FacetIndexingParams iParams = FacetIndexingParams.ALL_PARENTS; // Add documents and facets for (int i = 0; i < 1000; i++) { addFacets(iParams, w, tw, "facet", Integer.toString(i)); @@ -454,7 +451,7 @@ Directory[][] dirs = FacetTestUtils.createIndexTaxonomyDirs(2); // Create our index/taxonomy writers IndexTaxonomyWriterPair[] writers = FacetTestUtils.createIndexTaxonomyWriterPair(dirs); - DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams(); + FacetIndexingParams iParams = FacetIndexingParams.ALL_PARENTS; // Add a facet to the index addFacets(iParams, writers[0].indexWriter, writers[0].taxWriter, "a", "b"); Index: lucene/facet/src/test/org/apache/lucene/facet/search/association/AssociationsFacetRequestTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/search/association/AssociationsFacetRequestTest.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/search/association/AssociationsFacetRequestTest.java (working copy) @@ -2,17 +2,6 @@ import java.util.List; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.RandomIndexWriter; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.store.Directory; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; @@ -20,7 +9,7 @@ import org.apache.lucene.facet.enhancements.association.AssociationEnhancement; import org.apache.lucene.facet.enhancements.association.AssociationFloatProperty; import org.apache.lucene.facet.enhancements.association.AssociationIntProperty; -import org.apache.lucene.facet.enhancements.params.DefaultEnhancementsIndexingParams; +import org.apache.lucene.facet.enhancements.params.EnhancementsIndexingParams; import org.apache.lucene.facet.index.CategoryContainer; import org.apache.lucene.facet.search.FacetsCollector; import org.apache.lucene.facet.search.params.FacetSearchParams; @@ -31,6 +20,16 @@ import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.MatchAllDocsQuery; +import org.apache.lucene.search.Query; +import org.apache.lucene.store.Directory; +import org.apache.lucene.util.LuceneTestCase; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -72,8 +71,7 @@ TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir); EnhancementsDocumentBuilder builder = new EnhancementsDocumentBuilder( - taxoWriter, new DefaultEnhancementsIndexingParams( - new AssociationEnhancement())); + taxoWriter, new EnhancementsIndexingParams(new AssociationEnhancement())); // index documents, 50% have only 'b' and all have 'a' for (int i = 0; i < 100; i++) { Index: lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/search/params/FacetSearchParamsTest.java (working copy) @@ -1,16 +1,15 @@ package org.apache.lucene.facet.search.params; -import org.apache.lucene.store.Directory; -import org.junit.Test; - -import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams; +import org.apache.lucene.facet.index.params.FacetIndexingParams; 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.DirectoryTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; import org.apache.lucene.facet.util.PartitionsUtils; +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 +33,7 @@ @Test public void testDefaultSettings() throws Exception { FacetSearchParams fsp = new FacetSearchParams(); - assertEquals("unexpected default facet indexing params class", DefaultFacetIndexingParams.class.getName(), fsp.getFacetIndexingParams().getClass().getName()); + assertSame("unexpected default facet indexing params class", FacetIndexingParams.ALL_PARENTS, fsp.getFacetIndexingParams()); assertEquals("no facet requests should be added by default", 0, fsp.getFacetRequests().size()); Directory dir = newDirectory(); new DirectoryTaxonomyWriter(dir).close(); Index: lucene/facet/src/test/org/apache/lucene/facet/search/params/MultiIteratorsPerCLParamsTest.java =================================================================== --- lucene/facet/src/test/org/apache/lucene/facet/search/params/MultiIteratorsPerCLParamsTest.java (revision 1420923) +++ lucene/facet/src/test/org/apache/lucene/facet/search/params/MultiIteratorsPerCLParamsTest.java (working copy) @@ -7,16 +7,8 @@ import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.document.Document; -import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.RandomIndexWriter; -import org.apache.lucene.store.Directory; -import org.junit.Test; - -import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.facet.index.CategoryDocumentBuilder; 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.CategoryListIterator; import org.apache.lucene.facet.search.FacetArrays; @@ -35,6 +27,12 @@ import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter; import org.apache.lucene.facet.util.ScoredDocIdsUtils; +import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.RandomIndexWriter; +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 @@ -87,7 +85,7 @@ // Create a CLP which generates different CLIs according to the // FacetRequest's dimension CategoryListParams clp = new CategoryListParams(); - FacetIndexingParams iParams = new DefaultFacetIndexingParams(clp); + FacetIndexingParams iParams = new FacetIndexingParams(clp); Directory indexDir = newDirectory(); Directory taxoDir = newDirectory(); populateIndex(iParams, indexDir, taxoDir);