1 package org.apache.lucene.facet.search.params;
3 import java.util.ArrayList;
6 import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams;
7 import org.apache.lucene.facet.index.params.FacetIndexingParams;
8 import org.apache.lucene.facet.search.cache.CategoryListCache;
9 import org.apache.lucene.facet.search.results.FacetResult;
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed with
14 * this work for additional information regarding copyright ownership.
15 * The ASF licenses this file to You under the Apache License, Version 2.0
16 * (the "License"); you may not use this file except in compliance with
17 * the License. You may obtain a copy of the License at
19 * http://www.apache.org/licenses/LICENSE-2.0
21 * Unless required by applicable law or agreed to in writing, software
22 * distributed under the License is distributed on an "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 * See the License for the specific language governing permissions and
25 * limitations under the License.
29 * Faceted search parameters indicate for which facets should info be gathered.
31 * The contained facet requests define for which facets should info be gathered.
33 * Contained faceted indexing parameters provide required info on how
34 * to read and interpret the underlying faceted information in the search index.
36 * @lucene.experimental
38 public class FacetSearchParams {
40 protected final FacetIndexingParams indexingParams;
41 protected final List<FacetRequest> facetRequests;
42 private CategoryListCache clCache = null;
45 * Construct with specific faceted indexing parameters.
46 * It is important to know the indexing parameters so as to e.g.
47 * read facets data correctly from the index.
48 * {@link #addFacetRequest(FacetRequest)} must be called at least once
49 * for this faceted search to find any faceted result.
50 * @param indexingParams Indexing faceted parameters which were used at indexing time.
51 * @see #addFacetRequest(FacetRequest)
53 public FacetSearchParams(FacetIndexingParams indexingParams) {
54 this.indexingParams = indexingParams;
55 facetRequests = new ArrayList<FacetRequest>();
59 * Construct with default faceted indexing parameters.
60 * Usage of this constructor is valid only if also during indexing the
61 * default faceted indexing parameters were used.
62 * {@link #addFacetRequest(FacetRequest)} must be called at least once
63 * for this faceted search to find any faceted result.
64 * @see #addFacetRequest(FacetRequest)
66 public FacetSearchParams() {
67 this(new DefaultFacetIndexingParams());
71 * A list of {@link FacetRequest} objects, determining what to count.
72 * If the returned collection is empty, the faceted search will return no facet results!
74 public final FacetIndexingParams getFacetIndexingParams() {
75 return indexingParams;
79 * Parameters which controlled the indexing of facets, and which are also
80 * needed during search.
82 public final List<FacetRequest> getFacetRequests() {
87 * Add a facet request to apply for this faceted search.
88 * This method must be called at least once for faceted search
89 * to find any faceted result. <br>
90 * NOTE: The order of addition implies the order of the {@link FacetResult}s
91 * @param facetRequest facet request to be added.
93 public void addFacetRequest(FacetRequest facetRequest) {
94 if (facetRequest == null) {
95 throw new IllegalArgumentException("Provided facetRequest must not be null");
97 facetRequests.add(facetRequest);
101 public String toString() {
102 final char TAB = '\t';
103 final char NEWLINE = '\n';
105 StringBuilder sb = new StringBuilder("IndexingParams: ");
106 sb.append(NEWLINE).append(TAB).append(getFacetIndexingParams());
108 sb.append(NEWLINE).append("FacetRequests:");
109 for (FacetRequest facetRequest : getFacetRequests()) {
110 sb.append(NEWLINE).append(TAB).append(facetRequest);
113 return sb.toString();
117 * @return the cldCache in effect
119 public CategoryListCache getClCache() {
124 * Set Cached Category Lists data to be used in Faceted search.
125 * @param clCache the cldCache to set
127 public void setClCache(CategoryListCache clCache) {
128 this.clCache = clCache;