From ebaf2c081e3930f08bdf5b50a0821b337cae70c3 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Tue, 23 Nov 2010 10:02:01 -0800 Subject: [PATCH] returning nothing on empty query and limit the returning of the query to 90 --- app/models/person.rb | 8 ++++---- spec/models/person_spec.rb | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models/person.rb b/app/models/person.rb index 62cc5759b..f0da52941 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -50,7 +50,7 @@ class Person attr_accessible :profile def self.search(query) - return Person.searchable.all if query.to_s.empty? + return [] if query.to_s.empty? query_tokens = query.to_s.strip.split(" ") full_query_text = Regexp.escape(query.to_s.strip) @@ -58,9 +58,9 @@ class Person query_tokens.each do |token| q = Regexp.escape(token.to_s.strip) - p = Person.searchable.all('profile.first_name' => /^#{q}/i) \ - | Person.searchable.all('profile.last_name' => /^#{q}/i) \ - | Person.searchable.all('diaspora_handle' => /^#{q}/i) \ + p = Person.searchable.all('profile.first_name' => /^#{q}/i, 'limit' => 30) \ + | Person.searchable.all('profile.last_name' => /^#{q}/i, 'limit' => 30) \ + | Person.searchable.all('diaspora_handle' => /^#{q}/i, 'limit' => 30) \ | p end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index d7aa61fb9..061c78ace 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -164,6 +164,11 @@ describe Person do @connected_person_four.save end + it 'should return nothing on an emprty query' do + people = Person.search("") + people.empty?.should be true + end + it 'should yield search results on partial names' do people = Person.search("Eu") people.include?(@connected_person_two).should == true