From 45fc8c3e18dc5e43e98fc1fae5b519f1440086ea 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/public_body_controller.rb | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'app/controllers/public_body_controller.rb') diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index 05acf4868..cb27e78f0 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -16,7 +16,6 @@ class PublicBodyController < ApplicationController redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name], 'body'), :status => :moved_permanently return end - @locale = self.locale_from_params() PublicBody.with_locale(@locale) do @public_body = PublicBody.find_by_url_name_with_historic(params[:url_name]) @@ -39,11 +38,15 @@ class PublicBodyController < ApplicationController if !referrer.nil? && referrer.match(%r{^#{top_url}search/.*/bodies$}) @searched_to_send_request = true end - + query, sortby = alter_query_from_params + if !query.empty? + query = "(#{query})" + end + query += "requested_from:#{@public_body.url_name}" # Use search query for this so can collapse and paginate easily # XXX really should just use SQL query here rather than Xapian. begin - @xapian_requests = perform_search([InfoRequestEvent], 'requested_from:' + @public_body.url_name, 'newest', 'request_collapse') + @xapian_requests = perform_search([InfoRequestEvent], query, sortby, 'request_collapse') if (@page > 1) @page_desc = " (page " + @page.to_s + ")" else @@ -83,29 +86,35 @@ class PublicBodyController < ApplicationController def list long_cache # XXX move some of these tag SQL queries into has_tag_string.rb + if params[:commit] != _('Show all') + @query = "%#{params[:public_body_query].nil? ? "" : params[:public_body_query]}%" + else + redirect_to list_public_bodies_url(:tag => "all") + return + end @tag = params[:tag] @locale = self.locale_from_params() - locale_condition = 'public_body_translations.locale = ?' - if @tag.nil? + locale_condition = "upper(public_body_translations.name) LIKE upper(?) AND public_body_translations.locale = ?" + if @tag.nil? or @tag == "all" @tag = "all" - conditions = [locale_condition, @locale] + conditions = [locale_condition, @query, @locale] elsif @tag == 'other' category_list = PublicBodyCategories::CATEGORIES.map{|c| "'"+c+"'"}.join(",") conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name in (' + category_list + ')) = 0', @locale] + and has_tag_string_tags.name in (' + category_list + ')) = 0', @query, @locale] elsif @tag.size == 1 @tag.upcase! - conditions = [locale_condition + ' AND public_body_translations.first_letter = ?', @locale, @tag] + conditions = [locale_condition + ' AND public_body_translations.first_letter = ?', @query, @locale, @tag] elsif @tag.include?(":") name, value = HasTagString::HasTagStringTag.split_tag_into_name_value(@tag) conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name = ? and has_tag_string_tags.value = ?) > 0', @locale, name, value] + and has_tag_string_tags.name = ? and has_tag_string_tags.value = ?) > 0', @query, @locale, name, value] else conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name = ?) > 0', @locale, @tag] + and has_tag_string_tags.name = ?) > 0', @query, @locale, @tag] end if @tag.size == 1 @description = _("beginning with") + " '" + @tag + "'" -- cgit v1.2.3 From 5f0c0d59ded4301efa085c4103b84a42a9fa61f6 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/public_body_controller.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'app/controllers/public_body_controller.rb') diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index cb27e78f0..d7d8c2c56 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -38,13 +38,14 @@ class PublicBodyController < ApplicationController if !referrer.nil? && referrer.match(%r{^#{top_url}search/.*/bodies$}) @searched_to_send_request = true end - query, sortby = alter_query_from_params - if !query.empty? - query = "(#{query})" - end - query += "requested_from:#{@public_body.url_name}" + @view = params[:view] + params[:latest_status] = @view + + query = make_query_from_params + query += " requested_from:#{@public_body.url_name}" # Use search query for this so can collapse and paginate easily # XXX really should just use SQL query here rather than Xapian. + sortby = "described" begin @xapian_requests = perform_search([InfoRequestEvent], query, sortby, 'request_collapse') if (@page > 1) @@ -86,12 +87,7 @@ class PublicBodyController < ApplicationController def list long_cache # XXX move some of these tag SQL queries into has_tag_string.rb - if params[:commit] != _('Show all') - @query = "%#{params[:public_body_query].nil? ? "" : params[:public_body_query]}%" - else - redirect_to list_public_bodies_url(:tag => "all") - return - end + @query = "%#{params[:public_body_query].nil? ? "" : params[:public_body_query]}%" @tag = params[:tag] @locale = self.locale_from_params() locale_condition = "upper(public_body_translations.name) LIKE upper(?) AND public_body_translations.locale = ?" -- cgit v1.2.3 From b41edc7ae069e6071f7ff7223c1e60cca5e75e8c Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Mon, 29 Aug 2011 13:13:59 +0100 Subject: Add tests & fixes for new search/filtering functionality --- app/controllers/public_body_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'app/controllers/public_body_controller.rb') diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index d7d8c2c56..830f37855 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -90,27 +90,27 @@ class PublicBodyController < ApplicationController @query = "%#{params[:public_body_query].nil? ? "" : params[:public_body_query]}%" @tag = params[:tag] @locale = self.locale_from_params() - locale_condition = "upper(public_body_translations.name) LIKE upper(?) AND public_body_translations.locale = ?" + locale_condition = "(upper(public_body_translations.name) LIKE upper(?) OR upper(public_body_translations.notes) LIKE upper (?)) AND public_body_translations.locale = ?" if @tag.nil? or @tag == "all" @tag = "all" - conditions = [locale_condition, @query, @locale] + conditions = [locale_condition, @query, @query, @locale] elsif @tag == 'other' category_list = PublicBodyCategories::CATEGORIES.map{|c| "'"+c+"'"}.join(",") conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name in (' + category_list + ')) = 0', @query, @locale] + and has_tag_string_tags.name in (' + category_list + ')) = 0', @query, @query, @locale] elsif @tag.size == 1 @tag.upcase! - conditions = [locale_condition + ' AND public_body_translations.first_letter = ?', @query, @locale, @tag] + conditions = [locale_condition + ' AND public_body_translations.first_letter = ?', @query, @query, @locale, @tag] elsif @tag.include?(":") name, value = HasTagString::HasTagStringTag.split_tag_into_name_value(@tag) conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name = ? and has_tag_string_tags.value = ?) > 0', @query, @locale, name, value] + and has_tag_string_tags.name = ? and has_tag_string_tags.value = ?) > 0', @query, @query, @locale, name, value] else conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name = ?) > 0', @query, @locale, @tag] + and has_tag_string_tags.name = ?) > 0', @query, @query, @locale, @tag] end if @tag.size == 1 @description = _("beginning with") + " '" + @tag + "'" -- cgit v1.2.3