Skip to content

Apache Lucene open-source search software

SOLR-1094 -- Incorrect value of correctlySpelled attribute in some cases

Shalin Shekhar Mangar809a559b6394
diff --git a/CHANGES.txt b/CHANGES.txt
index 591000ffd29..2a7c05fb63f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -347,6 +347,8 @@ Bug Fixes
38. SOLR-1126: Replicated files have incorrect timestamp (Jian Han Guo, Jeff Newburn, Noble Paul via shalin)
+39. SOLR-1094: Incorrect value of correctlySpelled attribute in some cases (David Smiley, mark Miller via shalin)
+
Other Changes
----------------------
1. Upgraded to Lucene 2.4.0 (yonik)
diff --git a/src/java/org/apache/solr/handler/component/SpellCheckComponent.java b/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
index 898a6fdb86a..b10979c6187 100644
--- a/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
+++ b/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
@@ -186,11 +186,17 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar
NamedList result = new NamedList();
Map<Token, LinkedHashMap<String, Integer>> suggestions = spellingResult.getSuggestions();
boolean hasFreqInfo = spellingResult.hasTokenFrequencyInfo();
- boolean isCorrectlySpelled = true;
+ boolean isCorrectlySpelled = false;
Map<Token, String> best = null;
if (collate == true){
best = new LinkedHashMap<Token, String>(suggestions.size());
}
+
+ // will be flipped to false if any of the suggestions are not in the index and hasFreqInfo is true
+ if(suggestions.size() > 0) {
+ isCorrectlySpelled = true;
+ }
+
for (Map.Entry<Token, LinkedHashMap<String, Integer>> entry : suggestions.entrySet()) {
Token inputToken = entry.getKey();
Map<String, Integer> theSuggestions = entry.getValue();
diff --git a/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java b/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java
index 64d1bce1cf8..81c5f6dfa04 100644
--- a/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java
+++ b/src/test/org/apache/solr/handler/component/SpellCheckComponentTest.java
@@ -255,9 +255,22 @@ public class SpellCheckComponentTest extends AbstractSolrTestCase {
SolrQueryRequest req = new LocalSolrQueryRequest(core, new MapSolrParams(
args));
- assertQ("Make sure correct spellings are signalled in the response", req,
+ assertQ("Make sure correct spellings are signalled in the response", req,
"//*[@numFound='1']", "//result/doc[1]/int[@name='id'][.='1']",
"//*/lst[@name='suggestions']");
+
+
+ args = new HashMap<String, String>();
+
+ args.put(CommonParams.Q, "lakkle");
+ args.put(CommonParams.QT, "spellCheckCompRH");
+ args.put(SpellCheckComponent.SPELLCHECK_EXTENDED_RESULTS, "true");
+ args.put(SpellCheckComponent.COMPONENT_NAME, "true");
+ req = new LocalSolrQueryRequest(core, new MapSolrParams(
+ args));
+
+ assertQ("Make sure correct spellings are signalled in the response", req,
+ "//*[@numFound='0']", "//*/lst[@name='suggestions']", "//*/bool[@name='correctlySpelled'][.='false']");
}
public void testInit() throws Exception {