From 060d9fe70a1de0ba9aa592d25d6e7352114aa431 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 25 Mar 2013 16:17:03 +1100 Subject: Inline method InfoRequest.full_search --- app/controllers/application_controller.rb | 8 +++++++- app/controllers/user_controller.rb | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index df522519d..4f3624ab7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -378,7 +378,13 @@ class ApplicationController < ActionController::Base else @page = this_page end - result = InfoRequest.full_search(models, @query, order, ascending, collapse, @per_page, @page) + result = ActsAsXapian::Search.new(models, @query, + :offset => (@page - 1) * @per_page, + :limit => @per_page, + :sort_by_prefix => order, + :sort_by_ascending => ascending, + :collapse_by_prefix => collapse + ) result.results # Touch the results to load them, otherwise accessing them from the view # might fail later if the database has subsequently been reopened. return result diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 658daeeff..ed05b750b 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -119,7 +119,11 @@ class UserController < ApplicationController @track_things = TrackThing.find(:all, :conditions => ["tracking_user_id = ? and track_medium = ?", @display_user.id, 'email_daily'], :order => 'created_at desc') for track_thing in @track_things # XXX factor out of track_mailer.rb - xapian_object = InfoRequest.full_search([InfoRequestEvent], track_thing.track_query, 'described_at', true, nil, 20, 1) + xapian_object = ActsAsXapian::Search.new([InfoRequestEvent], track_thing.track_query, + :sort_by_prefix => 'described_at', + :sort_by_ascending => true, + :collapse_by_prefix => nil, + :limit => 20) feed_results += xapian_object.results.map {|x| x[:model]} end end -- cgit v1.2.3 From 1de7949b14f485772cfabf4f1713d423319bf678 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 25 Mar 2013 16:21:13 +1100 Subject: Tiny refactor --- app/controllers/general_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 6f79c50cb..83f890077 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -176,10 +176,8 @@ class GeneralController < ApplicationController # Query each type separately for separate display (XXX we are calling # perform_search multiple times and it clobbers per_page for each one, # so set as separate var) - requests_per_page = 25 - if params[:requests_per_page] - requests_per_page = params[:requests_per_page].to_i - end + requests_per_page = params[:requests_per_page] ? params[:requests_per_page].to_i : 25 + @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) -- cgit v1.2.3 From 7330ad14103642fb8c13707fe4ce61f67ab649cf Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 25 Mar 2013 16:22:06 +1100 Subject: ActsAsXapian doesn't need to be referenced from the global namespace --- app/controllers/general_controller.rb | 2 +- app/controllers/request_controller.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 83f890077..53cf58170 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -160,7 +160,7 @@ class GeneralController < ApplicationController # structured query which should show newest first, rather than a free text search # where we want most relevant as default. begin - dummy_query = ::ActsAsXapian::Search.new([InfoRequestEvent], @query, :limit => 1) + dummy_query = ActsAsXapian::Search.new([InfoRequestEvent], @query, :limit => 1) rescue => e flash[:error] = "Your query was not quite right. " + CGI.escapeHTML(e.to_str) redirect_to search_url("") diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index ad1918005..cad5d5597 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -101,7 +101,7 @@ class RequestController < ApplicationController # ... requests that have similar imporant terms begin limit = 10 - @xapian_similar = ::ActsAsXapian::Similar.new([InfoRequestEvent], @info_request.info_request_events, + @xapian_similar = ActsAsXapian::Similar.new([InfoRequestEvent], @info_request.info_request_events, :limit => limit, :collapse_by_prefix => 'request_collapse') @xapian_similar_more = (@xapian_similar.matches_estimated > limit) rescue @@ -149,7 +149,7 @@ class RequestController < ApplicationController render :template => 'request/hidden', :status => 410 # gone return end - @xapian_object = ::ActsAsXapian::Similar.new([InfoRequestEvent], @info_request.info_request_events, + @xapian_object = ActsAsXapian::Similar.new([InfoRequestEvent], @info_request.info_request_events, :offset => (@page - 1) * @per_page, :limit => @per_page, :collapse_by_prefix => 'request_collapse') @matches_estimated = @xapian_object.matches_estimated @show_no_more_than = (@matches_estimated > MAX_RESULTS) ? MAX_RESULTS : @matches_estimated -- cgit v1.2.3 From 9727c7b62fd3fe7b00cfc64cb4b36ba445a3a960 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 25 Mar 2013 16:28:14 +1100 Subject: Tiny refactor --- app/controllers/application_controller.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4f3624ab7..a2951bb42 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -373,11 +373,8 @@ class ApplicationController < ActionController::Base # Peform the search @per_page = per_page - if this_page.nil? - @page = get_search_page_from_params - else - @page = this_page - end + @page = this_page || get_search_page_from_params + result = ActsAsXapian::Search.new(models, @query, :offset => (@page - 1) * @per_page, :limit => @per_page, -- cgit v1.2.3