add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / facet / src / java / org / apache / lucene / facet / search / params / FacetSearchParams.java
1 package org.apache.lucene.facet.search.params;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
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;
10
11 /**
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
18  *
19  *     http://www.apache.org/licenses/LICENSE-2.0
20  *
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.
26  */
27
28 /**
29  * Faceted search parameters indicate for which facets should info be gathered.
30  * <p>
31  * The contained facet requests define for which facets should info be gathered.
32  * <p>
33  * Contained faceted indexing parameters provide required info on how
34  * to read and interpret the underlying faceted information in the search index.   
35  * 
36  * @lucene.experimental
37  */
38 public class FacetSearchParams {
39
40   protected final FacetIndexingParams indexingParams;
41   protected final List<FacetRequest> facetRequests;
42   private CategoryListCache clCache = null;
43
44   /**
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)
52    */
53   public FacetSearchParams(FacetIndexingParams indexingParams) {
54     this.indexingParams = indexingParams;
55     facetRequests = new ArrayList<FacetRequest>();
56   }
57
58   /**
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)
65    */
66   public FacetSearchParams() {
67     this(new DefaultFacetIndexingParams());
68   }
69
70   /**
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!
73    */
74   public final FacetIndexingParams getFacetIndexingParams() {
75     return indexingParams;
76   }
77
78   /**
79    * Parameters which controlled the indexing of facets, and which are also
80    * needed during search.
81    */
82   public final List<FacetRequest> getFacetRequests() {
83     return facetRequests;
84   }
85
86   /**
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.
92    */
93   public void addFacetRequest(FacetRequest facetRequest) {
94     if (facetRequest == null) {
95       throw new IllegalArgumentException("Provided facetRequest must not be null");
96     }
97     facetRequests.add(facetRequest);
98   }
99   
100   @Override
101   public String toString() {
102     final char TAB = '\t';
103     final char NEWLINE = '\n';
104
105     StringBuilder sb = new StringBuilder("IndexingParams: ");
106     sb.append(NEWLINE).append(TAB).append(getFacetIndexingParams());
107     
108     sb.append(NEWLINE).append("FacetRequests:");
109     for (FacetRequest facetRequest : getFacetRequests()) {
110       sb.append(NEWLINE).append(TAB).append(facetRequest);
111     }
112     
113     return sb.toString();
114   }
115
116   /**
117    * @return the cldCache in effect
118    */
119   public CategoryListCache getClCache() {
120     return clCache;
121   }
122
123   /**
124    * Set Cached Category Lists data to be used in Faceted search.
125    * @param clCache the cldCache to set
126    */
127   public void setClCache(CategoryListCache clCache) {
128     this.clCache = clCache;
129   }
130 }