pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / facet / src / test / org / apache / lucene / facet / index / params / PerDimensionIndexingParamsTest.java
1 package org.apache.lucene.facet.index.params;
2
3 import org.apache.lucene.index.Term;
4 import org.junit.Test;
5
6 import org.apache.lucene.util.LuceneTestCase;
7 import org.apache.lucene.facet.index.params.CategoryListParams;
8 import org.apache.lucene.facet.index.params.FacetIndexingParams;
9 import org.apache.lucene.facet.index.params.PerDimensionIndexingParams;
10 import org.apache.lucene.facet.search.DrillDown;
11 import org.apache.lucene.facet.taxonomy.CategoryPath;
12 import org.apache.lucene.facet.util.PartitionsUtils;
13
14 /**
15  * Licensed to the Apache Software Foundation (ASF) under one or more
16  * contributor license agreements.  See the NOTICE file distributed with
17  * this work for additional information regarding copyright ownership.
18  * The ASF licenses this file to You under the Apache License, Version 2.0
19  * (the "License"); you may not use this file except in compliance with
20  * the License.  You may obtain a copy of the License at
21  *
22  *     http://www.apache.org/licenses/LICENSE-2.0
23  *
24  * Unless required by applicable law or agreed to in writing, software
25  * distributed under the License is distributed on an "AS IS" BASIS,
26  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27  * See the License for the specific language governing permissions and
28  * limitations under the License.
29  */
30
31 public class PerDimensionIndexingParamsTest extends LuceneTestCase {
32
33   @Test
34   public void testTopLevelSettings() {
35     FacetIndexingParams ifip = new PerDimensionIndexingParams();
36     assertNotNull("Missing default category list", ifip
37         .getAllCategoryListParams());
38     assertEquals(
39         "Expected default category list term is $facets:$fulltree$",
40         new Term("$facets", "$fulltree$"), ifip.getCategoryListParams(
41             null).getTerm());
42     String expectedDDText = "a"
43         + ifip.getFacetDelimChar() + "b";
44     CategoryPath cp = new CategoryPath("a", "b");
45     assertEquals("wrong drill-down term", new Term("$facets",
46         expectedDDText), DrillDown.term(ifip,cp));
47     char[] buf = new char[20];
48     int numchars = ifip.drillDownTermText(cp, buf);
49     assertEquals("3 characters should be written", 3, numchars);
50     assertEquals("wrong drill-down term text", expectedDDText, new String(
51         buf, 0, numchars));
52     
53     CategoryListParams clParams = ifip.getCategoryListParams(null);
54     assertEquals("partition for all ordinals is the first", "$fulltree$", 
55         PartitionsUtils.partitionNameByOrdinal(ifip, clParams , 250));
56     assertEquals("for partition 0, the same name should be returned",
57         "$fulltree$", PartitionsUtils.partitionName(clParams, 0));
58     assertEquals(
59         "for any other, it's the concatenation of name + partition",
60         "$fulltree$1", PartitionsUtils.partitionName(clParams, 1));
61     assertEquals("default partition number is always 0", 0, 
62         PartitionsUtils.partitionNumber(ifip,100));
63     
64     assertEquals("default partition size is unbounded", Integer.MAX_VALUE,
65         ifip.getPartitionSize());
66   }
67
68   @Test
69   public void testCategoryListParamsAddition() {
70     PerDimensionIndexingParams tlfip = new PerDimensionIndexingParams();
71     CategoryListParams clp = new CategoryListParams(
72         new Term("clp", "value"));
73     tlfip.addCategoryListParams(new CategoryPath("a"), clp);
74     assertEquals("Expected category list term is " + clp.getTerm(), clp
75         .getTerm(), tlfip.getCategoryListParams(new CategoryPath("a"))
76         .getTerm());
77     assertNotSame("Unexpected default category list " + clp.getTerm(), clp,
78         tlfip.getCategoryListParams(null));
79   }
80
81 }