diff --git a/plugins/pg_search/lib/ext/active_record.rb b/plugins/pg_search/lib/ext/active_record.rb index d9db874..89b9a4d 100644 --- a/plugins/pg_search/lib/ext/active_record.rb +++ b/plugins/pg_search/lib/ext/active_record.rb @@ -2,8 +2,11 @@ require_dependency 'active_record' class ActiveRecord::Base def self.pg_search_plugin_search(query) + query.gsub!(/\|/,' ') + formatted_query = query.split.map{|w| w += ":*"}.join('|') + if defined?(self::SEARCHABLE_FIELDS) - where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{query}:*')") + where("to_tsvector('simple', #{pg_search_plugin_fields}) @@ to_tsquery('#{formatted_query}')") else raise "No searchable fields defined for #{self.name}" end diff --git a/plugins/pg_search/test/unit/pg_search_plugin_test.rb b/plugins/pg_search/test/unit/pg_search_plugin_test.rb index 8727458..f6017fc 100644 --- a/plugins/pg_search/test/unit/pg_search_plugin_test.rb +++ b/plugins/pg_search/test/unit/pg_search_plugin_test.rb @@ -14,6 +14,13 @@ class PgSearchPluginTest < ActiveSupport::TestCase assert_includes search(Profile, 'water'), profile end + should 'locate one or more profiles' do + profile1 = fast_create(Profile, :identifier => 'administrator') + profile2 = fast_create(Profile, :identifier => 'debugger') + assert_includes search(Profile, 'admin deb'), profile1 + assert_includes search(Profile, 'admin deb'), profile2 + end + # TODO This feature is available only on Postgresql 9.0 # http://www.postgresql.org/docs/9.0/static/unaccent.html # should 'ignore accents' do -- libgit2 0.21.2