returning nothing on empty query and limit the returning of the query to 90
This commit is contained in:
parent
9d98afb94f
commit
ebaf2c081e
2 changed files with 9 additions and 4 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue