下面列出了org.apache.lucene.search.spell.SuggestMode#org.apache.solr.common.params.SpellingParams 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void testSpellCheckResponse() throws Exception {
getSolrClient();
client.deleteByQuery("*:*");
client.commit(true, true);
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "111");
doc.setField(field, "Samsung");
client.add(doc);
client.commit(true, true);
SolrQuery query = new SolrQuery("*:*");
query.set(CommonParams.QT, "/spell");
query.set("spellcheck", true);
query.set(SpellingParams.SPELLCHECK_Q, "samsang");
QueryRequest request = new QueryRequest(query);
SpellCheckResponse response = request.process(client).getSpellCheckResponse();
Assert.assertEquals("samsung", response.getFirstSuggestion("samsang"));
}
@Test
public void testCorrectSpelling() throws Exception {
// Make sure correct spellings are signaled in the response
assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true",
"q","lowerfilt:lazy lowerfilt:brown", SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true")
,"/spellcheck/correctlySpelled==true"
);
assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "spellcheck.dictionary", "direct_lowerfilt",
"q","lowerfilt:lazy lowerfilt:brown", SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true")
,"/spellcheck/correctlySpelled==true"
);
assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "spellcheck.dictionary", "direct_lowerfilt",
"q","lakkle", SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true")
,"/spellcheck/correctlySpelled==false"
);
}
public void test() {
assertQ(req("qt", URI, "q", "hokk", SpellingParams.SPELLCHECK_COUNT, "1"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='hokk']/int[@name='numFound'][.='1']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='hokk']/arr[@name='suggestion']/str[1][.='北海道']"
);
assertQ(req("qt", URI, "q", "ほっk", SpellingParams.SPELLCHECK_COUNT, "1"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ほっk']/int[@name='numFound'][.='1']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ほっk']/arr[@name='suggestion']/str[1][.='北海道']"
);
assertQ(req("qt", URI, "q", "ホッk", SpellingParams.SPELLCHECK_COUNT, "1"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ホッk']/int[@name='numFound'][.='1']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ホッk']/arr[@name='suggestion']/str[1][.='北海道']"
);
assertQ(req("qt", URI, "q", "ホッk", SpellingParams.SPELLCHECK_COUNT, "1"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ホッk']/int[@name='numFound'][.='1']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ホッk']/arr[@name='suggestion']/str[1][.='北海道']"
);
}
public void testWithMaxEdit2() throws Exception {
assertQ(req("qt", URI_MIN_EDIT_2, "q", "chagn", SpellingParams.SPELLCHECK_COUNT, "3"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chagn']/int[@name='numFound'][.='3']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chagn']/arr[@name='suggestion']/str[1][.='chance']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chagn']/arr[@name='suggestion']/str[2][.='change']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chagn']/arr[@name='suggestion']/str[3][.='charge']"
);
assertQ(req("qt", URI_MIN_EDIT_2, "q", "chagr", SpellingParams.SPELLCHECK_COUNT, "3"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chagr']/int[@name='numFound'][.='3']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chagr']/arr[@name='suggestion']/str[1][.='chance']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chagr']/arr[@name='suggestion']/str[2][.='change']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chagr']/arr[@name='suggestion']/str[3][.='charge']"
);
assertQ(req("qt", URI_MIN_EDIT_2, "q", "chacn", SpellingParams.SPELLCHECK_COUNT, "3"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chacn']/int[@name='numFound'][.='3']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chacn']/arr[@name='suggestion']/str[1][.='chance']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chacn']/arr[@name='suggestion']/str[2][.='change']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chacn']/arr[@name='suggestion']/str[3][.='charge']"
);
}
public void testSingle() throws Exception {
assertQ(req("qt", URI_DEFAULT, "q", "japan", SpellingParams.SPELLCHECK_COUNT, "1"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/int[@name='numFound'][.='1']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/arr[@name='suggestion']/str[1][.='<b>Japan</b>ese Autocomplete and <b>Japan</b>ese Highlighter broken']"
);
assertQ(req("qt", URI_DEFAULT, "q", "high", SpellingParams.SPELLCHECK_COUNT, "1"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='high']/int[@name='numFound'][.='1']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='high']/arr[@name='suggestion']/str[1][.='Japanese Autocomplete and Japanese <b>High</b>lighter broken']"
);
/* equivalent SolrSuggester, SuggestComponent tests */
assertQ(req("qt", URI_SUGGEST_DEFAULT, "q", "japan", SuggesterParams.SUGGEST_COUNT, "1", SuggesterParams.SUGGEST_DICT, "analyzing_infix_suggest_default"),
"//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japan']/int[@name='numFound'][.='1']",
"//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japan']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='<b>Japan</b>ese Autocomplete and <b>Japan</b>ese Highlighter broken']"
);
assertQ(req("qt", URI_SUGGEST_DEFAULT, "q", "high", SuggesterParams.SUGGEST_COUNT, "1", SuggesterParams.SUGGEST_DICT, "analyzing_infix_suggest_default"),
"//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='high']/int[@name='numFound'][.='1']",
"//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='high']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='Japanese Autocomplete and Japanese <b>High</b>lighter broken']"
);
}
@Test
public void testPhrase() throws IOException, Exception {
assertQ(req(CommonParams.QT, "standard",
CommonParams.Q, "foo:bobo AND foo:marley",
SpellingParams.SPELLCHECK_COLLATE, "true",
SpellingParams.SPELLCHECK_BUILD, "true",
SpellingParams.SPELLCHECK_COUNT, "10",
SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true",
DymReSearcher.COMPONENT_NAME, "true",
SpellCheckComponent.COMPONENT_NAME, "true")
,"//result[@name='spellchecked_response'][@numFound='7']"
,"//result[@name='response'][@numFound='0']"
,"//arr[@name='extended_spellchecker_suggestions']/str[1][.='foo:bob AND foo:marley']"
,"//arr[@name='extended_spellchecker_suggestions']/str[2][.='foo:bono AND foo:marley']"
);
}
@Test
public void testSingleWord() {
assertQ(req(CommonParams.QT, "standard",
CommonParams.Q, "foo:bon",
SpellingParams.SPELLCHECK_COLLATE, "true",
SpellingParams.SPELLCHECK_BUILD, "true",
SpellingParams.SPELLCHECK_COUNT, "10",
SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true",
DymReSearcher.COMPONENT_NAME, "true",
SpellCheckComponent.COMPONENT_NAME, "true")
,"//result[@name='spellchecked_response'][@numFound='8']"
,"//result[@name='response'][@numFound='0']"
,"//arr[@name='extended_spellchecker_suggestions']/str[1][.='foo:bob']"
,"//arr[@name='extended_spellchecker_suggestions']/str[2][.='foo:bono']"
,"//lst[@name='extended_spellchecker_suggestions_hit_counts']/long[@name='foo:bob'][.='8']"
,"//lst[@name='extended_spellchecker_suggestions_hit_counts']/long[@name='foo:bono'][.='4']"
,"//result[@name='spellchecked_response']/doc[1]/str[@name='id'][.='2']"
,"//result[@name='spellchecked_response']/doc[2]/str[@name='id'][.='3']"
,"//result[@name='spellchecked_response']/doc[3]/str[@name='id'][.='5']"
,"//result[@name='spellchecked_response']/doc[4]/str[@name='id'][.='7']"
,"//result[@name='spellchecked_response']/doc[5]/str[@name='id'][.='8']"
,"//result[@name='spellchecked_response']/doc[6]/str[@name='id'][.='9']"
,"//result[@name='spellchecked_response']/doc[7]/str[@name='id'][.='10']"
,"//result[@name='spellchecked_response']/doc[8]/str[@name='id'][.='11']");
}
@Test
public void testFacetAndHighlight() {
assertQ(req(CommonParams.QT, "standardGoodSuggestion",
CommonParams.Q, "foo:bobo AND foo:marley",
SpellingParams.SPELLCHECK_COLLATE, "true",
SpellingParams.SPELLCHECK_BUILD, "true",
SpellingParams.SPELLCHECK_COUNT, "10",
SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true",
FacetParams.FACET, "true",
FacetParams.FACET_FIELD, "foo",
FacetParams.FACET_FIELD, "id",
FacetParams.FACET_FIELD, "bar",
FacetParams.FACET_QUERY, "id:[0 TO 20]",
FacetParams.FACET_QUERY, "id:[1 TO 100]",
HighlightParams.HIGHLIGHT, "true",
HighlightParams.FIELDS, "foo",
DymReSearcher.COMPONENT_NAME, "true",
SpellCheckComponent.COMPONENT_NAME, "true")
,"//result[@name='spellchecked_response'][@numFound='7']"
,"//result[@name='response'][@numFound='0']"
,"//arr[@name='extended_spellchecker_suggestions']/str[1][.='foo:bob AND foo:marley']"
,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='bob'][.='7']"
,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='marley'][.='7']"
,"//lst[@name='spellchecked_highlighting']/lst[@name='2']/arr[@name='foo']/str[1]");
}
@Test
public void testFacetAndHighlightWithCommonMisspellings() {
assertQ(req(CommonParams.QT, "standardResWithCommonMisspellings",
CommonParams.Q, "foo:bobo AND foo:marley",
SpellingParams.SPELLCHECK_COLLATE, "true",
SpellingParams.SPELLCHECK_BUILD, "true",
SpellingParams.SPELLCHECK_COUNT, "10",
SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true",
FacetParams.FACET, "true",
FacetParams.FACET_FIELD, "foo",
FacetParams.FACET_FIELD, "id",
FacetParams.FACET_FIELD, "bar",
FacetParams.FACET_QUERY, "id:[0 TO 20]",
FacetParams.FACET_QUERY, "id:[1 TO 100]",
HighlightParams.HIGHLIGHT, "true",
HighlightParams.FIELDS, "foo",
DymReSearcher.COMPONENT_NAME, "true",
SpellCheckComponent.COMPONENT_NAME, "true")
,"//result[@name='spellchecked_response'][@numFound='3']"
,"//result[@name='response'][@numFound='0']"
,"//arr[@name='extended_spellchecker_suggestions']/str[1][.='foo:bono AND foo:marley']"
,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='bob'][.='3']"
,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='marley'][.='3']"
,"//lst[@name='spellchecked_highlighting']/lst[@name='9']/arr[@name='foo']/str[1]"
);
}
@Test
public void testPhraseWithCorrectionHighlighting() {
assertQ(req(CommonParams.QT, "standard",
CommonParams.Q, "foo:bobo AND foo:marley",
SpellingParams.SPELLCHECK_COLLATE, "true",
SpellingParams.SPELLCHECK_BUILD, "true",
SpellingParams.SPELLCHECK_COUNT, "10",
SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true",
AbstractReSearcherComponent.RES_HIGHLIGHT_REPLACED_TAG_PARAM_NAME, "b",
DymReSearcher.COMPONENT_NAME, "true",
SpellCheckComponent.COMPONENT_NAME, "true")
,"//result[@name='spellchecked_response'][@numFound='7']"
,"//result[@name='response'][@numFound='0']"
,"//arr[@name='extended_spellchecker_suggestions']/str[1][.='foo:bob AND foo:marley']"
,"//arr[@name='extended_spellchecker_suggestions']/str[2][.='foo:bono AND foo:marley']"
,"//arr[@name='extended_spellchecker_suggestions_highlighted']/str[1][.='<b>foo:bob</b> AND foo:marley']"
,"//arr[@name='extended_spellchecker_suggestions_highlighted']/str[2][.='<b>foo:bono</b> AND foo:marley']"
);
}
@Test
public void testBugWithMultipleIncorrectWords() {
// the bug occurs only when the second word is the one that should be changed
assertQ(req(CommonParams.QT, "standardIgnoreCollation",
CommonParams.Q, "foo:marlex AND foo:bobo",
SpellingParams.SPELLCHECK_COLLATE, "true",
SpellingParams.SPELLCHECK_BUILD, "true",
SpellingParams.SPELLCHECK_COUNT, "10",
SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true",
DymReSearcher.COMPONENT_NAME, "true",
SpellCheckComponent.COMPONENT_NAME, "true")
,"//result[@name='response'][@numFound='0']"
);
// it is enough to see that exception didn't occur; since both words are incorrect and ReS currently handles only one
// incorrect word, just one word will be fixed which still isn't enough to get any results (so suggestions wont be
// returned either).
}
@Test
@ShardsFixed(num = 2)
public void test() throws Exception {
handle.clear();
handle.put("QTime", SKIPVAL);
handle.put("timestamp", SKIPVAL);
handle.put("maxScore", SKIPVAL);
handle.put("responseHeader", SKIP);
handle.put("spellchecked_response", UNORDERED);
query(CommonParams.QT, "standardResWithCommonMisspellings",
ShardParams.SHARDS_QT, "standardResWithCommonMisspellings",
CommonParams.Q, "foo:bobo AND foo:marley",
SpellingParams.SPELLCHECK_COLLATE, "true",
SpellingParams.SPELLCHECK_BUILD, "true",
SpellingParams.SPELLCHECK_COUNT, "10",
SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true",
DymReSearcher.COMPONENT_NAME, "true",
SpellCheckComponent.COMPONENT_NAME, "true");
}
@Test
public void testSpellCheckResponse_Extended() throws Exception {
getSolrClient();
client.deleteByQuery("*:*");
client.commit(true, true);
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "111");
doc.setField(field, "Samsung");
client.add(doc);
client.commit(true, true);
SolrQuery query = new SolrQuery("*:*");
query.set(CommonParams.QT, "/spell");
query.set("spellcheck", true);
query.set(SpellingParams.SPELLCHECK_Q, "samsang");
query.set(SpellingParams.SPELLCHECK_EXTENDED_RESULTS, true);
QueryRequest request = new QueryRequest(query);
SpellCheckResponse response = request.process(client).getSpellCheckResponse();
assertEquals("samsung", response.getFirstSuggestion("samsang"));
SpellCheckResponse.Suggestion sug = response.getSuggestion("samsang");
List<SpellCheckResponse.Suggestion> sugs = response.getSuggestions();
assertEquals(sug.getAlternatives().size(), sug.getAlternativeFrequencies().size());
assertEquals(sugs.get(0).getAlternatives().size(), sugs.get(0).getAlternativeFrequencies().size());
assertEquals("samsung", sug.getAlternatives().get(0));
assertEquals("samsung", sugs.get(0).getAlternatives().get(0));
// basic test if fields were filled in
assertTrue(sug.getEndOffset()>0);
assertTrue(sug.getToken().length() > 0);
assertTrue(sug.getNumFound() > 0);
// assertTrue(sug.getOriginalFrequency() > 0);
// Hmmm... the API for SpellCheckResponse could be nicer:
response.getSuggestions().get(0).getAlternatives().get(0);
}
/**
* For every param that is of the form "spellcheck.[dictionary name].XXXX=YYYY, add
* XXXX=YYYY as a param to the custom param list
* @param params The original SolrParams
* @return The new Params
*/
protected SolrParams getCustomParams(String dictionary, SolrParams params) {
ModifiableSolrParams result = new ModifiableSolrParams();
Iterator<String> iter = params.getParameterNamesIterator();
String prefix = SpellingParams.SPELLCHECK_PREFIX + dictionary + ".";
while (iter.hasNext()) {
String nxt = iter.next();
if (nxt.startsWith(prefix)) {
result.add(nxt.substring(prefix.length()), params.getParams(nxt));
}
}
return result;
}
@Test
public void testExtendedResultsCount() throws Exception {
assertJQ(req("qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", SpellingParams.SPELLCHECK_BUILD, "true", "q","bluo", SpellingParams.SPELLCHECK_COUNT,"5", SpellingParams.SPELLCHECK_EXTENDED_RESULTS,"false")
,"/spellcheck/suggestions/[0]=='bluo'"
,"/spellcheck/suggestions/[1]/numFound==5"
);
assertJQ(req("qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","bluo", SpellingParams.SPELLCHECK_COUNT,"3", SpellingParams.SPELLCHECK_EXTENDED_RESULTS,"true")
,"/spellcheck/suggestions/[1]/suggestion==[{'word':'blud','freq':1}, {'word':'blue','freq':1}, {'word':'blee','freq':1}]"
);
}
@Test
public void testPerDictionary() throws Exception {
assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", SpellingParams.SPELLCHECK_BUILD, "true", "q","documemt"
, SpellingParams.SPELLCHECK_DICT, "perDict", SpellingParams.SPELLCHECK_PREFIX + "perDict.foo", "bar", SpellingParams.SPELLCHECK_PREFIX + "perDict.bar", "foo")
,"/spellcheck/suggestions/bar=={'numFound':1, 'startOffset':0, 'endOffset':1, 'suggestion':['foo']}"
,"/spellcheck/suggestions/foo=={'numFound':1, 'startOffset':2, 'endOffset':3, 'suggestion':['bar']}"
);
}
@Test
public void testCollate() throws Exception {
assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", SpellingParams.SPELLCHECK_BUILD, "true", "q","documemt", SpellingParams.SPELLCHECK_COLLATE, "true")
,"/spellcheck/collations/collation=='document'"
);
assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","documemt lowerfilt:broen^4", SpellingParams.SPELLCHECK_COLLATE, "true")
,"/spellcheck/collations/collation=='document lowerfilt:brown^4'"
);
assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","documemtsss broens", SpellingParams.SPELLCHECK_COLLATE, "true")
,"/spellcheck/collations/collation=='document brown'"
);
assertJQ(req("json.nl","map", "qt",rh, SpellCheckComponent.COMPONENT_NAME, "true", "q","pixma", SpellingParams.SPELLCHECK_COLLATE, "true")
,"/spellcheck/collations/collation=='pixmaa'"
);
}
private void implTestCollateExtendedResultsWithJsonNl(String q, String jsonNl, boolean collateExtendedResults, String ... tests) throws Exception {
final SolrQueryRequest solrQueryRequest = req(
CommonParams.QT, rh,
CommonParams.Q, q,
"json.nl", jsonNl,
SpellCheckComponent.COMPONENT_NAME, "true",
SpellingParams.SPELLCHECK_COLLATE_EXTENDED_RESULTS, Boolean.toString(collateExtendedResults),
SpellingParams.SPELLCHECK_COLLATE, "true");
assertJQ(solrQueryRequest, tests);
}
public void testMultiple() {
assertQ(req("qt", URI, "q", "h", SpellingParams.SPELLCHECK_COUNT, "2"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='h']/int[@name='numFound'][.='2']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='h']/arr[@name='suggestion']/str[1][.='話した']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='h']/arr[@name='suggestion']/str[2][.='北海道']"
);
}
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig-phrasesuggest.xml","schema-phrasesuggest.xml");
// Suggestions text include : change, charge, chance
assertQ(req("qt", URI_DEFAULT, "q", "", SpellingParams.SPELLCHECK_BUILD, "true"));
assertQ(req("qt", URI_MIN_EDIT_2, "q", "", SpellingParams.SPELLCHECK_BUILD, "true"));
assertQ(req("qt", URI_NON_PREFIX_LENGTH_4, "q", "", SpellingParams.SPELLCHECK_BUILD, "true"));
assertQ(req("qt", URI_MIN_FUZZY_LENGTH, "q", "", SpellingParams.SPELLCHECK_BUILD, "true"));
}
public void testDefault() throws Exception {
// tests to demonstrate default maxEdit parameter (value: 1), control for testWithMaxEdit2
assertQ(req("qt", URI_DEFAULT, "q", "chagn", SpellingParams.SPELLCHECK_COUNT, "3"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chagn']/int[@name='numFound'][.='2']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chagn']/arr[@name='suggestion']/str[1][.='chance']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chagn']/arr[@name='suggestion']/str[2][.='change']"
);
assertQ(req("qt", URI_DEFAULT, "q", "chacn", SpellingParams.SPELLCHECK_COUNT, "3"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chacn']/int[@name='numFound'][.='2']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chacn']/arr[@name='suggestion']/str[1][.='chance']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chacn']/arr[@name='suggestion']/str[2][.='change']"
);
assertQ(req("qt", URI_DEFAULT, "q", "chagr", SpellingParams.SPELLCHECK_COUNT, "3"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chagr']/int[@name='numFound'][.='1']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chagr']/arr[@name='suggestion']/str[1][.='charge']"
);
// test to demonstrate default nonFuzzyPrefix parameter (value: 1), control for testWithNonFuzzyPrefix4
assertQ(req("qt", URI_DEFAULT, "q", "chanr", SpellingParams.SPELLCHECK_COUNT, "3"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chanr']/int[@name='numFound'][.='3']"
);
// test to demonstrate default minFuzzyPrefix parameter (value: 3), control for testWithMinFuzzyLength2
assertQ(req("qt", URI_DEFAULT, "q", "cyhnce", SpellingParams.SPELLCHECK_COUNT, "3"),
"//lst[@name='spellcheck']/lst[@name='suggestions'][not(node())]"
);
}
public void testWithNonFuzzyPrefix4() throws Exception {
// This test should not match charge, as the nonFuzzyPrefix has been set to 4
assertQ(req("qt", URI_NON_PREFIX_LENGTH_4, "q", "chanr", SpellingParams.SPELLCHECK_COUNT, "3"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chanr']/int[@name='numFound'][.='2']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chanr']/arr[@name='suggestion']/str[1][.='chance']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chanr']/arr[@name='suggestion']/str[2][.='change']"
);
}
public void testWithMinFuzzyLength2() throws Exception {
// This test should match chance as the minFuzzyLength parameter has been set to 2
assertQ(req("qt", URI_MIN_FUZZY_LENGTH, "q", "chynce", SpellingParams.SPELLCHECK_COUNT, "3"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chynce']/int[@name='numFound'][.='1']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='chynce']/arr[@name='suggestion']/str[1][.='chance']"
);
}
@Test
public void testSuggestions() throws Exception {
addDocs();
assertU(commit()); // configured to do a rebuild on commit
assertQ(req("qt", requestUri, "q", "ac", SpellingParams.SPELLCHECK_COUNT, "2", SpellingParams.SPELLCHECK_ONLY_MORE_POPULAR, "true"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/int[@name='numFound'][.='2']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/arr[@name='suggestion']/str[1][.='acquire']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/arr[@name='suggestion']/str[2][.='accommodate']"
);
}
@Test
public void testReload() throws Exception {
addDocs();
assertU(commit());
h.reload();
// wait until the new searcher is registered
waitForWarming();
assertQ(req("qt", requestUri, "q", "ac", SpellingParams.SPELLCHECK_COUNT, "2", SpellingParams.SPELLCHECK_ONLY_MORE_POPULAR, "true"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/int[@name='numFound'][.='2']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/arr[@name='suggestion']/str[1][.='acquire']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/arr[@name='suggestion']/str[2][.='accommodate']"
);
}
@Test
public void testRebuild() throws Exception {
addDocs();
assertU(commit());
assertQ(req("qt", requestUri, "q", "ac", SpellingParams.SPELLCHECK_COUNT, "2", SpellingParams.SPELLCHECK_ONLY_MORE_POPULAR, "true"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/int[@name='numFound'][.='2']");
assertU(adoc("id", "4",
"text", "actually"
));
assertU(commit());
assertQ(req("qt", requestUri, "q", "ac", SpellingParams.SPELLCHECK_COUNT, "2", SpellingParams.SPELLCHECK_ONLY_MORE_POPULAR, "true"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='ac']/int[@name='numFound'][.='2']");
}
public void testMultiple() throws Exception {
assertQ(req("qt", URI_DEFAULT, "q", "japan", SpellingParams.SPELLCHECK_COUNT, "2"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/int[@name='numFound'][.='2']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/arr[@name='suggestion']/str[1][.='<b>Japan</b>ese Autocomplete and <b>Japan</b>ese Highlighter broken']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/arr[@name='suggestion']/str[2][.='Add <b>Japan</b>ese Kanji number normalization to Kuromoji']"
);
assertQ(req("qt", URI_DEFAULT, "q", "japan", SpellingParams.SPELLCHECK_COUNT, "3"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/int[@name='numFound'][.='3']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/arr[@name='suggestion']/str[1][.='<b>Japan</b>ese Autocomplete and <b>Japan</b>ese Highlighter broken']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/arr[@name='suggestion']/str[2][.='Add <b>Japan</b>ese Kanji number normalization to Kuromoji']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/arr[@name='suggestion']/str[3][.='Add decompose compound <b>Japan</b>ese Katakana token capability to Kuromoji']"
);
assertQ(req("qt", URI_DEFAULT, "q", "japan", SpellingParams.SPELLCHECK_COUNT, "4"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/int[@name='numFound'][.='3']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/arr[@name='suggestion']/str[1][.='<b>Japan</b>ese Autocomplete and <b>Japan</b>ese Highlighter broken']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/arr[@name='suggestion']/str[2][.='Add <b>Japan</b>ese Kanji number normalization to Kuromoji']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/arr[@name='suggestion']/str[3][.='Add decompose compound <b>Japan</b>ese Katakana token capability to Kuromoji']"
);
/* SolrSuggester, SuggestComponent tests: allTermsRequire (true), highlight (true) */
assertQ(req("qt", URI_SUGGEST_DEFAULT, "q", "japan", SuggesterParams.SUGGEST_COUNT, "2", SuggesterParams.SUGGEST_DICT, "analyzing_infix_suggest_default"),
"//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japan']/int[@name='numFound'][.='2']",
"//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japan']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='<b>Japan</b>ese Autocomplete and <b>Japan</b>ese Highlighter broken']",
"//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japan']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='Add <b>Japan</b>ese Kanji number normalization to Kuromoji']"
);
assertQ(req("qt", URI_SUGGEST_DEFAULT, "q", "japanese ka", SuggesterParams.SUGGEST_COUNT, "2", SuggesterParams.SUGGEST_DICT, "analyzing_infix_suggest_default"),
"//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japanese ka']/int[@name='numFound'][.='2']",
"//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japanese ka']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='Add <b>Japanese</b> <b>Ka</b>nji number normalization to Kuromoji']",
"//lst[@name='suggest']/lst[@name='analyzing_infix_suggest_default']/lst[@name='japanese ka']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='Add decompose compound <b>Japanese</b> <b>Ka</b>takana token capability to Kuromoji']"
);
}
public void test() {
assertQ(req("qt", URI, "q", "the f", SpellingParams.SPELLCHECK_COUNT, "4"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='the f']/int[@name='numFound'][.='3']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='the f']/arr[@name='suggestion']/str[1][.='the final phrase']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='the f']/arr[@name='suggestion']/str[2][.='the fifth phrase']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='the f']/arr[@name='suggestion']/str[3][.='the first phrase']"
);
assertQ(req("qt", URI, "q", "Testing +12", SpellingParams.SPELLCHECK_COUNT, "4"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='testing 12']/int[@name='numFound'][.='1']",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='testing 12']/arr[@name='suggestion']/str[1][.='testing 1234']"
);
}
@Test
public void testOnlyMorePopularWithExtendedResults() throws Exception {
assertQ(req("q", "teststop:fox", "qt", "/spellCheckCompRH", SpellCheckComponent.COMPONENT_NAME, "true", SpellingParams.SPELLCHECK_DICT, "direct", SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true", SpellingParams.SPELLCHECK_ONLY_MORE_POPULAR, "true"),
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='fox']/int[@name='origFreq']=1",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='fox']/arr[@name='suggestion']/lst/str[@name='word']='foo'",
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='fox']/arr[@name='suggestion']/lst/int[@name='freq']=2",
"//lst[@name='spellcheck']/bool[@name='correctlySpelled']='true'"
);
}
@Test
public void test() throws Exception {
for(int i=0 ; i<200 ; i++) {
String[] doc = {"id","" + i, "group_i", "" + (i % 10), "a_s", ((i%2)==0 ? "love" : "peace")};
assertU(adoc(doc));
if(i%5==0) {
assertU(commit());
}
}
assertU(commit());
for (SolrParams params : new SolrParams[]{
params(CommonParams.FQ, "{!collapse field=group_i}"),
params(CommonParams.FQ, "${bleh}", "bleh", "{!collapse field=group_i}"), // substitution
params(CommonParams.FQ, "{!tag=collapser}{!collapse field=group_i}"), // with tag & collapse in localparams
params(CommonParams.FQ, "{!collapse tag=collapser field=group_i}")
}) {
assertQ(
req(params,
SpellCheckComponent.COMPONENT_NAME, "true",
SpellCheckComponent.SPELLCHECK_DICT, "direct",
SpellingParams.SPELLCHECK_COUNT, "10",
SpellingParams.SPELLCHECK_COLLATE, "true",
SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "5",
SpellingParams.SPELLCHECK_MAX_COLLATIONS, "1",
CommonParams.Q, "a_s:lpve",
CommonParams.QT, "/spellCheckCompRH_Direct",
SpellingParams.SPELLCHECK_COLLATE_MAX_COLLECT_DOCS, "5",
"expand", "true"),
"//lst[@name='spellcheck']/lst[@name='collations']/str[@name='collation']='a_s:love'"
);
}
}