1 package org.apache.lucene.facet.index.params;
3 import java.util.ArrayList;
4 import java.util.HashMap;
7 import org.apache.lucene.facet.taxonomy.CategoryPath;
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed with
12 * this work for additional information regarding copyright ownership.
13 * The ASF licenses this file to You under the Apache License, Version 2.0
14 * (the "License"); you may not use this file except in compliance with
15 * the License. You may obtain a copy of the License at
17 * http://www.apache.org/licenses/LICENSE-2.0
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
27 * A FacetIndexingParams that utilizes different category lists, defined by the
28 * dimension specified CategoryPaths (see
29 * {@link PerDimensionIndexingParams#addCategoryListParams(CategoryPath, CategoryListParams)}
31 * A 'dimension' is defined as the first or "zero-th" component in a
32 * CategoryPath. For example, if a CategoryPath is defined as
33 * "/Author/American/Mark Twain", then the dimension is "Author".
35 * This class also uses the 'default' CategoryListParams (as specified by
36 * {@link CategoryListParams#CategoryListParams()} when
37 * {@link #getCategoryListParams(CategoryPath)} is called for a CategoryPath
38 * whose dimension component has not been specifically defined.
40 * @lucene.experimental
42 public class PerDimensionIndexingParams extends DefaultFacetIndexingParams {
44 // "Root" or "first component" of a Category Path maps to a
46 private final Map<String, CategoryListParams> clParamsMap = new HashMap<String, CategoryListParams>();
49 * Construct with the default {@link CategoryListParams} as the default
50 * CategoryListParams for unspecified CategoryPaths.
52 public PerDimensionIndexingParams() {
53 this(new CategoryListParams());
57 * Construct with the included categoryListParams as the default
58 * CategoryListParams for unspecified CategoryPaths.
60 * @param categoryListParams
61 * the default categoryListParams to use
63 public PerDimensionIndexingParams(CategoryListParams categoryListParams) {
64 super(categoryListParams);
68 * Get all the categoryListParams, including the default.
71 public Iterable<CategoryListParams> getAllCategoryListParams() {
72 ArrayList<CategoryListParams> vals =
73 new ArrayList<CategoryListParams>(clParamsMap.values());
74 for (CategoryListParams clp : super.getAllCategoryListParams()) {
81 * Get the CategoryListParams based on the dimension or "zero-th category"
82 * of the specified CategoryPath.
85 public CategoryListParams getCategoryListParams(CategoryPath category) {
86 if (category != null) {
87 CategoryListParams clParams = clParamsMap.get(category.getComponent(0));
88 if (clParams != null) {
92 return super.getCategoryListParams(category);
96 * Add a CategoryListParams for a given CategoryPath's dimension or
102 public void addCategoryListParams(CategoryPath category, CategoryListParams clParams) {
103 clParamsMap.put(category.getComponent(0), clParams);