Skip to content

Commit

Permalink
Merge 4ba23d5 into d1a9955
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Feb 10, 2014
2 parents d1a9955 + 4ba23d5 commit 5f933c4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
22 changes: 22 additions & 0 deletions lib/blacklight/solr_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ def add_facetting_to_solr(solr_parameters, user_params)
if facet.sort
solr_parameters[:"f.#{facet.field}.facet.sort"] = facet.sort
end

if facet.solr_params
facet.solr_params.each do |k, v|
solr_parameters[:"f.#{facet.field}.#{k}"] = v
end
end

end

# Support facet paging and 'more'
Expand All @@ -341,11 +348,26 @@ def with_ex_local_param(ex, value)

def add_solr_fields_to_query solr_parameters, user_parameters
return unless blacklight_config.add_field_configuration_to_solr_request

blacklight_config.show_fields.each do |field_name, field|
if field.solr_params
field.solr_params.each do |k, v|
solr_parameters[:"f.#{field.field}.#{k}"] = v
end
end
end

blacklight_config.index_fields.each do |field_name, field|
if field.highlight
solr_parameters[:hl] = true
solr_parameters.append_highlight_field field.field
end

if field.solr_params
field.solr_params.each do |k, v|
solr_parameters[:"f.#{field.field}.#{k}"] = v
end
end
end
end

Expand Down
37 changes: 35 additions & 2 deletions spec/lib/blacklight/solr_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,45 @@ def params
end
end

describe "Allow passing :sort when defining facet" do
describe "#add_solr_fields_to_query" do
let(:blacklight_config) do
config = Blacklight::Configuration.new do |config|

config.add_index_field 'an_index_field', solr_params: { 'hl.alternativeField' => 'field_x'}
config.add_show_field 'a_show_field', solr_params: { 'hl.alternativeField' => 'field_y'}
config.add_field_configuration_to_solr_request!
end
end

subject do
solr_parameters = Blacklight::Solr::Request.new

add_solr_fields_to_query(solr_parameters, {})

solr_parameters
end

it "should add any extra solr parameters from index and show fields" do
expect(subject[:'f.an_index_field.hl.alternativeField']).to eq "field_x"
expect(subject[:'f.a_show_field.hl.alternativeField']).to eq "field_y"
end
end

describe "#add_facetting_to_solr" do

let(:blacklight_config) do
config = Blacklight::Configuration.new

config.add_facet_field 'test_field', :sort => 'count'
config.add_facet_field 'some-query', :query => {'x' => {:fq => 'some:query' }}, :ex => 'xyz'
config.add_facet_field 'some-pivot', :pivot => ['a','b'], :ex => 'xyz'
config.add_facet_field 'some-field', solr_params: { 'facet.mincount' => 15 }
config.add_facet_fields_to_solr_request!

config
end

it "should return the correct solr parameters" do
it "should add sort parameters" do

solr_parameters = Blacklight::Solr::Request.new

Expand All @@ -296,6 +321,14 @@ def params
expect(solr_parameters[:'facet.query']).to include('{!ex=xyz}some:query')
expect(solr_parameters[:'facet.pivot']).to include('{!ex=xyz}a,b')
end

it "should add any additional solr_params" do
solr_parameters = Blacklight::Solr::Request.new

add_facetting_to_solr(solr_parameters, {})

expect(solr_parameters[:'f.some-field.facet.mincount']).to eq 15
end
end

describe "with a complex parameter environment" do
Expand Down

0 comments on commit 5f933c4

Please sign in to comment.