mirror of https://github.com/apache/lucene.git
SOLR-2993: fix (2) for fail on TestSpellCheckResponse: ConjunctionSolrSpellChecker was not preserving original Token Freqs.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1346116 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e4a6061e8a
commit
050f6c7a3c
|
@ -19,6 +19,7 @@ package org.apache.solr.spelling;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
@ -135,8 +136,12 @@ public class ConjunctionSolrSpellChecker extends SolrSpellChecker {
|
|||
//TODO: This just interleaves the results. In the future, we might want to let users give each checker its
|
||||
// own weight and use that in combination to score & frequency to sort the results ?
|
||||
private SpellingResult mergeCheckers(SpellingResult[] results, int numSug) {
|
||||
Map<Token, Integer> combinedTokenFrequency = new HashMap<Token, Integer>();
|
||||
Map<Token, List<LinkedHashMap<String, Integer>>> allSuggestions = new LinkedHashMap<Token, List<LinkedHashMap<String, Integer>>>();
|
||||
for(SpellingResult result : results) {
|
||||
if(result.getTokenFrequency()!=null) {
|
||||
combinedTokenFrequency.putAll(result.getTokenFrequency());
|
||||
}
|
||||
for(Map.Entry<Token, LinkedHashMap<String, Integer>> entry : result.getSuggestions().entrySet()) {
|
||||
List<LinkedHashMap<String, Integer>> allForThisToken = allSuggestions.get(entry.getKey());
|
||||
if(allForThisToken==null) {
|
||||
|
@ -161,6 +166,10 @@ public class ConjunctionSolrSpellChecker extends SolrSpellChecker {
|
|||
anyData = true;
|
||||
Map.Entry<String,Integer> corr = iter.next();
|
||||
combinedResult.add(original, corr.getKey(), corr.getValue());
|
||||
Integer tokenFrequency = combinedTokenFrequency.get(original);
|
||||
if(tokenFrequency!=null) {
|
||||
combinedResult.addFrequency(original, tokenFrequency);
|
||||
}
|
||||
if(++numberAdded==numSug) {
|
||||
break;
|
||||
}
|
||||
|
@ -170,7 +179,9 @@ public class ConjunctionSolrSpellChecker extends SolrSpellChecker {
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return combinedResult;
|
||||
}
|
||||
|
||||
|
|
|
@ -1245,7 +1245,7 @@
|
|||
collations (re-written queries) can include a combination of
|
||||
corrections from both spellcheckers -->
|
||||
<str name="spellcheck.dictionary">default</str>
|
||||
<!--str name="spellcheck.dictionary">wordbreak</str-->
|
||||
<str name="spellcheck.dictionary">wordbreak</str>
|
||||
<str name="spellcheck">on</str>
|
||||
<str name="spellcheck.extendedResults">true</str>
|
||||
<str name="spellcheck.count">10</str>
|
||||
|
|
|
@ -56,10 +56,9 @@ public class TestSpellCheckResponse extends SolrJettyTestBase {
|
|||
server.add(doc);
|
||||
server.commit(true, true);
|
||||
|
||||
SolrQuery query = new SolrQuery("*:*");
|
||||
SolrQuery query = new SolrQuery("name:samsang");
|
||||
query.set(CommonParams.QT, "/spell");
|
||||
query.set("spellcheck", true);
|
||||
query.set(SpellingParams.SPELLCHECK_Q, "samsang");
|
||||
query.set(SpellingParams.SPELLCHECK_BUILD, true);
|
||||
QueryRequest request = new QueryRequest(query);
|
||||
SpellCheckResponse response = request.process(server).getSpellCheckResponse();
|
||||
|
|
Loading…
Reference in New Issue