Improve sorting algorithm for `pod search`

parent 67d29d0b
......@@ -14,6 +14,11 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[#4487](https://github.com/CocoaPods/CocoaPods/pull/4487)
* Improve `pod search` performance while using _`--full`_ flag
* Improve sorting algorithm for `pod search`.
[Muhammed Yavuz Nuzumlalı](https://github.com/manuyavuz)
[cocoapods-search#12](https://github.com/CocoaPods/cocoapods-search/issues/12)
* Improve `pod search` performance while using _`--full`_ flag.
[Muhammed Yavuz Nuzumlalı](https://github.com/manuyavuz)
[cocoapods-search#8](https://github.com/CocoaPods/cocoapods-search/issues/8)
......
......@@ -7,7 +7,7 @@ GIT
GIT
remote: https://github.com/CocoaPods/Core.git
revision: d66fcb7160f060198c3808eb2ff3f51edf212687
revision: ce26e1eb797a6ad1f1d94b0304a50c491bc41237
branch: master
specs:
cocoapods-core (0.39.0)
......@@ -49,7 +49,7 @@ GIT
GIT
remote: https://github.com/CocoaPods/cocoapods-search.git
revision: 4e7de92e477f47918d869a7c4819251633efca0d
revision: 1dd4aba6378678ca45e364e58f96196937fd297b
branch: master
specs:
cocoapods-search (0.1.0)
......
......@@ -113,8 +113,8 @@ module Pod
# @return [Array<Set>] The sets that contain the search term.
#
def search_by_name(query, full_text_search = false)
if full_text_search
query_word_regexps = query.split.map { |word| /#{word}/i }
if full_text_search
query_word_results_hash = {}
updated_search_index.each_value do |word_spec_hash|
word_spec_hash.each_pair do |word, spec_symbols|
......@@ -138,6 +138,23 @@ module Pod
raise Informative, "Unable to find a pod with name#{extra}" \
"matching `#{query}`"
end
# Sort sets
sets.sort_by! { |set|
pre_match_length = nil
found_query_index = nil
found_query_count = 0
query_word_regexps.each_with_index do |q, idx|
if (m = set.name.match(/#{q}/i))
pre_match_length ||= (m.pre_match.length)
found_query_index ||= idx
found_query_count += 1
end
end
pre_match_length ||= 1000
found_query_index ||= 1000
[-found_query_count, pre_match_length, found_query_index, set.name.downcase]
}
sets
end
......
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