From 8aa8a88d938173dd3aa382d33c48d7e6063f1844 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 24 Aug 2011 16:48:55 +0100 Subject: more work in progress on search forms --- app/controllers/general_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 4fa603aab..e9325c3c5 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -82,9 +82,12 @@ class GeneralController < ApplicationController # Just does a redirect from ?query= search to /query def search_redirect - @query = params[:query] + @query = alter_query_from_params @sortby = params[:sortby] @bodies = params[:bodies] + [:latest_status, :request_variety, :request_date_after, :request_date_before, :query].each do |x| + session[x] = params[x] + end if @query.nil? || @query.empty? @query = nil @page = 1 @@ -103,6 +106,9 @@ class GeneralController < ApplicationController def search # XXX Why is this so complicated with arrays and stuff? Look at the route # in config/routes.rb for comments. + [:latest_status, :request_variety, :request_date_after, :request_date_before, :query].each do |x| + params[x] = session[x] + end combined = params[:combined] @sortby = nil @bodies = false # searching from front page, largely for a public authority -- cgit v1.2.3 From 0c321987194b3ef089e32f61cdac351d6b44e8c4 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 26 Aug 2011 09:48:01 +0100 Subject: Further work in progress on better search functionality --- app/controllers/general_controller.rb | 114 +++++++++++++++++++++++++--------- 1 file changed, 84 insertions(+), 30 deletions(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index e9325c3c5..2d0527d3a 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -82,23 +82,34 @@ class GeneralController < ApplicationController # Just does a redirect from ?query= search to /query def search_redirect - @query = alter_query_from_params + if params[:advanced].nil? + @query, _ = make_query_from_params + else + @query, _ = params[:query] + end @sortby = params[:sortby] - @bodies = params[:bodies] - [:latest_status, :request_variety, :request_date_after, :request_date_before, :query].each do |x| + path = request.path.split("/") + if path.size > 0 && (['newest', 'described', 'relevant'].include?(path[-1])) + @sort_postfix = path.pop + end + if path.size > 0 && (['bodies', 'requests', 'users', 'all'].include?(path[-1])) + @variety_postfix = path.pop + end + @variety_postfix = params[:bodies] if @variety_postfix.nil? && !params[:bodies].nil? + @variety_postfix = "all" if @variety_postfix.nil? + if @variety_postfix != "users" + @common_query = get_tags_from_params + end + [:latest_status, :request_variety, :request_date_after, :request_date_before, :query, :tags].each do |x| session[x] = params[x] end if @query.nil? || @query.empty? @query = nil @page = 1 + @advanced = !params[:advanced].nil? render :action => "search" else - if (@bodies == '1') && (@sortby.nil? || @sortby.empty?) - @postfix = 'bodies' - else - @postfix = @sortby - end - redirect_to search_url(@query, @postfix) + redirect_to search_url(@query, @variety_postfix, @sort_postfix, params[:advanced]) end end @@ -106,26 +117,49 @@ class GeneralController < ApplicationController def search # XXX Why is this so complicated with arrays and stuff? Look at the route # in config/routes.rb for comments. - [:latest_status, :request_variety, :request_date_after, :request_date_before, :query].each do |x| + if !params[:commit].nil? + search_redirect + return + end + [:latest_status, :request_variety, :request_date_after, :request_date_before, :query, :tags].each do |x| params[x] = session[x] end combined = params[:combined] @sortby = nil - @bodies = false # searching from front page, largely for a public authority + @bodies = @requests = @users = true + if combined.size > 0 && (['advanced'].include?(combined[-1])) + combined.pop + @advanced = true + else + @advanced = false + end # XXX currently /described isn't linked to anywhere, just used in RSS and for /list/successful # This is because it's confusingly different from /newest - but still useful for power users. - if combined.size > 1 && (['newest', 'described', 'bodies', 'relevant'].include?(combined[-1])) - @postfix = combined[-1] - combined = combined[0..-2] - if @postfix == 'bodies' + if combined.size > 0 && (['newest', 'described', 'relevant'].include?(combined[-1])) + @sort_postfix = combined.pop + @sortby = @sort_postfix + end + + if combined.size > 0 && (['bodies', 'requests', 'users', 'all'].include?(combined[-1])) + @variety_postfix = combined.pop + case @variety_postfix + when 'bodies' @bodies = true - else - @sortby = @postfix + @requests = false + @users = false + when 'requests' + @bodies = false + @requests = true + @users = false + when 'users' + @bodies = false + @requests = false + @users = true end end @query = combined.join("/") - @inputted_sortby = @sortby + @common_query = get_tags_from_params if @sortby.nil? # Parse query, so can work out if it has prefix terms only - if so then it is a # structured query which should show newest first, rather than a free text search @@ -151,21 +185,41 @@ class GeneralController < ApplicationController if params[:requests_per_page] requests_per_page = params[:requests_per_page].to_i end - @xapian_requests = perform_search([InfoRequestEvent], @query, @sortby, 'request_collapse', requests_per_page) - @requests_per_page = @per_page - @xapian_bodies = perform_search([PublicBody], @query, @sortby, nil, 5) - @bodies_per_page = @per_page - @xapian_users = perform_search([User], @query, @sortby, nil, 5) - @users_per_page = @per_page - - @this_page_hits = @xapian_requests.results.size + @xapian_bodies.results.size + @xapian_users.results.size - @total_hits = @xapian_requests.matches_estimated + @xapian_bodies.matches_estimated + @xapian_users.matches_estimated + @this_page_hits = @total_hits = @xapian_requests_hits = @xapian_bodies_hits = @xapian_users_hits = 0 + if @requests + @xapian_requests = perform_search([InfoRequestEvent], @query, @sortby, 'request_collapse', requests_per_page) + @requests_per_page = @per_page + @this_page_hits += @xapian_requests.results.size + @xapian_requests_hits = @xapian_requests.results.size + @xapian_requests_total_hits = @xapian_requests.matches_estimated + @total_hits += @xapian_requests.matches_estimated + end + if @bodies + @xapian_bodies = perform_search([PublicBody], @query, @sortby, nil, 5) + @bodies_per_page = @per_page + @this_page_hits += @xapian_bodies.results.size + @xapian_bodies_hits = @xapian_bodies.results.size + @xapian_bodies_total_hits = @xapian_bodies.matches_estimated + @total_hits += @xapian_bodies.matches_estimated + end + if @users + @xapian_users = perform_search([User], @query, @sortby, nil, 5) + @users_per_page = @per_page + @this_page_hits += @xapian_users.results.size + @xapian_users_hits = @xapian_users.results.size + @xapian_users_total_hits = @xapian_users.matches_estimated + @total_hits += @xapian_users.matches_estimated + end # Spelling and highight words are same for all three queries - @spelling_correction = @xapian_requests.spelling_correction - @highlight_words = @xapian_requests.words_to_highlight + 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 + end - @track_thing = TrackThing.create_track_for_search_query(@query) + @track_thing = TrackThing.create_track_for_search_query(@query, @variety_postfix) @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ] end -- cgit v1.2.3 From 6032be3fadc6056c7171a492ba456b4374d0a966 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 30 Aug 2011 18:08:08 +0100 Subject: remove redundant config and code relating to front page search examples (relates to issue #153) --- app/controllers/general_controller.rb | 4 ---- 1 file changed, 4 deletions(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 2d0527d3a..1ddf3acff 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -45,10 +45,6 @@ class GeneralController < ApplicationController :joins => :translations) end end - @search_examples = MySociety::Config.get('FRONTPAGE_SEARCH_EXAMPLES', '').split(/\s*;\s*/) - if @search_examples.empty? - @search_examples = @popular_bodies.map { |body| body.name } - end # Get some successful requests # begin query = 'variety:response (status:successful OR status:partially_successful)' -- cgit v1.2.3 From 7833dfbf9833f6fd42b05c36d308d016ae614be2 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 1 Sep 2011 12:54:30 +0100 Subject: final set of fixes to get tests to pass, post-new-design --- app/controllers/general_controller.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 1ddf3acff..004136163 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -50,11 +50,18 @@ class GeneralController < ApplicationController query = 'variety:response (status:successful OR status:partially_successful)' # query = 'variety:response' # XXX debug sortby = "described" - xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_title_collapse', 8) - @successful_request_events = xapian_object.results.map { |r| r[:model] } - @successful_request_events = @successful_request_events.sort_by { |e| e.described_at }.reverse + max_count = 5 + xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_title_collapse', max_count) + @request_events = xapian_object.results.map { |r| r[:model] } + @request_events = @request_events.sort_by { |e| e.described_at }.reverse + if @request_events.count < max_count + query = 'variety:sent' + xapian_object = perform_search([InfoRequestEvent], query, sortby, 'request_title_collapse', max_count-@request_events.count) + more_events = xapian_object.results.map { |r| r[:model] } + @request_events += more_events.sort_by { |e| e.described_at }.reverse + end rescue - @successful_request_events = [] + @request_events = [] end end end -- cgit v1.2.3 From 21495a7361c275040d22bb88a70186253d20853a Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 1 Sep 2011 13:45:18 +0100 Subject: Make the general search return requests only, by default --- app/controllers/general_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 004136163..73c8407fd 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -99,7 +99,7 @@ class GeneralController < ApplicationController @variety_postfix = path.pop end @variety_postfix = params[:bodies] if @variety_postfix.nil? && !params[:bodies].nil? - @variety_postfix = "all" if @variety_postfix.nil? + @variety_postfix = "requests" if @variety_postfix.nil? if @variety_postfix != "users" @common_query = get_tags_from_params end -- cgit v1.2.3 From fc70bdf0099613ddc2112538bf8c7614fc82431a Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 1 Sep 2011 13:53:00 +0100 Subject: Ensure we show the "request" search view by default --- app/controllers/general_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 73c8407fd..6b4683881 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -142,7 +142,9 @@ class GeneralController < ApplicationController @sort_postfix = combined.pop @sortby = @sort_postfix end - + if !params[:view].nil? + combined += [params[:view]] + end if combined.size > 0 && (['bodies', 'requests', 'users', 'all'].include?(combined[-1])) @variety_postfix = combined.pop case @variety_postfix -- cgit v1.2.3 From a79be3df0fddf2763376033cf731f0efbc915fcf Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Sat, 3 Sep 2011 09:02:42 +0100 Subject: Show the right thing in the UI (i.e. the query, and "all" filter) to users for a search URL like "/search/dog" --- app/controllers/general_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 6b4683881..ada891ce9 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -161,8 +161,13 @@ class GeneralController < ApplicationController @requests = false @users = true end + else + @variety_postfix = "all" end @query = combined.join("/") + if params[:query].nil? + params[:query] = @query + end @inputted_sortby = @sortby @common_query = get_tags_from_params if @sortby.nil? -- cgit v1.2.3 From 1def714bd60164afe10b0b9d83b87fec27d9617c Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 15 Sep 2011 11:48:08 +0100 Subject: Ensure we search public bodies only when special hidden form field is passed in --- app/controllers/general_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index ada891ce9..cefc3c020 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -98,7 +98,7 @@ class GeneralController < ApplicationController if path.size > 0 && (['bodies', 'requests', 'users', 'all'].include?(path[-1])) @variety_postfix = path.pop end - @variety_postfix = params[:bodies] if @variety_postfix.nil? && !params[:bodies].nil? + @variety_postfix = "bodies" if @variety_postfix.nil? && !params[:bodies].nil? @variety_postfix = "requests" if @variety_postfix.nil? if @variety_postfix != "users" @common_query = get_tags_from_params -- cgit v1.2.3 From c13c5a717ad2ede8f51cc90c66daf8f573bf2ea4 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 16 Sep 2011 09:26:34 +0100 Subject: Preserve search text when flipping between result types. Fixes #187. --- app/controllers/general_controller.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index cefc3c020..55abea3b7 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -125,7 +125,7 @@ class GeneralController < ApplicationController return end [:latest_status, :request_variety, :request_date_after, :request_date_before, :query, :tags].each do |x| - params[x] = session[x] + params[x] = session[x] if params[x].nil? end combined = params[:combined] @sortby = nil @@ -160,14 +160,17 @@ class GeneralController < ApplicationController @bodies = false @requests = false @users = true + else + @variety_postfix = "all" end - else - @variety_postfix = "all" end @query = combined.join("/") if params[:query].nil? params[:query] = @query end + if @variety_postfix != "all" && @requests + @query, _ = make_query_from_params + end @inputted_sortby = @sortby @common_query = get_tags_from_params if @sortby.nil? -- cgit v1.2.3 From a4b7dd4fc7eb766752213bd6fb5243d9a340e7e5 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Mon, 26 Sep 2011 13:51:56 +0200 Subject: Add locale parameter to blog URL when fetching posts. Fixes #197 --- app/controllers/general_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 55abea3b7..0bd9ac87a 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -70,13 +70,13 @@ class GeneralController < ApplicationController def blog medium_cache @feed_autodetect = [] - feed_url = MySociety::Config.get('BLOG_FEED', '') + @feed_url = "#{MySociety::Config.get('BLOG_FEED', '')}?lang=#{self.locale_from_params()}" if not feed_url.empty? - content = open(feed_url).read + content = open(@feed_url).read @data = XmlSimple.xml_in(content) @channel = @data['channel'][0] @blog_items = @channel['item'] - @feed_autodetect = [{:url => feed_url, :title => "#{site_name} blog"}] + @feed_autodetect = [{:url => @feed_url, :title => "#{site_name} blog"}] else @blog_items = [] end -- cgit v1.2.3 From 30c2435b2d5f7895774a2e479cec9c82583991f4 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Tue, 27 Sep 2011 12:50:37 +0200 Subject: Fix wrong variable name, fixes #197 --- app/controllers/general_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/general_controller.rb') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 0bd9ac87a..194a1cec0 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -71,7 +71,7 @@ class GeneralController < ApplicationController medium_cache @feed_autodetect = [] @feed_url = "#{MySociety::Config.get('BLOG_FEED', '')}?lang=#{self.locale_from_params()}" - if not feed_url.empty? + if not @feed_url.empty? content = open(@feed_url).read @data = XmlSimple.xml_in(content) @channel = @data['channel'][0] -- cgit v1.2.3