Permalink
Browse files

Allow spellcheck collation for one word

  • Loading branch information...
1 parent cab3055 commit 435f57289e682da225252a0307dbd8b2419b6514 @ethirajsrinivasan ethirajsrinivasan committed Nov 11, 2016
Showing with 47 additions and 3 deletions.
  1. +2 −3 sunspot/lib/sunspot/search/standard_search.rb
  2. +45 −0 sunspot/spec/integration/spellcheck_spec.rb
@@ -49,12 +49,11 @@ def spellcheck_suggestion_for(term)
# the index. Otherwise return Solr's suggested collation.
#
# Solr's suggested collation is more liberal, replacing even terms that
- # are present in the index. This may not be useful if only one term is
- # misspelled and preventing useful results.
+ # are present in the index.
#
# Mix and match in your views for a blend of strict and liberal collations.
def spellcheck_collation(*terms)
- if solr_spellcheck['suggestions'] && solr_spellcheck['suggestions'].length > 2
+ if solr_spellcheck['suggestions'] && solr_spellcheck['suggestions'].length > 0
collation = terms.join(" ").dup if terms
# If we are given a query string, tokenize it and strictly replace
@@ -69,6 +69,51 @@
end
search.spellcheck_collation.should == 'clojure developer'
end
+
+ it 'returns Solr collation if terms are not provided even for single word' do
+
+ search = Sunspot.search(Post) do
+ keywords 'lojure'
+ spellcheck :count => 3, :only_more_popular => true
+ end
+ search.spellcheck_collation.should == 'clojure'
+ end
+
+ it 'returns Solr collation if terms are provided even for single word' do
+
+ search = Sunspot.search(Post) do
+ keywords 'lojure'
+ spellcheck :count => 3
+ end
+ search.spellcheck_collation.should == 'clojure'
+ end
+
+ it 'returns Solr collation if terms are provided even for single word' do
+
+ search = Sunspot.search(Post) do
+ keywords 'lojure'
+ spellcheck :count => 3
+ end
+ search.spellcheck_collation('lojure').should == 'clojure'
+ end
+
+ it 'returns Solr collation if terms are provided even if single keyword is word' do
+
+ search = Sunspot.search(Post) do
+ keywords 'C++, lojure Developer'
+ spellcheck :count => 3
+ end
+ search.spellcheck_collation.should == 'C++, clojure Developer'
+ end
+
+ it 'returns nil if terms are provided which varies from actual keywords' do
+
+ search = Sunspot.search(Post) do
+ keywords 'clojure'
+ spellcheck :count => 3
+ end
+ search.spellcheck_collation('lojure').should == nil
+ end
end
end

0 comments on commit 435f572

Please sign in to comment.