~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to lucene/contrib/facet/src/test/org/apache/lucene/facet/index/params/DefaultFacetIndexingParamsTest.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.categorypolicy.DefaultOrdinalPolicy;
8
 
import org.apache.lucene.facet.index.categorypolicy.DefaultPathPolicy;
9
 
import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy;
10
 
import org.apache.lucene.facet.index.categorypolicy.PathPolicy;
11
 
import org.apache.lucene.facet.index.params.CategoryListParams;
12
 
import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams;
13
 
import org.apache.lucene.facet.index.params.FacetIndexingParams;
14
 
import org.apache.lucene.facet.search.DrillDown;
15
 
import org.apache.lucene.facet.taxonomy.CategoryPath;
16
 
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
17
 
import org.apache.lucene.facet.util.PartitionsUtils;
18
 
 
19
 
/**
20
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
21
 
 * contributor license agreements.  See the NOTICE file distributed with
22
 
 * this work for additional information regarding copyright ownership.
23
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
24
 
 * (the "License"); you may not use this file except in compliance with
25
 
 * the License.  You may obtain a copy of the License at
26
 
 *
27
 
 *     http://www.apache.org/licenses/LICENSE-2.0
28
 
 *
29
 
 * Unless required by applicable law or agreed to in writing, software
30
 
 * distributed under the License is distributed on an "AS IS" BASIS,
31
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
 
 * See the License for the specific language governing permissions and
33
 
 * limitations under the License.
34
 
 */
35
 
 
36
 
public class DefaultFacetIndexingParamsTest extends LuceneTestCase {
37
 
 
38
 
  @Test
39
 
  public void testDefaultSettings() {
40
 
    FacetIndexingParams dfip = new DefaultFacetIndexingParams();
41
 
    assertNotNull("Missing default category list", dfip
42
 
        .getAllCategoryListParams());
43
 
    assertEquals(
44
 
        "all categories have the same CategoryListParams by default",
45
 
        dfip.getCategoryListParams(null), dfip
46
 
            .getCategoryListParams(new CategoryPath("a")));
47
 
    assertEquals(
48
 
        "Expected default category list term is $facets:$fulltree$",
49
 
        new Term("$facets", "$fulltree$"), dfip.getCategoryListParams(
50
 
            null).getTerm());
51
 
    String expectedDDText = "a"
52
 
        + dfip.getFacetDelimChar() + "b";
53
 
    CategoryPath cp = new CategoryPath("a", "b");
54
 
    assertEquals("wrong drill-down term", new Term("$facets",
55
 
        expectedDDText), DrillDown.term(dfip,cp));
56
 
    char[] buf = new char[20];
57
 
    int numchars = dfip.drillDownTermText(cp, buf);
58
 
    assertEquals("3 characters should be written", 3, numchars);
59
 
    assertEquals("wrong drill-down term text", expectedDDText, new String(
60
 
        buf, 0, numchars));
61
 
    CategoryListParams clParams = dfip.getCategoryListParams(null);
62
 
    assertEquals("partition for all ordinals is the first", "$fulltree$", 
63
 
        PartitionsUtils.partitionNameByOrdinal(dfip, clParams , 250));
64
 
    assertEquals("for partition 0, the same name should be returned",
65
 
        "$fulltree$", PartitionsUtils.partitionName(clParams, 0));
66
 
    assertEquals(
67
 
        "for any other, it's the concatenation of name + partition",
68
 
        "$fulltree$1", PartitionsUtils.partitionName(clParams, 1));
69
 
    assertEquals("default partition number is always 0", 0, 
70
 
        PartitionsUtils.partitionNumber(dfip,100));
71
 
    assertEquals("default partition size is unbounded", Integer.MAX_VALUE,
72
 
        dfip.getPartitionSize());
73
 
  }
74
 
 
75
 
  @Test
76
 
  public void testCategoryListParamsWithDefaultIndexingParams() {
77
 
    CategoryListParams clp = new CategoryListParams(
78
 
        new Term("clp", "value"));
79
 
    FacetIndexingParams dfip = new DefaultFacetIndexingParams(clp);
80
 
    assertEquals("Expected default category list term is " + clp.getTerm(),
81
 
        clp.getTerm(), dfip.getCategoryListParams(null).getTerm());
82
 
  }
83
 
 
84
 
  @Test
85
 
  public void testCategoryPolicies() {
86
 
    FacetIndexingParams dfip = new DefaultFacetIndexingParams();
87
 
    long seed = System.currentTimeMillis();
88
 
    // check path policy
89
 
    CategoryPath cp = new CategoryPath();
90
 
    PathPolicy pathPolicy = new DefaultPathPolicy();
91
 
    assertEquals("path policy does not match default for root" + "(seed "
92
 
        + seed + ")", pathPolicy.shouldAdd(cp), dfip.getPathPolicy()
93
 
        .shouldAdd(cp));
94
 
    for (int i = 0; i < 30; i++) {
95
 
      int nComponents = random.nextInt(10);
96
 
      String[] components = new String[nComponents];
97
 
      for (int j = 0; j < components.length; j++) {
98
 
        components[j] = (Integer.valueOf(random.nextInt(30))).toString();
99
 
      }
100
 
      cp = new CategoryPath(components);
101
 
      assertEquals("path policy does not match default for "
102
 
          + cp.toString('/') + "(seed " + seed + ")", pathPolicy
103
 
          .shouldAdd(cp), dfip.getPathPolicy().shouldAdd(cp));
104
 
    }
105
 
 
106
 
    // check ordinal policy
107
 
    OrdinalPolicy ordinalPolicy = new DefaultOrdinalPolicy();
108
 
    assertEquals("ordinal policy does not match default for root"
109
 
        + "(seed " + seed + ")", ordinalPolicy
110
 
        .shouldAdd(TaxonomyReader.ROOT_ORDINAL), dfip
111
 
        .getOrdinalPolicy().shouldAdd(TaxonomyReader.ROOT_ORDINAL));
112
 
    for (int i = 0; i < 30; i++) {
113
 
      int ordinal = random.nextInt();
114
 
      assertEquals("ordinal policy does not match default for " + ordinal
115
 
          + "(seed " + seed + ")", ordinalPolicy.shouldAdd(ordinal),
116
 
          dfip.getOrdinalPolicy().shouldAdd(ordinal));
117
 
    }
118
 
  }
119
 
 
120
 
}
 
 
b'\\ No newline at end of file'