pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / facet / src / java / org / apache / lucene / facet / search / params / CountFacetRequest.java
1 package org.apache.lucene.facet.search.params;
2
3 import org.apache.lucene.index.IndexReader;
4
5 import org.apache.lucene.facet.search.FacetArrays;
6 import org.apache.lucene.facet.search.aggregator.Aggregator;
7 import org.apache.lucene.facet.search.aggregator.ComplementCountingAggregator;
8 import org.apache.lucene.facet.search.aggregator.CountingAggregator;
9 import org.apache.lucene.facet.taxonomy.CategoryPath;
10 import org.apache.lucene.facet.taxonomy.TaxonomyReader;
11
12 /**
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
19  *
20  *     http://www.apache.org/licenses/LICENSE-2.0
21  *
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.
27  */
28
29 /**
30  * Facet request for counting facets.
31  * 
32  * @lucene.experimental
33  */
34 public class CountFacetRequest extends FacetRequest {
35
36   /**
37    * Create a count facet request for a given node in the taxonomy.
38    * 
39    * @param path category path of the category of interest.
40    * @param num number of child categories for which count info is requeted.
41    *        reqiested. Default implementation will find <b>top</b> categories, -
42    *        this behavior can be overridden by overriding
43    *        {@link #createFacetResultsHandler(TaxonomyReader)}.
44    */
45   public CountFacetRequest(CategoryPath path, int num) {
46     super(path, num);
47   }
48
49   @Override
50   public Aggregator createAggregator(boolean useComplements,
51                                       FacetArrays arrays, IndexReader reader,
52                                       TaxonomyReader taxonomy) {
53     // we rely on that, if needed, result is cleared by arrays!
54     int[] a = arrays.getIntArray();
55     if (useComplements) {
56       return new ComplementCountingAggregator(a);
57     }
58     return new CountingAggregator(a);
59   }
60
61   @Override
62   public double getValueOf(FacetArrays arrays, int ordinal) {
63     return arrays.getIntArray()[ordinal];
64   }
65
66   @Override
67   public boolean supportsComplements() {
68     return true;
69   }
70   
71   @Override
72   public boolean requireDocumentScore() {
73     return false;
74   }
75 }