Class: NameSearch::Search
- Inherits:
-
Array
- Object
- Array
- NameSearch::Search
- Defined in:
- lib/name_search/search.rb
Instance Method Summary collapse
-
#initialize(klass_or_query, name, options = {}) ⇒ Search
constructor
A new instance of Search.
Constructor Details
#initialize(klass_or_query, name, options = {}) ⇒ Search
Returns a new instance of Search.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/name_search/search.rb', line 3 def initialize(klass_or_query, name, = {}) name_values = Name.scrub_and_split_name(name) names = get_names(name_values) nick_names = ([:match_mode] == :exact) ? [] : get_nick_names(names) results = matched_models(klass_or_query, names + nick_names). map{|x| SearchResult.new(x, name_values, nick_names.map(&:value)) }. sort{|a,b| b.match_score <=> a.match_score } if .has_key?(:matches_at_least) results = results.delete_if{|x| x.matched_names.length < [:matches_at_least] } end self.concat(results) end |