Skip to content

Commit

Permalink
Allow spellcheck collation to support Solr 5 json response format
Browse files Browse the repository at this point in the history
  • Loading branch information
tampakis authored and cbeer committed Sep 9, 2015
1 parent c4b93f0 commit 5d7082d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/blacklight/solr_response/spelling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def collation
unless suggestions.nil?
if suggestions.index("collation")
suggestions[suggestions.index("collation") + 1]
elsif spellcheck.key?("collations")
spellcheck['collations'].last
end
end
end
Expand Down
39 changes: 30 additions & 9 deletions spec/lib/blacklight/solr_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,34 @@ def create_response
expect(r.spelling.words).to eq []
end

it 'should provide spelling suggestions for a regular spellcheck results with a collation' do
raw_response = eval(mock_response_with_spellcheck_collation)
r = Blacklight::SolrResponse.new(raw_response, {})
expect(r.spelling.words).to include("dell")
expect(r.spelling.words).to include("ultrasharp")
context "pre solr 5 spellcheck collation syntax" do
it 'should provide spelling suggestions for a regular spellcheck results with a collation' do
raw_response = eval(mock_response_with_spellcheck_collation)
r = Blacklight::SolrResponse.new(raw_response, {})
expect(r.spelling.words).to include("dell")
expect(r.spelling.words).to include("ultrasharp")
end

it 'should provide spelling suggestion collation' do
raw_response = eval(mock_response_with_spellcheck_collation)
r = Blacklight::SolrResponse.new(raw_response, {})
expect(r.spelling.collation).to eq 'dell ultrasharp'
end
end

it 'should provide spelling suggestion collation' do
raw_response = eval(mock_response_with_spellcheck_collation)
r = Blacklight::SolrResponse.new(raw_response, {})
expect(r.spelling.collation).to eq 'dell ultrasharp'
context "solr 5 spellcheck collation syntax" do
it 'should provide spelling suggestions for a regular spellcheck results with a collation' do
raw_response = eval(mock_response_with_spellcheck_collation_solr5)
r = Blacklight::SolrResponse.new(raw_response, {})
expect(r.spelling.words).to include("dell")
expect(r.spelling.words).to include("ultrasharp")
end

it 'should provide spelling suggestion collation' do
raw_response = eval(mock_response_with_spellcheck_collation_solr5)
r = Blacklight::SolrResponse.new(raw_response, {})
expect(r.spelling.collation).to eq 'dell ultrasharp'
end
end

it "should provide MoreLikeThis suggestions" do
Expand Down Expand Up @@ -207,6 +224,10 @@ def mock_response_with_spellcheck_same_frequency
def mock_response_with_spellcheck_collation
%|{'responseHeader'=>{'status'=>0,'QTime'=>3,'params'=>{'spellspellcheck.build'=>'true','spellcheck'=>'true','q'=>'hell','spellcheck.q'=>'hell ultrashar','wt'=>'ruby','spellcheck.collate'=>'true'}},'response'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'spellcheck'=>{'suggestions'=>['hell',{'numFound'=>1,'startOffset'=>0,'endOffset'=>4,'suggestion'=>['dell']},'ultrashar',{'numFound'=>1,'startOffset'=>5,'endOffset'=>14,'suggestion'=>['ultrasharp']},'collation','dell ultrasharp']}}|
end

def mock_response_with_spellcheck_collation_solr5
%|{'responseHeader'=>{'status'=>0,'QTime'=>3,'params'=>{'spellspellcheck.build'=>'true','spellcheck'=>'true','q'=>'hell','spellcheck.q'=>'hell ultrashar','wt'=>'ruby','spellcheck.collate'=>'true'}},'response'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'spellcheck'=>{'suggestions'=>['hell',{'numFound'=>1,'startOffset'=>0,'endOffset'=>4,'suggestion'=>['dell']},'ultrashar',{'numFound'=>1,'startOffset'=>5,'endOffset'=>14,'suggestion'=>['ultrasharp']}],'collations'=>['collation','dell ultrasharp']}}|
end

def mock_response_with_more_like_this
%({'responseHeader'=>{'status'=>0,'QTime'=>8,'params'=>{'facet'=>'false','mlt.mindf'=>'1','mlt.fl'=>'subject_t','fl'=>'id','mlt.count'=>'3','mlt.mintf'=>'0','mlt'=>'true','q.alt'=>'*:*','qt'=>'search','wt'=>'ruby'}},'response'=>{'numFound'=>30,'start'=>0,'docs'=>[{'id'=>'00282214'},{'id'=>'00282371'},{'id'=>'00313831'},{'id'=>'00314247'},{'id'=>'43037890'},{'id'=>'53029833'},{'id'=>'77826928'},{'id'=>'78908283'},{'id'=>'79930185'},{'id'=>'85910001'}]},'moreLikeThis'=>{'00282214'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'00282371'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'00313831'=>{'numFound'=>1,'start'=>0,'docs'=>[{'id'=>'96933325'}]},'00314247'=>{'numFound'=>3,'start'=>0,'docs'=>[{'id'=>'2008543486'},{'id'=>'96933325'},{'id'=>'2009373513'}]},'43037890'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'53029833'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'77826928'=>{'numFound'=>1,'start'=>0,'docs'=>[{'id'=>'94120425'}]},'78908283'=>{'numFound'=>0,'start'=>0,'docs'=>[]},'79930185'=>{'numFound'=>2,'start'=>0,'docs'=>[{'id'=>'94120425'},{'id'=>'2007020969'}]},'85910001'=>{'numFound'=>0,'start'=>0,'docs'=>[]}}})
Expand Down

0 comments on commit 5d7082d

Please sign in to comment.