1
package org.apache.lucene.facet.index.params;
3
import java.util.ArrayList;
6
import org.apache.lucene.facet.index.categorypolicy.DefaultOrdinalPolicy;
7
import org.apache.lucene.facet.index.categorypolicy.DefaultPathPolicy;
8
import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy;
9
import org.apache.lucene.facet.index.categorypolicy.PathPolicy;
10
import org.apache.lucene.facet.taxonomy.CategoryPath;
13
* Licensed to the Apache Software Foundation (ASF) under one or more
14
* contributor license agreements. See the NOTICE file distributed with
15
* this work for additional information regarding copyright ownership.
16
* The ASF licenses this file to You under the Apache License, Version 2.0
17
* (the "License"); you may not use this file except in compliance with
18
* the License. You may obtain a copy of the License at
20
* http://www.apache.org/licenses/LICENSE-2.0
22
* Unless required by applicable law or agreed to in writing, software
23
* distributed under the License is distributed on an "AS IS" BASIS,
24
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
* See the License for the specific language governing permissions and
26
* limitations under the License.
30
* Default implementation for {@link FacetIndexingParams}.
32
* Getters for <em>partition-size</em>, {@link OrdinalPolicy} and
33
* {@link PathPolicy} are all final, and so the proper way to modify them when
34
* extending this class is through {@link #fixedPartitionSize()},
35
* {@link #fixedOrdinalPolicy()} or {@link #fixedPathPolicy()} accordingly.
37
* @lucene.experimental
39
public class DefaultFacetIndexingParams implements FacetIndexingParams {
42
* delimiter between a categories in a path, e.g. Products FACET_DELIM
43
* Consumer FACET_DELIM Tv. This should be a character not found in any path
46
public static final char DEFAULT_FACET_DELIM_CHAR = '\uF749';
48
private final CategoryListParams clpParams;
49
private final OrdinalPolicy ordinalPolicy;
50
private final PathPolicy pathPolicy;
51
private final int partitionSize;
53
public DefaultFacetIndexingParams() {
54
this(new CategoryListParams());
57
public DefaultFacetIndexingParams(CategoryListParams categoryListParams) {
58
clpParams = categoryListParams;
59
ordinalPolicy = fixedOrdinalPolicy();
60
pathPolicy = fixedPathPolicy();
61
partitionSize = fixedPartitionSize();
64
public CategoryListParams getCategoryListParams(CategoryPath category) {
68
public int drillDownTermText(CategoryPath path, char[] buffer) {
69
return path.copyToCharArray(buffer, 0, -1, getFacetDelimChar());
73
* "fixed" partition size.
74
* @see #getPartitionSize()
76
protected int fixedPartitionSize() {
77
return Integer.MAX_VALUE;
81
* "fixed" ordinal policy.
82
* @see #getOrdinalPolicy()
84
protected OrdinalPolicy fixedOrdinalPolicy() {
85
return new DefaultOrdinalPolicy();
89
* "fixed" path policy.
90
* @see #getPathPolicy()
92
protected PathPolicy fixedPathPolicy() {
93
return new DefaultPathPolicy();
96
public final int getPartitionSize() {
104
* org.apache.lucene.facet.index.params.FacetIndexingParams#getAllCategoryListParams
107
public Iterable<CategoryListParams> getAllCategoryListParams() {
108
List<CategoryListParams> res = new ArrayList<CategoryListParams>();
113
public final OrdinalPolicy getOrdinalPolicy() {
114
return ordinalPolicy;
117
public final PathPolicy getPathPolicy() {
122
* @see java.lang.Object#hashCode()
125
public int hashCode() {
126
final int prime = 31;
128
result = prime * result
129
+ ((clpParams == null) ? 0 : clpParams.hashCode());
130
result = prime * result
131
+ ((ordinalPolicy == null) ? 0 : ordinalPolicy.hashCode());
132
result = prime * result + partitionSize;
133
result = prime * result
134
+ ((pathPolicy == null) ? 0 : pathPolicy.hashCode());
136
for (CategoryListParams clp: getAllCategoryListParams()) {
137
result ^= clp.hashCode();
144
* @see java.lang.Object#equals(java.lang.Object)
147
public boolean equals(Object obj) {
154
if (!(obj instanceof DefaultFacetIndexingParams)) {
157
DefaultFacetIndexingParams other = (DefaultFacetIndexingParams) obj;
158
if (clpParams == null) {
159
if (other.clpParams != null) {
162
} else if (!clpParams.equals(other.clpParams)) {
165
if (ordinalPolicy == null) {
166
if (other.ordinalPolicy != null) {
169
} else if (!ordinalPolicy.equals(other.ordinalPolicy)) {
172
if (partitionSize != other.partitionSize) {
175
if (pathPolicy == null) {
176
if (other.pathPolicy != null) {
179
} else if (!pathPolicy.equals(other.pathPolicy)) {
183
Iterable<CategoryListParams> cLs = getAllCategoryListParams();
184
Iterable<CategoryListParams> otherCLs = other.getAllCategoryListParams();
186
return cLs.equals(otherCLs);
190
* Use {@link #DEFAULT_FACET_DELIM_CHAR} as the delimiter.
192
public char getFacetDelimChar() {
193
return DEFAULT_FACET_DELIM_CHAR;