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
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.solr.spelling.suggest;
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;
28
public class SuggesterTest extends SolrTestCaseJ4 {
30
* Expected URI at which the given suggester will live.
32
protected String requestUri = "/suggest";
35
public static void beforeClass() throws Exception {
36
initCore("solrconfig-spellchecker.xml","schema-spellchecker.xml");
39
public static void addDocs() throws Exception {
40
assertU(adoc("id", "1",
41
"text", "acceptable accidentally accommodate acquire"
43
assertU(adoc("id", "2",
44
"text", "believe bellwether accommodate acquire"
46
assertU(adoc("id", "3",
47
"text", "cemetery changeable conscientious consensus acquire bellwether"
52
public void testSuggestions() throws Exception {
54
assertU(commit()); // configured to do a rebuild on commit
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']"
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");
71
String config = configString;
74
configString = config;
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']"
82
// restore the property
83
System.setProperty("solr.test.leavedatadir", leaveData);
87
public void testRebuild() throws Exception {
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",
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']");
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);