Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 4 commits into from

3 participants

@floere
Owner

This is a small rewrite to the full text search

pod search <query>

which makes it possible to use regular expressions.

It also slightly lowers memory usage, because it avoids using temporary strings. Instead, it uses an Array of existing strings.

I've added only a single spec which shows off the capability. Please let me know if you need more examples.

@alloy

grep ftw! :)

Owner

I know right! ;)

Btw, this deserves a mention in the changelog. If I'm correct regular expressions should work directly from the command line!

Owner

@irrationalfab Ok – @alloy also asked me to add a mention. Cheers!

@alloy
Owner

Excellent!

Can you add a CHANGELOG entry crediting yourself?

@fabiopelosin
Owner

:+1:

@floere
Owner

I added a CHANGELOG entry :)

@alloy
Owner

:heart:

@alloy alloy merged commit 1404110 into from
@fabiopelosin fabiopelosin deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
7 CHANGELOG.md
@@ -19,7 +19,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
View
11 lib/cocoapods/sources_manager.rb
@@ -61,14 +61,15 @@ def search(dependency)
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
View
7 spec/unit/sources_manager_spec.rb
@@ -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])
Something went wrong with that request. Please try again.