Skip to content

Commit

Permalink
return an empty result set instead of throwing exception when the use…
Browse files Browse the repository at this point in the history
…r requests a custom facet query value that does not exist (fixes #1255)
  • Loading branch information
peetucket committed Oct 7, 2015
1 parent 6e2b36f commit c119f0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/blacklight/solr/search_builder_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,12 @@ def facet_value_to_fq_string(facet_field, value)

case
when (facet_config and facet_config.query)
facet_config.query[value][:fq]
if facet_config.query[value]
facet_config.query[value][:fq]
else
# exclude all documents if the custom facet key specified was not found
'-*:*'
end
when (facet_config and facet_config.date)
# in solr 3.2+, this could be replaced by a !term query
"#{prefix}#{solr_field}:#{RSolr.solr_escape(value)}"
Expand Down
12 changes: 12 additions & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,19 @@ def assigns_response
expect(facet.items).to be_empty
end
end

it "should show 0 results when the user asks for an invalid value to a custom facet query", :integration => true do
get :index, f: {example_query_facet_field: 'bogus'} # bogus custom facet value
expect(assigns_response.docs).to be_empty
end

it "should return results (possibly 0) when the user asks for a valid value to a custom facet query", :integration => true do
get :index, f: {example_query_facet_field: 'years_10'} # valid custom facet value with some results
expect(assigns_response.docs).to_not be_empty
get :index, f: {example_query_facet_field: 'years_5'} # valid custom facet value with NO results
expect(assigns_response.docs).to be_empty
end

it "should have a spelling suggestion for an appropriately poor query", :integration => true do
get :index, :q => 'boo'
expect(assigns_response.spelling.words).to_not be_nil
Expand Down

0 comments on commit c119f0c

Please sign in to comment.