diff --git a/lib/blacklight/solr/search_builder.rb b/lib/blacklight/solr/search_builder.rb index b89bfcbbbd..2ee9262ad0 100644 --- a/lib/blacklight/solr/search_builder.rb +++ b/lib/blacklight/solr/search_builder.rb @@ -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?) @@ -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 ## diff --git a/spec/lib/blacklight/search_helper_spec.rb b/spec/lib/blacklight/search_helper_spec.rb index 3ee1a65bca..2690b73f50 100644 --- a/spec/lib/blacklight/search_helper_spec.rb +++ b/spec/lib/blacklight/search_helper_spec.rb @@ -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 diff --git a/spec/lib/blacklight/solr/search_builder_spec.rb b/spec/lib/blacklight/solr/search_builder_spec.rb index 42b095f4ee..3499c3955e 100644 --- a/spec/lib/blacklight/solr/search_builder_spec.rb +++ b/spec/lib/blacklight/solr/search_builder_spec.rb @@ -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