1 package org.apache.lucene.facet.util;
3 import org.apache.lucene.facet.index.params.CategoryListParams;
4 import org.apache.lucene.facet.index.params.FacetIndexingParams;
5 import org.apache.lucene.facet.search.params.FacetSearchParams;
6 import org.apache.lucene.facet.taxonomy.TaxonomyReader;
9 * Licensed to the Apache Software Foundation (ASF) under one or more
10 * contributor license agreements. See the NOTICE file distributed with
11 * this work for additional information regarding copyright ownership.
12 * The ASF licenses this file to You under the Apache License, Version 2.0
13 * (the "License"); you may not use this file except in compliance with
14 * the License. You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
26 * Utilities for partitions - sizes and such
28 * @lucene.experimental
30 public final class PartitionsUtils {
33 * Get the offset for a given partition. That is, what is the minimum number an
34 * ordinal could be for a particular partition.
36 public final static int partitionOffset ( FacetIndexingParams iParams,
38 final TaxonomyReader taxonomyReader) {
39 return partitionNumber * partitionSize(iParams, taxonomyReader);
43 * @see #partitionOffset(FacetIndexingParams, int, TaxonomyReader)
45 public final static int partitionOffset ( FacetSearchParams sParams,
47 final TaxonomyReader taxonomyReader) {
48 return partitionOffset(sParams.getFacetIndexingParams(), partitionNumber, taxonomyReader);
52 * Get the partition size in this parameter, or return the size of the taxonomy, which
53 * is smaller. (Guarantees usage of as little memory as possible at search time).
55 public final static int partitionSize(FacetIndexingParams indexingParams, final TaxonomyReader taxonomyReader) {
56 return Math.min(indexingParams.getPartitionSize(), taxonomyReader.getSize());
60 * @see #partitionSize(FacetIndexingParams, TaxonomyReader)
62 public final static int partitionSize(FacetSearchParams sParams, final TaxonomyReader taxonomyReader) {
63 return partitionSize(sParams.getFacetIndexingParams(), taxonomyReader);
67 * Partition number of an ordinal.
69 * This allows to locate the partition containing a certain (facet) ordinal.
70 * @see FacetIndexingParams#getPartitionSize()
72 public final static int partitionNumber(FacetIndexingParams iParams, int ordinal) {
73 return ordinal / iParams.getPartitionSize();
77 * @see #partitionNumber(FacetIndexingParams, int)
79 public final static int partitionNumber(FacetSearchParams sParams, int ordinal) {
80 return partitionNumber(sParams.getFacetIndexingParams(), ordinal);
84 * Partition name by category ordinal
86 public final static String partitionNameByOrdinal( FacetIndexingParams iParams,
87 CategoryListParams clParams,
89 int partition = partitionNumber(iParams, ordinal);
90 return partitionName(clParams, partition);
94 * Partition name by its number
96 public final static String partitionName(CategoryListParams clParams, int partition) {
97 String term = clParams.getTerm().text();
99 return term; // for backwards compatibility we do not add a partition number in this case
101 return term + partition;