1
package org.apache.lucene.facet.search;
3
import java.io.IOException;
4
import java.util.Arrays;
7
import org.apache.lucene.index.CorruptIndexException;
8
import org.apache.lucene.index.IndexWriterConfig;
9
import org.apache.lucene.index.RandomIndexWriter;
10
import org.apache.lucene.util._TestUtil;
12
import org.apache.lucene.analysis.Analyzer;
13
import org.apache.lucene.facet.FacetTestBase;
14
import org.apache.lucene.facet.index.params.FacetIndexingParams;
15
import org.apache.lucene.facet.search.params.CountFacetRequest;
16
import org.apache.lucene.facet.search.params.FacetSearchParams;
17
import org.apache.lucene.facet.taxonomy.CategoryPath;
18
import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
21
* Licensed to the Apache Software Foundation (ASF) under one or more
22
* contributor license agreements. See the NOTICE file distributed with
23
* this work for additional information regarding copyright ownership.
24
* The ASF licenses this file to You under the Apache License, Version 2.0
25
* (the "License"); you may not use this file except in compliance with
26
* the License. You may obtain a copy of the License at
28
* http://www.apache.org/licenses/LICENSE-2.0
30
* Unless required by applicable law or agreed to in writing, software
31
* distributed under the License is distributed on an "AS IS" BASIS,
32
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33
* See the License for the specific language governing permissions and
34
* limitations under the License.
37
public abstract class BaseTestTopK extends FacetTestBase {
39
protected static final String ALPHA = "alpha";
40
protected static final String BETA = "beta";
42
/** partition sizes on which the tests are run */
43
protected static int[] partitionSizes = new int[] { 2, 3, 100, Integer.MAX_VALUE };
45
/** Categories are generated from range [0,maxCategory) */
46
protected static int maxCategory = 5000;
47
private static final int categoriesPow2 = maxCategory * maxCategory;
53
protected void populateIndex(RandomIndexWriter iw, TaxonomyWriter taxo,
54
FacetIndexingParams iParams) throws IOException, CorruptIndexException {
56
super.populateIndex(iw, taxo, iParams);
59
/** prepare the next random int */
60
private void nextInt(int doc) {
61
if (currDoc == doc ) {
65
nextInt = random.nextInt(categoriesPow2);
66
nextInt = (int)Math.sqrt(nextInt);
70
protected String getContent(int doc) {
72
if (random.nextDouble() > 0.1) {
73
return ALPHA + ' ' + BETA;
79
protected List<CategoryPath> getCategories(int doc) {
81
CategoryPath cp = new CategoryPath(
83
Integer.toString(nextInt / 1000),
84
Integer.toString(nextInt / 100),
85
Integer.toString(nextInt / 10));
87
System.out.println("Adding CP: " + cp.toString());
89
return Arrays.asList(new CategoryPath[] { cp });
92
protected FacetSearchParams searchParamsWithRequests(int numResults) {
93
return searchParamsWithRequests(numResults, Integer.MAX_VALUE);
96
protected FacetSearchParams searchParamsWithRequests(int numResults, int partitionSize) {
97
FacetSearchParams res = getFacetedSearchParams(partitionSize);
98
res.addFacetRequest(new CountFacetRequest(new CategoryPath("a"), numResults));
99
res.addFacetRequest(new CountFacetRequest(new CategoryPath("a", "1"), numResults));
100
res.addFacetRequest(new CountFacetRequest(new CategoryPath("a", "1", "10"), numResults));
101
res.addFacetRequest(new CountFacetRequest(new CategoryPath("a", "2", "26", "267"), numResults));
106
protected int numDocsToIndex() {
111
protected IndexWriterConfig getIndexWriterConfig(Analyzer analyzer) {
112
return super.getIndexWriterConfig(analyzer).setMaxBufferedDocs(_TestUtil.nextInt(random, 500, 10000));