mirror of https://github.com/apache/lucene.git
SOLR-5529: add support for queries to use multiple suggesters in SuggestComponent
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1557206 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f59271723b
commit
13084e4e81
|
@ -142,6 +142,9 @@ New Features
|
|||
* SOLR-5463: new 'cursorMark' request param for deep paging of sorted result sets
|
||||
(sarowe, hossman)
|
||||
|
||||
* SOLR-5529: Add support for queries to use multiple suggesters.
|
||||
(Areek Zillur, Erick Erickson, via Robert Muir)
|
||||
|
||||
Bug Fixes
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -19,8 +19,11 @@ package org.apache.solr.handler.component;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -145,20 +148,26 @@ public class SuggestComponent extends SearchComponent implements SolrCoreAware,
|
|||
return;
|
||||
}
|
||||
|
||||
SolrSuggester suggester = getSuggester(params);
|
||||
if (suggester == null) {
|
||||
if (params.get(SUGGEST_DICT) != null) {
|
||||
throw new IllegalArgumentException("No suggester named " + params.get(SUGGEST_DICT) +" was configured");
|
||||
boolean buildAll = params.getBool(SUGGEST_BUILD_ALL, false);
|
||||
boolean reloadAll = params.getBool(SUGGEST_RELOAD_ALL, false);
|
||||
|
||||
final Collection<SolrSuggester> querysuggesters;
|
||||
if (buildAll || reloadAll) {
|
||||
querysuggesters = suggesters.values();
|
||||
} else {
|
||||
throw new IllegalArgumentException("No default suggester was configured");
|
||||
querysuggesters = getSuggesters(params);
|
||||
}
|
||||
}
|
||||
if (params.getBool(SUGGEST_BUILD, false)) {
|
||||
|
||||
if (params.getBool(SUGGEST_BUILD, false) || buildAll) {
|
||||
for (SolrSuggester suggester : querysuggesters) {
|
||||
suggester.build(rb.req.getCore(), rb.req.getSearcher());
|
||||
rb.rsp.add("command", "build");
|
||||
} else if (params.getBool(SUGGEST_RELOAD, false)) {
|
||||
}
|
||||
rb.rsp.add("command", (!buildAll) ? "build" : "buildAll");
|
||||
} else if (params.getBool(SUGGEST_RELOAD, false) || reloadAll) {
|
||||
for (SolrSuggester suggester : querysuggesters) {
|
||||
suggester.reload(rb.req.getCore(), rb.req.getSearcher());
|
||||
rb.rsp.add("command", "reload");
|
||||
}
|
||||
rb.rsp.add("command", (!reloadAll) ? "reload" : "reloadAll");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +202,19 @@ public class SuggestComponent extends SearchComponent implements SolrCoreAware,
|
|||
return;
|
||||
}
|
||||
|
||||
SolrSuggester suggester = getSuggester(params);
|
||||
boolean buildAll = params.getBool(SUGGEST_BUILD_ALL, false);
|
||||
boolean reloadAll = params.getBool(SUGGEST_RELOAD_ALL, false);
|
||||
Set<SolrSuggester> querySuggesters;
|
||||
try {
|
||||
querySuggesters = getSuggesters(params);
|
||||
} catch(IllegalArgumentException ex) {
|
||||
if (!buildAll && !reloadAll) {
|
||||
throw ex;
|
||||
} else {
|
||||
querySuggesters = new HashSet<SolrSuggester>();
|
||||
}
|
||||
}
|
||||
|
||||
String query = params.get(SUGGEST_Q);
|
||||
if (query == null) {
|
||||
query = rb.getQueryString();
|
||||
|
@ -205,10 +226,13 @@ public class SuggestComponent extends SearchComponent implements SolrCoreAware,
|
|||
if (query != null) {
|
||||
int count = params.getInt(SUGGEST_COUNT, 1);
|
||||
SuggesterOptions options = new SuggesterOptions(new CharsRef(query), count);
|
||||
Map<String, SimpleOrderedMap<NamedList<Object>>> namedListResults =
|
||||
new HashMap<String, SimpleOrderedMap<NamedList<Object>>>();
|
||||
for (SolrSuggester suggester : querySuggesters) {
|
||||
SuggesterResult suggesterResult = suggester.getSuggestions(options);
|
||||
|
||||
NamedList<NamedList<Object>> namedListResult = toNamedList(suggesterResult);
|
||||
rb.rsp.add(SuggesterResultLabels.SUGGEST, namedListResult);
|
||||
toNamedList(suggesterResult, namedListResults);
|
||||
}
|
||||
rb.rsp.add(SuggesterResultLabels.SUGGEST, namedListResults);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,7 +248,6 @@ public class SuggestComponent extends SearchComponent implements SolrCoreAware,
|
|||
int count = params.getInt(SUGGEST_COUNT, 1);
|
||||
|
||||
List<SuggesterResult> suggesterResults = new ArrayList<SuggesterResult>();
|
||||
NamedList<NamedList<Object>> namedListResult = null;
|
||||
|
||||
// Collect Shard responses
|
||||
for (ShardRequest sreq : rb.finished) {
|
||||
|
@ -232,8 +255,8 @@ public class SuggestComponent extends SearchComponent implements SolrCoreAware,
|
|||
NamedList<Object> resp;
|
||||
if((resp = srsp.getSolrResponse().getResponse()) != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
NamedList<NamedList<Object>> namedList =
|
||||
(NamedList<NamedList<Object>>) resp.get(SuggesterResultLabels.SUGGEST);
|
||||
Map<String, SimpleOrderedMap<NamedList<Object>>> namedList =
|
||||
(Map<String, SimpleOrderedMap<NamedList<Object>>>) resp.get(SuggesterResultLabels.SUGGEST);
|
||||
LOG.info(srsp.getShard() + " : " + namedList);
|
||||
suggesterResults.add(toSuggesterResult(namedList));
|
||||
}
|
||||
|
@ -242,9 +265,11 @@ public class SuggestComponent extends SearchComponent implements SolrCoreAware,
|
|||
|
||||
// Merge Shard responses
|
||||
SuggesterResult suggesterResult = merge(suggesterResults, count);
|
||||
namedListResult = toNamedList(suggesterResult);
|
||||
Map<String, SimpleOrderedMap<NamedList<Object>>> namedListResults =
|
||||
new HashMap<String, SimpleOrderedMap<NamedList<Object>>>();
|
||||
toNamedList(suggesterResult, namedListResults);
|
||||
|
||||
rb.rsp.add(SuggesterResultLabels.SUGGEST, namedListResult);
|
||||
rb.rsp.add(SuggesterResultLabels.SUGGEST, namedListResults);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -254,23 +279,25 @@ public class SuggestComponent extends SearchComponent implements SolrCoreAware,
|
|||
* weights
|
||||
* */
|
||||
private static SuggesterResult merge(List<SuggesterResult> suggesterResults, int count) {
|
||||
if (suggesterResults.size() == 1) {
|
||||
return suggesterResults.get(0);
|
||||
}
|
||||
SuggesterResult result = new SuggesterResult();
|
||||
Set<String> allTokens = new HashSet<String>();
|
||||
Set<String> suggesterNames = new HashSet<String>();
|
||||
|
||||
// collect all tokens
|
||||
for (SuggesterResult shardResult : suggesterResults) {
|
||||
allTokens.addAll(shardResult.getTokens());
|
||||
for (String suggesterName : shardResult.getSuggesterNames()) {
|
||||
allTokens.addAll(shardResult.getTokens(suggesterName));
|
||||
suggesterNames.add(suggesterName);
|
||||
}
|
||||
}
|
||||
|
||||
// Get Top N for every token in every shard (using weights)
|
||||
for (String suggesterName : suggesterNames) {
|
||||
for (String token : allTokens) {
|
||||
Lookup.LookupPriorityQueue resultQueue = new Lookup.LookupPriorityQueue(
|
||||
count);
|
||||
for (SuggesterResult shardResult : suggesterResults) {
|
||||
List<LookupResult> suggests = shardResult.getLookupResult(token);
|
||||
List<LookupResult> suggests = shardResult.getLookupResult(suggesterName, token);
|
||||
if (suggests == null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -280,7 +307,8 @@ public class SuggestComponent extends SearchComponent implements SolrCoreAware,
|
|||
}
|
||||
List<LookupResult> sortedSuggests = new LinkedList<LookupResult>();
|
||||
Collections.addAll(sortedSuggests, resultQueue.getResults());
|
||||
result.add(token, sortedSuggests);
|
||||
result.add(suggesterName, token, sortedSuggests);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -315,24 +343,43 @@ public class SuggestComponent extends SearchComponent implements SolrCoreAware,
|
|||
return sizeInBytes;
|
||||
}
|
||||
|
||||
private SolrSuggester getSuggester(SolrParams params) {
|
||||
return suggesters.get(getSuggesterName(params));
|
||||
private Set<SolrSuggester> getSuggesters(SolrParams params) {
|
||||
Set<SolrSuggester> solrSuggesters = new HashSet<SolrSuggester>();
|
||||
for(String suggesterName : getSuggesterNames(params)) {
|
||||
SolrSuggester curSuggester = suggesters.get(suggesterName);
|
||||
if (curSuggester != null) {
|
||||
solrSuggesters.add(curSuggester);
|
||||
} else {
|
||||
throw new IllegalArgumentException("No suggester named " + suggesterName +" was configured");
|
||||
}
|
||||
}
|
||||
if (solrSuggesters.size() == 0) {
|
||||
throw new IllegalArgumentException("No default suggester was configured");
|
||||
}
|
||||
return solrSuggesters;
|
||||
|
||||
}
|
||||
|
||||
private String getSuggesterName(SolrParams params){
|
||||
return (params.get(SUGGEST_DICT) != null) ?
|
||||
(String)params.get(SUGGEST_DICT)
|
||||
: DEFAULT_DICT_NAME;
|
||||
|
||||
private Set<String> getSuggesterNames(SolrParams params) {
|
||||
Set<String> suggesterNames = new HashSet<String>();
|
||||
String[] suggesterNamesFromParams = params.getParams(SUGGEST_DICT);
|
||||
if (suggesterNamesFromParams == null) {
|
||||
suggesterNames.add(DEFAULT_DICT_NAME);
|
||||
} else {
|
||||
for (String name : suggesterNamesFromParams) {
|
||||
suggesterNames.add(name);
|
||||
}
|
||||
}
|
||||
return suggesterNames;
|
||||
}
|
||||
|
||||
/** Convert {@link SuggesterResult} to NamedList for constructing responses */
|
||||
private NamedList<NamedList<Object>> toNamedList(SuggesterResult suggesterResult) {
|
||||
NamedList<NamedList<Object>> results = new SimpleOrderedMap<NamedList<Object>>();
|
||||
for (String token : suggesterResult.getTokens()) {
|
||||
private void toNamedList(SuggesterResult suggesterResult, Map<String, SimpleOrderedMap<NamedList<Object>>> resultObj) {
|
||||
for(String suggesterName : suggesterResult.getSuggesterNames()) {
|
||||
SimpleOrderedMap<NamedList<Object>> results = new SimpleOrderedMap<NamedList<Object>>();
|
||||
for (String token : suggesterResult.getTokens(suggesterName)) {
|
||||
SimpleOrderedMap<Object> suggestionBody = new SimpleOrderedMap<Object>();
|
||||
List<LookupResult> lookupResults = suggesterResult.getLookupResult(token);
|
||||
List<LookupResult> lookupResults = suggesterResult.getLookupResult(suggesterName, token);
|
||||
suggestionBody.add(SuggesterResultLabels.SUGGESTION_NUM_FOUND, lookupResults.size());
|
||||
List<SimpleOrderedMap<Object>> suggestEntriesNamedList = new ArrayList<SimpleOrderedMap<Object>>();
|
||||
for (LookupResult lookupResult : lookupResults) {
|
||||
|
@ -352,20 +399,24 @@ public class SuggestComponent extends SearchComponent implements SolrCoreAware,
|
|||
suggestionBody.add(SuggesterResultLabels.SUGGESTIONS, suggestEntriesNamedList);
|
||||
results.add(token, suggestionBody);
|
||||
}
|
||||
return results;
|
||||
resultObj.put(suggesterName, results);
|
||||
}
|
||||
}
|
||||
|
||||
/** Convert NamedList (suggester response) to {@link SuggesterResult} */
|
||||
private SuggesterResult toSuggesterResult(NamedList<NamedList<Object>> suggestions) {
|
||||
private SuggesterResult toSuggesterResult(Map<String, SimpleOrderedMap<NamedList<Object>>> suggestionsMap) {
|
||||
SuggesterResult result = new SuggesterResult();
|
||||
if (suggestions == null) {
|
||||
if (suggestionsMap == null) {
|
||||
return result;
|
||||
}
|
||||
// for each token
|
||||
for(int i = 0; i < suggestions.size() ; i++) {
|
||||
String tokenString = suggestions.getName(i);
|
||||
for(Map.Entry<String, SimpleOrderedMap<NamedList<Object>>> entry : suggestionsMap.entrySet()) {
|
||||
String suggesterName = entry.getKey();
|
||||
for (Iterator<Map.Entry<String, NamedList<Object>>> suggestionsIter = entry.getValue().iterator(); suggestionsIter.hasNext();) {
|
||||
Map.Entry<String, NamedList<Object>> suggestions = suggestionsIter.next();
|
||||
String tokenString = suggestions.getKey();
|
||||
List<LookupResult> lookupResults = new ArrayList<LookupResult>();
|
||||
NamedList<Object> suggestion = (NamedList<Object>) suggestions.getVal(i);
|
||||
NamedList<Object> suggestion = suggestions.getValue();
|
||||
// for each suggestion
|
||||
for (int j = 0; j < suggestion.size(); j++) {
|
||||
String property = suggestion.getName(j);
|
||||
|
@ -380,7 +431,8 @@ public class SuggestComponent extends SearchComponent implements SolrCoreAware,
|
|||
lookupResults.add(res);
|
||||
}
|
||||
}
|
||||
result.add(tokenString, lookupResults);
|
||||
result.add(suggesterName, tokenString, lookupResults);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -179,7 +179,7 @@ public class SolrSuggester {
|
|||
|
||||
SuggesterResult res = new SuggesterResult();
|
||||
List<LookupResult> suggestions = lookup.lookup(options.token, false, options.count);
|
||||
res.add(options.token.toString(), suggestions);
|
||||
res.add(getName(), options.token.toString(), suggestions);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,9 +48,22 @@ public interface SuggesterParams {
|
|||
*/
|
||||
public static final String SUGGEST_BUILD = SUGGEST_PREFIX + "build";
|
||||
|
||||
/**
|
||||
* Whether to build the index or not for all suggesters in the component.
|
||||
* Optional and false by default.
|
||||
* This parameter does not need any suggest dictionary names to be specified
|
||||
*/
|
||||
public static final String SUGGEST_BUILD_ALL = SUGGEST_PREFIX + "buildAll";
|
||||
|
||||
/**
|
||||
* Whether to reload the index. Optional and false by default.
|
||||
*/
|
||||
public static final String SUGGEST_RELOAD = SUGGEST_PREFIX + "reload";
|
||||
|
||||
/**
|
||||
* Whether to reload the index or not for all suggesters in the component.
|
||||
* Optional and false by default.
|
||||
* This parameter does not need any suggest dictionary names to be specified
|
||||
*/
|
||||
public static final String SUGGEST_RELOAD_ALL = SUGGEST_PREFIX + "reloadAll";
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@ package org.apache.solr.spelling.suggest;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -32,14 +34,19 @@ public class SuggesterResult {
|
|||
public SuggesterResult() {}
|
||||
|
||||
/** token -> lookup results mapping*/
|
||||
private Map<String, List<LookupResult>> suggestions = new HashMap<String, List<LookupResult>>();
|
||||
private Map<String, Map<String, List<LookupResult>>> suggestionsMap =
|
||||
new HashMap<String, Map<String, List<LookupResult>>>();
|
||||
|
||||
/** Add suggestion results for <code>token</code> */
|
||||
public void add(String token, List<LookupResult> results) {
|
||||
List<LookupResult> res = this.suggestions.get(token);
|
||||
public void add(String suggesterName, String token, List<LookupResult> results) {
|
||||
Map<String, List<LookupResult>> suggesterRes = this.suggestionsMap.get(suggesterName);
|
||||
if (suggesterRes == null) {
|
||||
this.suggestionsMap.put(suggesterName, new HashMap<String, List<LookupResult>>());
|
||||
}
|
||||
List<LookupResult> res = this.suggestionsMap.get(suggesterName).get(token);
|
||||
if (res == null) {
|
||||
res = results;
|
||||
this.suggestions.put(token, res);
|
||||
this.suggestionsMap.get(suggesterName).put(token, res);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,15 +55,27 @@ public class SuggesterResult {
|
|||
* null can be returned, if there are no lookup results
|
||||
* for the <code>token</code>
|
||||
* */
|
||||
public List<LookupResult> getLookupResult(String token) {
|
||||
return this.suggestions.get(token);
|
||||
public List<LookupResult> getLookupResult(String suggesterName, String token) {
|
||||
return (this.suggestionsMap.containsKey(suggesterName))
|
||||
? this.suggestionsMap.get(suggesterName).get(token)
|
||||
: new ArrayList<LookupResult>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set of tokens that are present in the
|
||||
* instance
|
||||
*/
|
||||
public Set<String> getTokens() {
|
||||
return this.suggestions.keySet();
|
||||
public Set<String> getTokens(String suggesterName) {
|
||||
return (this.suggestionsMap.containsKey(suggesterName))
|
||||
? this.suggestionsMap.get(suggesterName).keySet()
|
||||
: new HashSet<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set of suggesterNames for which this
|
||||
* instance holds results
|
||||
*/
|
||||
public Set<String> getSuggesterNames() {
|
||||
return this.suggestionsMap.keySet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -254,7 +254,6 @@
|
|||
<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/fuzzy_suggest_analyzing_with_file_dict">
|
||||
<lst name="defaults">
|
||||
<str name="suggest">true</str>
|
||||
<str name="suggest.dictionary">fuzzy_suggest_analyzing_with_file_dict</str>
|
||||
</lst>
|
||||
<arr name="components">
|
||||
<str>fuzzy_suggest_analyzing_with_file_dict</str>
|
||||
|
@ -264,7 +263,6 @@
|
|||
<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/fuzzy_suggest_analyzing_with_high_freq_dict">
|
||||
<lst name="defaults">
|
||||
<str name="suggest">true</str>
|
||||
<str name="suggest.dictionary">fuzzy_suggest_analyzing_with_high_freq_dict</str>
|
||||
</lst>
|
||||
<arr name="components">
|
||||
<str>fuzzy_suggest_analyzing_with_high_freq_dict</str>
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.solr.handler.component;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
|
@ -27,6 +28,7 @@ import org.apache.lucene.util.LuceneTestCase.Slow;
|
|||
import org.apache.solr.BaseDistributedSearchTestCase;
|
||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.apache.solr.common.util.SimpleOrderedMap;
|
||||
import org.apache.solr.spelling.suggest.SuggesterParams;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
|
@ -67,9 +69,10 @@ public class DistributedSuggestComponentTest extends BaseDistributedSearchTestCa
|
|||
{
|
||||
NamedList<Object> nl = control.getResponse();
|
||||
@SuppressWarnings("unchecked")
|
||||
NamedList<Object> sc = (NamedList<Object>) nl.get("suggest");
|
||||
if(sc.size()==0) {
|
||||
Assert.fail("Control data did not return any suggestions.");
|
||||
Map<String, SimpleOrderedMap<NamedList<Object>>> sc = (Map<String, SimpleOrderedMap<NamedList<Object>>>) nl.get("suggest");
|
||||
String command = (String) nl.get("command");
|
||||
if(sc.size() == 0 && command == null) {
|
||||
Assert.fail("Control data did not return any suggestions or execute any command");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,12 +103,17 @@ public class DistributedSuggestComponentTest extends BaseDistributedSearchTestCa
|
|||
|
||||
//Shortcut names
|
||||
String build = SuggesterParams.SUGGEST_BUILD;
|
||||
String buildAll = SuggesterParams.SUGGEST_BUILD_ALL;
|
||||
String count = SuggesterParams.SUGGEST_COUNT;
|
||||
String dictionaryName = SuggesterParams.SUGGEST_DICT;
|
||||
|
||||
//Build the suggest dictionary
|
||||
if (random().nextBoolean()) { // build all the suggesters in one go
|
||||
query(buildRequest("", true, requestHandlerName, buildAll, "true"));
|
||||
} else { // build suggesters individually
|
||||
query(buildRequest("", true, requestHandlerName, build, "true", dictionaryName, docDictName));
|
||||
query(buildRequest("", true, requestHandlerName, build, "true", dictionaryName, docExprDictName));
|
||||
}
|
||||
|
||||
//Test Basic Functionality
|
||||
query(buildRequest("exampel", false, requestHandlerName, dictionaryName, docDictName, count, "2"));
|
||||
|
@ -113,6 +121,9 @@ public class DistributedSuggestComponentTest extends BaseDistributedSearchTestCa
|
|||
query(buildRequest("blah", true, requestHandlerName, dictionaryName, docExprDictName, count, "2"));
|
||||
query(buildRequest("blah", true, requestHandlerName, dictionaryName, docDictName, count, "2"));
|
||||
|
||||
//Test multiSuggester
|
||||
query(buildRequest("exampel", false, requestHandlerName, dictionaryName, docDictName, dictionaryName, docExprDictName, count, "2"));
|
||||
|
||||
}
|
||||
private Object[] buildRequest(String q, boolean useSuggestQ, String handlerName, String... addlParams) {
|
||||
List<Object> params = new ArrayList<Object>();
|
||||
|
@ -124,6 +135,7 @@ public class DistributedSuggestComponentTest extends BaseDistributedSearchTestCa
|
|||
}
|
||||
params.add(q);
|
||||
|
||||
|
||||
params.add("qt");
|
||||
params.add(handlerName);
|
||||
|
||||
|
|
|
@ -66,11 +66,11 @@ public class SuggestComponentTest extends SolrTestCaseJ4 {
|
|||
SuggesterParams.SUGGEST_BUILD, "true",
|
||||
SuggesterParams.SUGGEST_Q, "exampel",
|
||||
SuggesterParams.SUGGEST_COUNT, "2"),
|
||||
"//lst[@name='suggest']/lst[@name='exampel']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='exampel']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='example inputdata']",
|
||||
"//lst[@name='suggest']/lst[@name='exampel']/arr[@name='suggestions']/lst[1]/long[@name='weight'][.='45']",
|
||||
"//lst[@name='suggest']/lst[@name='exampel']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='example data']",
|
||||
"//lst[@name='suggest']/lst[@name='exampel']/arr[@name='suggestions']/lst[2]/long[@name='weight'][.='40']"
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='exampel']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='example inputdata']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[1]/long[@name='weight'][.='45']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='example data']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[2]/long[@name='weight'][.='40']"
|
||||
);
|
||||
|
||||
assertQ(req("qt", rh,
|
||||
|
@ -78,11 +78,11 @@ public class SuggestComponentTest extends SolrTestCaseJ4 {
|
|||
SuggesterParams.SUGGEST_BUILD, "true",
|
||||
SuggesterParams.SUGGEST_Q, "Rad",
|
||||
SuggesterParams.SUGGEST_COUNT, "2"),
|
||||
"//lst[@name='suggest']/lst[@name='Rad']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='Rad']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='Rad fox']",
|
||||
"//lst[@name='suggest']/lst[@name='Rad']/arr[@name='suggestions']/lst[1]/long[@name='weight'][.='35']",
|
||||
"//lst[@name='suggest']/lst[@name='Rad']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='Red fox']",
|
||||
"//lst[@name='suggest']/lst[@name='Rad']/arr[@name='suggestions']/lst[2]/long[@name='weight'][.='30']"
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='Rad']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='Rad']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='Rad fox']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='Rad']/arr[@name='suggestions']/lst[1]/long[@name='weight'][.='35']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='Rad']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='Red fox']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='Rad']/arr[@name='suggestions']/lst[2]/long[@name='weight'][.='30']"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -93,11 +93,11 @@ public class SuggestComponentTest extends SolrTestCaseJ4 {
|
|||
SuggesterParams.SUGGEST_BUILD, "true",
|
||||
SuggesterParams.SUGGEST_Q, "exampel",
|
||||
SuggesterParams.SUGGEST_COUNT, "2"),
|
||||
"//lst[@name='suggest']/lst[@name='exampel']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='exampel']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='example inputdata']",
|
||||
"//lst[@name='suggest']/lst[@name='exampel']/arr[@name='suggestions']/lst[1]/long[@name='weight'][.='120']",
|
||||
"//lst[@name='suggest']/lst[@name='exampel']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='example data']",
|
||||
"//lst[@name='suggest']/lst[@name='exampel']/arr[@name='suggestions']/lst[2]/long[@name='weight'][.='110']"
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_expr_dict']/lst[@name='exampel']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_expr_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='example inputdata']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_expr_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[1]/long[@name='weight'][.='120']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_expr_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='example data']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_expr_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[2]/long[@name='weight'][.='110']"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -108,11 +108,62 @@ public class SuggestComponentTest extends SolrTestCaseJ4 {
|
|||
SuggesterParams.SUGGEST_BUILD, "true",
|
||||
SuggesterParams.SUGGEST_Q, "chn",
|
||||
SuggesterParams.SUGGEST_COUNT, "2"),
|
||||
"//lst[@name='suggest']/lst[@name='chn']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='chn']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='chance']",
|
||||
"//lst[@name='suggest']/lst[@name='chn']/arr[@name='suggestions']/lst[1]/long[@name='weight'][.='1']",
|
||||
"//lst[@name='suggest']/lst[@name='chn']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='change']",
|
||||
"//lst[@name='suggest']/lst[@name='chn']/arr[@name='suggestions']/lst[2]/long[@name='weight'][.='1']"
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_file_based']/lst[@name='chn']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_file_based']/lst[@name='chn']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='chance']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_file_based']/lst[@name='chn']/arr[@name='suggestions']/lst[1]/long[@name='weight'][.='1']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_file_based']/lst[@name='chn']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='change']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_file_based']/lst[@name='chn']/arr[@name='suggestions']/lst[2]/long[@name='weight'][.='1']"
|
||||
);
|
||||
}
|
||||
@Test
|
||||
public void testMultiSuggester() throws Exception {
|
||||
assertQ(req("qt", rh,
|
||||
SuggesterParams.SUGGEST_DICT, "suggest_fuzzy_doc_dict",
|
||||
SuggesterParams.SUGGEST_DICT, "suggest_fuzzy_doc_expr_dict",
|
||||
SuggesterParams.SUGGEST_BUILD, "true",
|
||||
SuggesterParams.SUGGEST_Q, "exampel",
|
||||
SuggesterParams.SUGGEST_COUNT, "2"),
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='exampel']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='example inputdata']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[1]/long[@name='weight'][.='45']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='example data']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[2]/long[@name='weight'][.='40']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_expr_dict']/lst[@name='exampel']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_expr_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='example inputdata']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_expr_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[1]/long[@name='weight'][.='120']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_expr_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='example data']",
|
||||
"//lst[@name='suggest']/lst[@name='suggest_fuzzy_doc_expr_dict']/lst[@name='exampel']/arr[@name='suggestions']/lst[2]/long[@name='weight'][.='110']"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildAllSuggester() throws Exception {
|
||||
assertQ(req("qt", rh,
|
||||
SuggesterParams.SUGGEST_BUILD_ALL, "true",
|
||||
SuggesterParams.SUGGEST_Q, "exampel",
|
||||
SuggesterParams.SUGGEST_COUNT, "2"),
|
||||
"//str[@name='command'][.='buildAll']"
|
||||
);
|
||||
|
||||
assertQ(req("qt", rh,
|
||||
SuggesterParams.SUGGEST_BUILD_ALL, "true"),
|
||||
"//str[@name='command'][.='buildAll']"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReloadAllSuggester() throws Exception {
|
||||
assertQ(req("qt", rh,
|
||||
SuggesterParams.SUGGEST_RELOAD_ALL, "true",
|
||||
SuggesterParams.SUGGEST_Q, "exampel",
|
||||
SuggesterParams.SUGGEST_COUNT, "2"),
|
||||
"//str[@name='command'][.='reloadAll']"
|
||||
);
|
||||
|
||||
assertQ(req("qt", rh,
|
||||
SuggesterParams.SUGGEST_RELOAD_ALL, "true"),
|
||||
"//str[@name='command'][.='reloadAll']"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,39 +22,40 @@ import org.junit.BeforeClass;
|
|||
|
||||
public class TestFileDictionaryLookup extends SolrTestCaseJ4 {
|
||||
static final String REQUEST_URI = "/fuzzy_suggest_analyzing_with_file_dict";
|
||||
static final String DICT_NAME = "fuzzy_suggest_analyzing_with_file_dict";
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
initCore("solrconfig-phrasesuggest.xml","schema-phrasesuggest.xml");
|
||||
assertQ(req("qt", REQUEST_URI, "q", "", SuggesterParams.SUGGEST_BUILD, "true"));
|
||||
assertQ(req("qt", REQUEST_URI, "q", "", SuggesterParams.SUGGEST_DICT, DICT_NAME, SuggesterParams.SUGGEST_BUILD, "true"));
|
||||
}
|
||||
|
||||
public void testDefault() throws Exception {
|
||||
|
||||
// tests to demonstrate default maxEdit parameter (value: 1), control for testWithMaxEdit2
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chagn", SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='chagn']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='chagn']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='chance']",
|
||||
"//lst[@name='suggest']/lst[@name='chagn']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='change']"
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chagn", SuggesterParams.SUGGEST_DICT, DICT_NAME, SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chagn']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chagn']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='chance']",
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chagn']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='change']"
|
||||
);
|
||||
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chacn", SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='chacn']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='chacn']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='chance']",
|
||||
"//lst[@name='suggest']/lst[@name='chacn']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='change']"
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chacn", SuggesterParams.SUGGEST_DICT, DICT_NAME, SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chacn']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chacn']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='chance']",
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chacn']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='change']"
|
||||
);
|
||||
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chagr", SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='chagr']/int[@name='numFound'][.='1']",
|
||||
"//lst[@name='suggest']/lst[@name='chagr']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='charge']"
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chagr", SuggesterParams.SUGGEST_DICT, DICT_NAME, SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chagr']/int[@name='numFound'][.='1']",
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chagr']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='charge']"
|
||||
);
|
||||
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chanr", SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='chanr']/int[@name='numFound'][.='3']"
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chanr", SuggesterParams.SUGGEST_DICT, DICT_NAME, SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chanr']/int[@name='numFound'][.='3']"
|
||||
);
|
||||
|
||||
assertQ(req("qt", REQUEST_URI, "q", "cyhnce", SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='cyhnce']/int[@name='numFound'][.='0']"
|
||||
assertQ(req("qt", REQUEST_URI, "q", "cyhnce", SuggesterParams.SUGGEST_DICT, DICT_NAME, SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='cyhnce']/int[@name='numFound'][.='0']"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.junit.BeforeClass;
|
|||
public class TestHighFrequencyDictionaryFactory extends SolrTestCaseJ4 {
|
||||
|
||||
static final String REQUEST_URI = "/fuzzy_suggest_analyzing_with_high_freq_dict";
|
||||
static final String DICT_NAME = "fuzzy_suggest_analyzing_with_high_freq_dict";
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
|
@ -39,36 +40,36 @@ public class TestHighFrequencyDictionaryFactory extends SolrTestCaseJ4 {
|
|||
"stext", "chance"));
|
||||
|
||||
assertU(commit());
|
||||
assertQ(req("qt", REQUEST_URI, "q", "", SuggesterParams.SUGGEST_BUILD, "true"));
|
||||
assertQ(req("qt", REQUEST_URI, "q", "", SuggesterParams.SUGGEST_DICT, DICT_NAME, SuggesterParams.SUGGEST_BUILD, "true"));
|
||||
}
|
||||
|
||||
|
||||
public void testDefault() throws Exception {
|
||||
|
||||
// tests to demonstrate default maxEdit parameter (value: 1), control for testWithMaxEdit2
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chagn", SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='chagn']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='chagn']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='chance']",
|
||||
"//lst[@name='suggest']/lst[@name='chagn']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='change']"
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chagn", SuggesterParams.SUGGEST_DICT, DICT_NAME, SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chagn']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chagn']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='chance']",
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chagn']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='change']"
|
||||
);
|
||||
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chacn", SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='chacn']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='chacn']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='chance']",
|
||||
"//lst[@name='suggest']/lst[@name='chacn']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='change']"
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chacn", SuggesterParams.SUGGEST_DICT, DICT_NAME, SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chacn']/int[@name='numFound'][.='2']",
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chacn']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='chance']",
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chacn']/arr[@name='suggestions']/lst[2]/str[@name='term'][.='change']"
|
||||
);
|
||||
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chagr", SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='chagr']/int[@name='numFound'][.='1']",
|
||||
"//lst[@name='suggest']/lst[@name='chagr']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='charge']"
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chagr", SuggesterParams.SUGGEST_DICT, DICT_NAME, SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chagr']/int[@name='numFound'][.='1']",
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chagr']/arr[@name='suggestions']/lst[1]/str[@name='term'][.='charge']"
|
||||
);
|
||||
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chanr", SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='chanr']/int[@name='numFound'][.='3']"
|
||||
assertQ(req("qt", REQUEST_URI, "q", "chanr", SuggesterParams.SUGGEST_DICT, DICT_NAME, SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='chanr']/int[@name='numFound'][.='3']"
|
||||
);
|
||||
|
||||
assertQ(req("qt", REQUEST_URI, "q", "cyhnce", SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='cyhnce']/int[@name='numFound'][.='0']"
|
||||
assertQ(req("qt", REQUEST_URI, "q", "cyhnce", SuggesterParams.SUGGEST_DICT, DICT_NAME, SuggesterParams.SUGGEST_COUNT, "3"),
|
||||
"//lst[@name='suggest']/lst[@name='"+ DICT_NAME +"']/lst[@name='cyhnce']/int[@name='numFound'][.='0']"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue