Skip to content

Commit

Permalink
Only set spellcheck.q if we set local parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Mar 1, 2015
1 parent 50acc87 commit 023024e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
19 changes: 6 additions & 13 deletions lib/blacklight/solr/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def add_query_to_solr(solr_parameters)
key.to_s + "=" + solr_param_quote(val, :quote => "'")
end.join(" ")
solr_parameters[:q] = "{!#{local_params}}#{blacklight_params[:q]}"

##
# Set Solr spellcheck.q to be original user-entered query, without
# our local params, otherwise it'll try and spellcheck the local
# params!
solr_parameters["spellcheck.q"] ||= blacklight_params[:q]
elsif blacklight_params[:q].is_a? Hash
q = blacklight_params[:q]
solr_parameters[:q] = if q.values.any?(&:blank?)
Expand All @@ -61,19 +67,6 @@ def add_query_to_solr(solr_parameters)
elsif blacklight_params[:q]
solr_parameters[:q] = blacklight_params[:q]
end


##
# Set Solr spellcheck.q to be original user-entered query, without
# our local params, otherwise it'll try and spellcheck the local
# params! Unless spellcheck.q has already been set by someone,
# respect that.
#
# TODO: Change calling code to expect this as a symbol instead of
# a string, for consistency? :'spellcheck.q' is a symbol. Right now
# rspec tests for a string, and can't tell if other code may
# insist on a string.
solr_parameters["spellcheck.q"] = blacklight_params[:q] unless solr_parameters["spellcheck.q"]
end

##
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/blacklight/search_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def params
expect(path).to eq 'select'
expect(params[:params]['facet.field']).to eq ["format", "{!ex=pub_date_single}pub_date", "subject_topic_facet", "language_facet", "lc_1letter_facet", "subject_geo_facet", "subject_era_facet"]
expect(params[:params]["facet.query"]).to eq ["pub_date:[#{5.years.ago.year} TO *]", "pub_date:[#{10.years.ago.year} TO *]", "pub_date:[#{25.years.ago.year} TO *]"]
expect(params[:params]).to include('rows' => 10, 'qt'=>"custom_request_handler", 'q'=>"", "spellcheck.q"=>"", "f.subject_topic_facet.facet.limit"=>21, 'sort'=>"score desc, pub_date_sort desc, title_sort asc")
expect(params[:params]).to include('rows' => 10, 'qt'=>"custom_request_handler", 'q'=>"", "f.subject_topic_facet.facet.limit"=>21, 'sort'=>"score desc, pub_date_sort desc, title_sort asc")
end.and_return({'response'=>{'docs'=>[]}})
subject.search_results({ q: @all_docs_query }, default_method_chain)
end
Expand Down
1 change: 0 additions & 1 deletion spec/lib/blacklight/solr/search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@
let(:user_params) { { q: "" } }
it "should return empty string q in solr parameters" do
expect(subject[:q]).to eq ""
expect(subject["spellcheck.q"]).to eq ""
end
end

Expand Down

0 comments on commit 023024e

Please sign in to comment.