Commit 59c87ff3 authored by Florian R. Hanke's avatar Florian R. Hanke

Add regexp-search capabilities to full text search and lower memory usage.

parent 73d5a97a
...@@ -61,14 +61,15 @@ module Pod ...@@ -61,14 +61,15 @@ module Pod
def search_by_name(query, full_text_search = false) def search_by_name(query, full_text_search = false)
if full_text_search if full_text_search
set_names = [] set_names = []
query_regexp = %r{#{query}}i
updated_search_index.each do |name, set_data| updated_search_index.each do |name, set_data|
text = name.dup texts = [name]
if full_text_search if full_text_search
text << set_data['authors'].to_s if set_data['authors'] texts << set_data['authors'].to_s if set_data['authors']
text << set_data['summary'] if set_data['summary'] texts << set_data['summary'] if set_data['summary']
text << set_data['description'] if set_data['description'] texts << set_data['description'] if set_data['description']
end end
set_names << name if text.downcase.include?(query.downcase) set_names << name unless texts.grep(query_regexp).empty?
end end
sets = set_names.sort.map { |name| aggregate.represenative_set(name) } sets = set_names.sort.map { |name| aggregate.represenative_set(name) }
else else
......
...@@ -49,6 +49,13 @@ module Pod ...@@ -49,6 +49,13 @@ module Pod
sets.all?{ |s| s.class == Specification::Set}.should.be.true sets.all?{ |s| s.class == Specification::Set}.should.be.true
sets.any?{ |s| s.name == 'BananaLib'}.should.be.true sets.any?{ |s| s.name == 'BananaLib'}.should.be.true
end end
it "can perform a full text regexp search of the sets" do
Source::Aggregate.any_instance.stubs(:all).returns([@test_source])
sets = SourcesManager.search_by_name('Ch[aeiou]nky', true)
sets.all?{ |s| s.class == Specification::Set}.should.be.true
sets.any?{ |s| s.name == 'BananaLib'}.should.be.true
end
it "generates the search index before performing a search if it doesn't exits" do it "generates the search index before performing a search if it doesn't exits" do
Source::Aggregate.any_instance.stubs(:all).returns([@test_source]) Source::Aggregate.any_instance.stubs(:all).returns([@test_source])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment