1 package org.apache.lucene.facet.search.params;
3 import org.apache.lucene.index.IndexReader;
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;
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 * Facet request for counting facets.
32 * @lucene.experimental
34 public class CountFacetRequest extends FacetRequest {
37 * Create a count facet request for a given node in the taxonomy.
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)}.
45 public CountFacetRequest(CategoryPath path, int num) {
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();
56 return new ComplementCountingAggregator(a);
58 return new CountingAggregator(a);
62 public double getValueOf(FacetArrays arrays, int ordinal) {
63 return arrays.getIntArray()[ordinal];
67 public boolean supportsComplements() {
72 public boolean requireDocumentScore() {