From 9f1fe3ca49298c5ea52cd6ebb7c2e518d45e7718 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 21 Dec 2011 13:33:18 +0000 Subject: Don't do wildcard searches for partial matches in type ahead searches. Fixes #310. --- app/controllers/request_controller.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 1801648ca..d91df3780 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -754,11 +754,14 @@ class RequestController < ApplicationController def search_typeahead # Since acts_as_xapian doesn't support the Partial match flag, we work around it # by making the last work a wildcard, which is quite the same - query = params[:q] + '*' - - query = query.split(' ').join(' OR ') # XXX: HACK for OR instead of default AND! - @xapian_requests = perform_search([InfoRequestEvent], query, 'relevant', 'request_collapse', 5) - + query = params[:q] + query = query.split(' ') + if query.last.nil? || query.last.strip.length < 3 + @xapian_requests = nil + else + query = query.join(' OR ') # XXX: HACK for OR instead of default AND! + @xapian_requests = perform_search([InfoRequestEvent], query, 'relevant', 'request_collapse', 5) + end render :partial => "request/search_ahead.rhtml" end -- cgit v1.2.3