aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/general_controller.rb11
-rw-r--r--app/views/general/search.html.erb6
-rw-r--r--spec/controllers/general_controller_spec.rb11
3 files changed, 20 insertions, 8 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index 540f67ec9..beefef4e6 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -178,6 +178,7 @@ class GeneralController < ApplicationController
@xapian_requests_hits = @xapian_requests.results.size
@xapian_requests_total_hits = @xapian_requests.matches_estimated
@total_hits += @xapian_requests.matches_estimated
+ @request_for_spelling = @xapian_requests
end
if @bodies
@xapian_bodies = perform_search([PublicBody], @query, @sortby, nil, 5)
@@ -186,6 +187,7 @@ class GeneralController < ApplicationController
@xapian_bodies_hits = @xapian_bodies.results.size
@xapian_bodies_total_hits = @xapian_bodies.matches_estimated
@total_hits += @xapian_bodies.matches_estimated
+ @request_for_spelling = @xapian_bodies
end
if @users
@xapian_users = perform_search([User], @query, @sortby, nil, 5)
@@ -194,14 +196,13 @@ class GeneralController < ApplicationController
@xapian_users_hits = @xapian_users.results.size
@xapian_users_total_hits = @xapian_users.matches_estimated
@total_hits += @xapian_users.matches_estimated
+ @request_for_spelling = @xapian_users
end
# Spelling and highight words are same for all three queries
- if !@xapian_requests.nil?
- @highlight_words = @xapian_requests.words_to_highlight
- if !(@xapian_requests.spelling_correction =~ /[a-z]+:/)
- @spelling_correction = @xapian_requests.spelling_correction
- end
+ @highlight_words = @request_for_spelling.words_to_highlight
+ if !(@request_for_spelling.spelling_correction =~ /[a-z]+:/)
+ @spelling_correction = @request_for_spelling.spelling_correction
end
@track_thing = TrackThing.create_track_for_search_query(@query, @variety_postfix)
diff --git a/app/views/general/search.html.erb b/app/views/general/search.html.erb
index d526a93c0..be8f2ed86 100644
--- a/app/views/general/search.html.erb
+++ b/app/views/general/search.html.erb
@@ -137,6 +137,9 @@
<div style="clear:both;"></div>
<% if @total_hits == 0 %>
<h2><%=@title %></h2>
+ <% if @spelling_correction %>
+ <p id="did_you_mean"><%= _('Did you mean: {{correction}}', :correction => search_link(@spelling_correction)) %></p>
+ <% end %>
<% end %>
<% if not @query.nil? %>
@@ -156,9 +159,6 @@
<%= will_paginate WillPaginate::Collection.new(@page, @bodies_per_page, @xapian_bodies.matches_estimated) %>
<% elsif @bodies && !@query.nil? && @xapian_bodies.results.size == 0 && @page == 1 %>
- <% if @spelling_correction %>
- <p id="did_you_mean"><%= _('Did you mean: {{correction}}', :correction => search_link(@spelling_correction)) %></p>
- <% end %>
<p><%= raw(_('<a href="{{browse_url}}">Browse all</a> or <a href="{{add_url}}">ask us to add one</a>.', :browse_url => list_public_bodies_default_path.html_safe, :add_url => (help_requesting_path + '#missing_body').html_safe)) %></p>
<% end %>
</div>
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 8c86ad0be..ecd403315 100644
--- a/spec/controllers/general_controller_spec.rb
+++ b/spec/controllers/general_controller_spec.rb
@@ -219,6 +219,17 @@ describe GeneralController, 'when using xapian search' do
assigns[:xapian_bodies].should == nil
end
+ it 'should highlight words for a user-only request' do
+ get :search, :combined => "bob/users"
+ assigns[:highlight_words].should == ['bob']
+ end
+
+ it 'should show spelling corrections for a user-only request' do
+ get :search, :combined => "rob/users"
+ assigns[:spelling_correction].should == 'bob'
+ response.body.should include('did_you_mean')
+ end
+
it "should filter results based on end of URL being 'requests'" do
get :search, :combined => "bob/requests"
assigns[:xapian_requests].results.map{|x|x[:model]}.should =~ [