Commit 14041109 authored by Eloy Durán's avatar Eloy Durán

Merge pull request #1643 from CocoaPods/regexp-search

Add regexp search capabilities to full text search and lower memory usage.
parents d01b8e5f 57608162
......@@ -23,7 +23,12 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
* Add Bazaar support for installing directly from a repo.
[Fred McCann](https://github.com/fmccann)
[#1632](https://github.com/CocoaPods/CocoaPods/pull/1632)
[#1632](https://github.com/CocoaPods/CocoaPods/pull/1632)
* The `pod search <query>` command now supports regular expressions
for the query parameter when searching using the option `--full`.
[Florian Hanke](https://github.com/floere)
[#1643][https://github.com/CocoaPods/CocoaPods/pull/1643]
###### Bug Fixes
......
......@@ -61,14 +61,15 @@ module Pod
def search_by_name(query, full_text_search = false)
if full_text_search
set_names = []
query_regexp = /#{query}/i
updated_search_index.each do |name, set_data|
text = name.dup
texts = [name]
if full_text_search
text << set_data['authors'].to_s if set_data['authors']
text << set_data['summary'] if set_data['summary']
text << set_data['description'] if set_data['description']
texts << set_data['authors'].to_s if set_data['authors']
texts << set_data['summary'] if set_data['summary']
texts << set_data['description'] if set_data['description']
end
set_names << name if text.downcase.include?(query.downcase)
set_names << name unless texts.grep(query_regexp).empty?
end
sets = set_names.sort.map { |name| aggregate.represenative_set(name) }
else
......
......@@ -49,6 +49,13 @@ module Pod
sets.all?{ |s| s.class == Specification::Set}.should.be.true
sets.any?{ |s| s.name == 'BananaLib'}.should.be.true
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
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