aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Longair <mhl@pobox.com>2013-11-07 17:54:06 +0000
committerMark Longair <mhl@pobox.com>2013-11-07 17:54:06 +0000
commit5d6d7571c7c49115609bbf0b5142ae9630cfafa0 (patch)
tree895c2b940cf878d92f402261f01ce1c77feae31a
parent0d6c60edf025ef86d8ca74f9e10fca7e08951a90 (diff)
parent6524c746c31a7e6243249bcbe88c1a58f2088208 (diff)
Merge branch 'feature/1118-fix-ask-us-to-add-links' into rails-3-develop
-rw-r--r--app/controllers/general_controller.rb11
-rw-r--r--app/views/general/search.html.erb10
-rw-r--r--app/views/public_body/_search_ahead.html.erb4
-rw-r--r--spec/controllers/general_controller_spec.rb16
4 files changed, 28 insertions, 13 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..18f258444 100644
--- a/app/views/general/search.html.erb
+++ b/app/views/general/search.html.erb
@@ -116,7 +116,7 @@
<% end # if @advanced %>
- <% if !@query.nil? %>
+ <% if !@query.nil? && @total_hits > 0 %>
<p id="search_controls">
<%=link_to_unless @sortby == 'relevant', _("Show most relevant results first"), search_path([params[:query], @variety_postfix, 'relevant'], params) %>
|
@@ -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? %>
@@ -155,10 +158,7 @@
</div>
<%= 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 %>
+ <% elsif @variety_postfix == 'bodies' %>
<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/app/views/public_body/_search_ahead.html.erb b/app/views/public_body/_search_ahead.html.erb
index 3d1dc8f93..2de638034 100644
--- a/app/views/public_body/_search_ahead.html.erb
+++ b/app/views/public_body/_search_ahead.html.erb
@@ -14,7 +14,5 @@
<% end %>
</div>
<%= will_paginate WillPaginate::Collection.new(@page, @per_page, @xapian_requests.matches_estimated), :params => {:controller=>"request", :action => "select_authority"} %>
+ <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 %>
-
-
-
diff --git a/spec/controllers/general_controller_spec.rb b/spec/controllers/general_controller_spec.rb
index 8c86ad0be..593d51683 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 =~ [
@@ -238,6 +249,11 @@ describe GeneralController, 'when using xapian search' do
assigns[:xapian_bodies].results.map{|x|x[:model]}.should == [public_bodies(:geraldine_public_body)]
end
+ it 'should show "Browse all" link if there are no results for a search restricted to bodies' do
+ get :search, :combined => "noresultsshouldbefound/bodies"
+ response.body.should include('Browse all')
+ end
+
it "should show help when searching for nothing" do
get :search_redirect, :query => nil
response.should render_template('search')