1 package org.apache.lucene.facet.search.params;
3 import org.apache.lucene.store.Directory;
6 import org.apache.lucene.util.LuceneTestCase;
7 import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams;
8 import org.apache.lucene.facet.taxonomy.CategoryPath;
9 import org.apache.lucene.facet.taxonomy.TaxonomyReader;
10 import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
11 import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader;
12 import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter;
13 import org.apache.lucene.facet.util.PartitionsUtils;
16 * Licensed to the Apache Software Foundation (ASF) under one or more
17 * contributor license agreements. See the NOTICE file distributed with
18 * this work for additional information regarding copyright ownership.
19 * The ASF licenses this file to You under the Apache License, Version 2.0
20 * (the "License"); you may not use this file except in compliance with
21 * the License. You may obtain a copy of the License at
23 * http://www.apache.org/licenses/LICENSE-2.0
25 * Unless required by applicable law or agreed to in writing, software
26 * distributed under the License is distributed on an "AS IS" BASIS,
27 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 * See the License for the specific language governing permissions and
29 * limitations under the License.
32 public class FacetSearchParamsTest extends LuceneTestCase {
35 public void testDefaultSettings() throws Exception {
36 FacetSearchParams fsp = new FacetSearchParams();
37 assertEquals("unexpected default facet indexing params class", DefaultFacetIndexingParams.class.getName(), fsp.getFacetIndexingParams().getClass().getName());
38 assertEquals("no facet requests should be added by default", 0, fsp.getFacetRequests().size());
39 Directory dir = newDirectory();
40 new LuceneTaxonomyWriter(dir).close();
41 TaxonomyReader tr = new LuceneTaxonomyReader(dir);
42 assertEquals("unexpected partition offset for 0 categories", 1, PartitionsUtils.partitionOffset(fsp, 1, tr));
43 assertEquals("unexpected partition size for 0 categories", 1, PartitionsUtils.partitionSize(fsp,tr));
49 public void testAddFacetRequest() throws Exception {
50 FacetSearchParams fsp = new FacetSearchParams();
51 fsp.addFacetRequest(new CountFacetRequest(new CategoryPath("a", "b"), 1));
52 assertEquals("expected 1 facet request", 1, fsp.getFacetRequests().size());
56 public void testPartitionSizeWithCategories() throws Exception {
57 FacetSearchParams fsp = new FacetSearchParams();
58 Directory dir = newDirectory();
59 TaxonomyWriter tw = new LuceneTaxonomyWriter(dir);
60 tw.addCategory(new CategoryPath("a"));
63 TaxonomyReader tr = new LuceneTaxonomyReader(dir);
64 assertEquals("unexpected partition offset for 1 categories", 2, PartitionsUtils.partitionOffset(fsp, 1, tr));
65 assertEquals("unexpected partition size for 1 categories", 2, PartitionsUtils.partitionSize(fsp,tr));
71 public void testSearchParamsWithNullRequest() throws Exception {
72 FacetSearchParams fsp = new FacetSearchParams();
74 fsp.addFacetRequest(null);
75 fail("FacetSearchParams should throw IllegalArgumentException when trying to add a null FacetRequest");
76 } catch (IllegalArgumentException e) {