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

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/spelling/suggest/SuggesterTest.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
 
/**
2
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 
 * contributor license agreements.  See the NOTICE file distributed with
4
 
 * this work for additional information regarding copyright ownership.
5
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 
 * (the "License"); you may not use this file except in compliance with
7
 
 * the License.  You may obtain a copy of the License at
8
 
 *
9
 
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 
 *
11
 
 * Unless required by applicable law or agreed to in writing, software
12
 
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 
 * See the License for the specific language governing permissions and
15
 
 * limitations under the License.
16
 
 */
17
 
 
18
 
package org.apache.solr.spelling.suggest;
19
 
 
20
 
import java.io.File;
21
 
 
22
 
import org.apache.solr.SolrTestCaseJ4;
23
 
import org.apache.solr.common.params.SpellingParams;
24
 
import org.apache.solr.common.util.NamedList;
25
 
import org.junit.BeforeClass;
26
 
import org.junit.Test;
27
 
 
28
 
public class SuggesterTest extends SolrTestCaseJ4 {
29
 
  /**
30
 
   * Expected URI at which the given suggester will live.
31
 
   */
32
 
  protected String requestUri = "/suggest";
33
 
 
34
 
  @BeforeClass
35
 
  public static void beforeClass() throws Exception {
36
 
    initCore("solrconfig-spellchecker.xml","schema-spellchecker.xml");
37
 
  }
38
 
 
39
 
  public static void addDocs() throws Exception {
40
 
    assertU(adoc("id", "1",
41
 
                 "text", "acceptable accidentally accommodate acquire"
42
 
               ));
43
 
    assertU(adoc("id", "2",
44
 
                 "text", "believe bellwether accommodate acquire"
45
 
               ));
46
 
    assertU(adoc("id", "3",
47
 
                "text", "cemetery changeable conscientious consensus acquire bellwether"
48
 
               ));
49
 
  }
50
 
  
51
 
  @Test
52
 
  public void testSuggestions() throws Exception {
53
 
    addDocs();
54
 
    assertU(commit()); // configured to do a rebuild on commit
55
 
 
56
 
    assertQ(req("qt", requestUri, "q", "ac", SpellingParams.SPELLCHECK_COUNT, "2", SpellingParams.SPELLCHECK_ONLY_MORE_POPULAR, "true"),
57
 
        "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/int[@name='numFound'][.='2']",
58
 
        "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/arr[@name='suggestion']/str[1][.='acquire']",
59
 
        "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/arr[@name='suggestion']/str[2][.='accommodate']"
60
 
    );
61
 
  }
62
 
  
63
 
  @Test
64
 
  public void testReload() throws Exception {
65
 
    String leaveData = System.getProperty("solr.test.leavedatadir");
66
 
    if (leaveData == null) leaveData = "";
67
 
    System.setProperty("solr.test.leavedatadir", "true");
68
 
    addDocs();
69
 
    assertU(commit());
70
 
    File data = dataDir;
71
 
    String config = configString;
72
 
    deleteCore();
73
 
    dataDir = data;
74
 
    configString = config;
75
 
    initCore();
76
 
    assertQ(req("qt", requestUri, "q", "ac", SpellingParams.SPELLCHECK_COUNT, "2", SpellingParams.SPELLCHECK_ONLY_MORE_POPULAR, "true"),
77
 
            "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/int[@name='numFound'][.='2']",
78
 
            "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/arr[@name='suggestion']/str[1][.='acquire']",
79
 
            "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/arr[@name='suggestion']/str[2][.='accommodate']"
80
 
        );
81
 
 
82
 
    // restore the property
83
 
    System.setProperty("solr.test.leavedatadir", leaveData);
84
 
  }
85
 
  
86
 
  @Test
87
 
  public void testRebuild() throws Exception {
88
 
    addDocs();
89
 
    assertU(commit());
90
 
    assertQ(req("qt", requestUri, "q", "ac", SpellingParams.SPELLCHECK_COUNT, "2", SpellingParams.SPELLCHECK_ONLY_MORE_POPULAR, "true"),
91
 
      "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/int[@name='numFound'][.='2']");
92
 
    assertU(adoc("id", "4",
93
 
        "text", "actually"
94
 
       ));
95
 
    assertU(commit());
96
 
    assertQ(req("qt", requestUri, "q", "ac", SpellingParams.SPELLCHECK_COUNT, "2", SpellingParams.SPELLCHECK_ONLY_MORE_POPULAR, "true"),
97
 
      "//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/int[@name='numFound'][.='2']");
98
 
  }
99
 
  
100
 
  // SOLR-2726
101
 
  public void testAnalyzer() throws Exception {
102
 
    Suggester suggester = new Suggester();
103
 
    NamedList params = new NamedList();
104
 
    params.add("lookupImpl", "org.apache.solr.spelling.suggest.tst.TSTLookupFactory");
105
 
    suggester.init(params, h.getCore());
106
 
    assertTrue(suggester.getQueryAnalyzer() != null);
107
 
  }
108
 
}