Skip to content

Commit

Permalink
Blacklight.config solr defaults consolidated in [:default_solr_params…
Browse files Browse the repository at this point in the history
…]. CODEBASE-244
  • Loading branch information
jrochkind committed Aug 19, 2010
1 parent 83f4589 commit 82c7cae
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
17 changes: 13 additions & 4 deletions config/initializers/blacklight_config.rb
Expand Up @@ -36,9 +36,13 @@


##############################

config[:default_solr_params] = {
:qt => "search",
:per_page => 10
}


config[:default_qt] = "search"


# solr field values given special treatment in the show (single result) view
Expand All @@ -51,7 +55,6 @@
# solr fld values given special treatment in the index (search results) view
config[:index] = {
:show_link => "title_display",
:num_per_page => 10,
:record_display_type => "format"
}

Expand All @@ -61,15 +64,15 @@
# for human reading/writing, kind of like search_fields. Eg,
# config[:facet] << {:field_name => "format", :label => "Format", :limit => 10}
config[:facet] = {
:field_names => [
:field_names => (facet_fields = [
"format",
"pub_date",
"subject_topic_facet",
"language_facet",
"lc_1letter_facet",
"subject_geo_facet",
"subject_era_facet"
],
]),
:labels => {
"format" => "Format",
"pub_date" => "Publication Year",
Expand All @@ -91,6 +94,12 @@
}
}

# Have BL send all facet field names to Solr, which has been the default
# previously. Simply remove these lines if you'd rather use Solr request
# handler defaults, or have no facets.
config[:default_solr_params] ||= {}
config[:default_solr_params][:"facet.field"] = facet_fields

# solr fields to be displayed in the index (search results) view
# The ordering of the field names is the order of the display
config[:index_fields] = {
Expand Down
4 changes: 2 additions & 2 deletions lib/blacklight/search_fields.rb
Expand Up @@ -10,7 +10,7 @@
# [:display_label]
# "Title", # user-displayable label, optional, if not supplied :key.titlecase will be used
# [:qt]
# "search", # Solr qt param, request handler, usually can be left blank; defaults to Blacklight.config[:default_qt] if not specified.
# "search", # Solr qt param, request handler, usually can be left blank; defaults to Blacklight.config[:default_solr_params][:qt] if not specified.
# [:solr_parameters]
# {:qf => "something"} # optional hash of additional parameters to pass to solr for searches on this field.
# [:solr_local_parameters]
Expand Down Expand Up @@ -98,7 +98,7 @@ def normalize_config(field_hash)
field_hash[:display_label] ||= field_hash[:key].titlecase

# If no :qt was provided, take from config default
field_hash[:qt] ||= config[:default_qt]
field_hash[:qt] ||= config[:default_solr_params][:qt] if config[:default_solr_params]

field_hash
end
Expand Down
27 changes: 10 additions & 17 deletions lib/blacklight/solr_helper.rb
Expand Up @@ -51,26 +51,15 @@ def solr_param_quote(val, options = {})
#
# Incoming parameter :f is mapped to :fq solr parameter.
def solr_search_params(extra_controller_params={})
solr_parameters = {}


# Order of precedence for all the places solr params can come from,
# start lowest, and keep over-riding with higher.
####
# Start with general defaults from BL config.
# TODO -- remove :facets
# when are we passing in "facets" here? just for tests? -- no, always.
# Bess prefers to pass in the desired facets this way.
# Naomi prefers it as part of the Solr request handler
# ** we need to be consistent about what is getting passed in:
# ** -- solr params or controller params that need to be mapped?
# jrochkind 28-dec-09 likes it the way it is, where facets can be part
# of the solr request handler OR in Blacklight. If you don't want them
# in blacklight, just leave don't fill out the config.
####
solr_parameters = {
:qt => Blacklight.config[:default_qt],
:facets => Blacklight.config[:facet][:field_names].clone,
:per_page => (Blacklight.config[:index][:num_per_page] rescue "10")
}

# Start with general defaults from BL config.
solr_parameters.deep_merge!(Blacklight.config[:default_solr_params]) if Blacklight.config[:default_solr_params]


###
# Merge in search field configured values, if present, over-writing general
Expand Down Expand Up @@ -109,7 +98,11 @@ def solr_search_params(extra_controller_params={})
# (Stanford is doing faux "hierarchical" facets this way; the
# hierarchical facet code for SOLR isn't fully baked yet and won't be
# included until Solr 1.5)
# TODO: jrochkind asks why we need to copy "facet.field" to RSolr-specific
# :facets, can't we just use "facet.field" alone and ignore the duplicate
# confusing one?
if params.has_key?("facet.field")
solr_parameters[:facets] ||= []
params["facet.field"].each do |ff|
if !solr_parameters[:facets].include?(ff)
solr_parameters[:facets] << ff
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/catalog_controller_spec.rb
Expand Up @@ -93,7 +93,7 @@
page = 2
get :index, :page => page
assigns[:response].docs.size.should > 1
assigns[:response].params[:start].to_i.should == (page-1) * Blacklight.config[:index][:num_per_page]
assigns[:response].params[:start].to_i.should == (page-1) * Blacklight.config[:default_solr_params][:per_page]
assert_facets_have_values(assigns[:response].facets)
end

Expand Down
15 changes: 8 additions & 7 deletions spec/helpers/solr_helper_spec.rb
Expand Up @@ -81,10 +81,10 @@ def facet_limit_hash
@produced_params[:per_page].should == 10
end
it 'should have default facet fields' do
@produced_params[:facets][:fields].should == Blacklight.config[:facet][:field_names]
@produced_params[:"facet.field"].should == Blacklight.config[:default_solr_params][:"facet.field"]
end
it 'should not use the exact facet array from config defaults' do
@produced_params[:facets][:fields].should_not be_equal(Blacklight.config[:facet][:field_names])
@produced_params[:"facet.field"].should_not be_equal(Blacklight.config[:facet][:field_names])
end
it "should have default qt" do
@produced_params[:qt].should == "search"
Expand All @@ -111,7 +111,7 @@ def facet_limit_hash

params[:q].should be_blank
params["spellcheck.q"].should be_blank
params[:facets][:fields].should == Blacklight.config[:facet][:field_names]
params[:"facet.field"].should == Blacklight.config[:default_solr_params][:"facet.field"]

@single_facet.each_value do |value|
params[:fq].should include("{!raw f=#{@single_facet.keys[0]}}#{value}")
Expand Down Expand Up @@ -155,7 +155,7 @@ def facet_limit_hash

params[:q].should == "wome"
params["spellcheck.q"].should == params[:q]
params[:facets][:fields].should == Blacklight.config[:facet][:field_names]
params[:"facet.field"].should == Blacklight.config[:default_solr_params][:"facet.field"]
params[:commit].should be_nil
params[:action].should be_nil
params[:controller].should be_nil
Expand Down Expand Up @@ -199,6 +199,7 @@ def facet_limit_hash
describe "should respect proper precedence of settings, " do
before do
@produced_params = @solr_helper_with_params.solr_search_params(:sort => "extra_params_sort")
1+1
end


Expand All @@ -207,7 +208,7 @@ def facet_limit_hash
end

it "should fall through to BL general defaults for qt not otherwise specified " do
@produced_params[:qt].should == Blacklight.config[:default_qt]
@produced_params[:qt].should == Blacklight.config[:default_solr_params][:qt]
end

it "should take per_page from search field definition where specified" do
Expand Down Expand Up @@ -550,7 +551,7 @@ def facet_limit_hash
it 'should have number of results (per page) set in initializer, by default' do
(solr_response, document_list) = @solr_helper.get_search_results(:q => @all_docs_query)
solr_response.docs.size.should == document_list.size
solr_response.docs.size.should == Blacklight.config[:index][:num_per_page]
solr_response.docs.size.should == Blacklight.config[:default_solr_params][:per_page]
end

it 'should get number of results per page requested' do
Expand All @@ -563,7 +564,7 @@ def facet_limit_hash
it 'should skip appropriate number of results when requested - default per page' do
page = 3
(solr_response2, document_list2) = @solr_helper.get_search_results(:q => @all_docs_query, :page => page)
solr_response2.params[:start].to_i.should == Blacklight.config[:index][:num_per_page] * (page-1)
solr_response2.params[:start].to_i.should == Blacklight.config[:default_solr_params][:per_page] * (page-1)
end
it 'should skip appropriate number of results when requested - non-default per page' do
page = 3
Expand Down

0 comments on commit 82c7cae

Please sign in to comment.