SOLR-606: fixed spell checker collation issue

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@685983 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2008-08-14 18:17:49 +00:00
parent facb2db8f3
commit 3c034ffbc9
3 changed files with 26 additions and 2 deletions

View File

@ -528,6 +528,8 @@ Bug Fixes
47. SOLR-669: snappuler fix for FreeBSD/Darwin (Richard "Trey" Hyde via Otis Gospodnetic)
48. SOLR-606: Fixed spell check collation offset issue. (Stefan Oestreicher , Geoffrey Young, gsingers)
Other Changes
1. SOLR-135: Moved common classes to org.apache.solr.common and altered the
build scripts to make two jars: apache-solr-1.3.jar and

View File

@ -190,7 +190,7 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
boolean isCorrectlySpelled = true;
Map<Token, String> best = null;
if (collate == true){
best = new HashMap<Token, String>(suggestions.size());
best = new LinkedHashMap<Token, String>(suggestions.size());
}
for (Map.Entry<Token, LinkedHashMap<String, Integer>> entry : suggestions.entrySet()) {
Token inputToken = entry.getKey();
@ -225,10 +225,13 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
}
if (collate == true){
StringBuilder collation = new StringBuilder(origQuery);
int offset = 0;
for (Iterator<Map.Entry<Token, String>> bestIter = best.entrySet().iterator(); bestIter.hasNext();) {
Map.Entry<Token, String> entry = bestIter.next();
Token tok = entry.getKey();
collation.replace(tok.startOffset(), tok.endOffset(), entry.getValue());
collation.replace(tok.startOffset() + offset,
tok.endOffset() + offset, entry.getValue());
offset += entry.getValue().length() - (tok.endOffset() - tok.startOffset());
}
String collVal = collation.toString();
if (collVal.equals(origQuery) == false) {

View File

@ -199,6 +199,7 @@ public class SpellCheckComponentTest extends AbstractSolrTestCase {
SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");
SolrQueryResponse rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
NamedList values = rsp.getValues();
NamedList spellCheck = (NamedList) values.get("spellcheck");
@ -212,6 +213,7 @@ public class SpellCheckComponentTest extends AbstractSolrTestCase {
params.add(CommonParams.Q, "documemt lowerfilt:broen^4");
handler = core.getRequestHandler("spellCheckCompRH");
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
values = rsp.getValues();
spellCheck = (NamedList) values.get("spellcheck");
@ -222,6 +224,23 @@ public class SpellCheckComponentTest extends AbstractSolrTestCase {
assertTrue("collation is null and it shouldn't be", collation != null);
assertTrue(collation + " is not equal to " + "document lowerfilt:brown^4", collation.equals("document lowerfilt:brown^4") == true);
params.remove(CommonParams.Q);
params.add(CommonParams.Q, "documemtsss broens");
handler = core.getRequestHandler("spellCheckCompRH");
rsp = new SolrQueryResponse();
rsp.add("responseHeader", new SimpleOrderedMap());
handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
values = rsp.getValues();
spellCheck = (NamedList) values.get("spellcheck");
assertTrue("spellCheck is null and it shouldn't be", spellCheck != null);
suggestions = (NamedList) spellCheck.get("suggestions");
assertTrue("suggestions is null and it shouldn't be", suggestions != null);
collation = (String) suggestions.get("collation");
assertTrue("collation is null and it shouldn't be", collation != null);
System.out.println("Collation: " + collation);
assertTrue(collation + " is not equal to " + "document brown", collation.equals("document brown") == true);
}
public void testCorrectSpelling() throws Exception {