Class: IndexedSearch::Match::StartWith
- Defined in:
- lib/indexed_search/match/start_with.rb
Overview
Does a start-with comparison to find words whose beginning part is equal to the given terms. In concept it’s kind of like a nice lowest-common-denominator stemmer for all languages. Though it’s obviously not as good as most real language-specific stemmer algorithms of course.
Note this uses database LIKE matching in some places, and ruby String#start_with? in others, which does not always mean exactly the same thing. But our term normalization in IndexedSearch::Query.split_into_words should make it a non-issue.
Instance Method Summary collapse
Methods inherited from Base
#find, find_attributes, #initialize, match_against_term?, #results, #term_matches, #term_non_matches
Constructor Details
This class inherits a constructor from IndexedSearch::Match::Base
Instance Method Details
#scope ⇒ Object
22 23 24 |
# File 'lib/indexed_search/match/start_with.rb', line 22 def scope @scope.where(@scope.arel_table[self.class.matcher_attribute].matches_any(term_matches.collect { |t| "#{t}%" })) end |
#term_map ⇒ Object
26 27 28 29 30 |
# File 'lib/indexed_search/match/start_with.rb', line 26 def term_map @term_map ||= Hash.new { |hash,key| hash[key] = [] }.tap do |map| find.each { |id,count,rank,match| term_matches.each { |term| map[match] << term if match.start_with?(term) } } end end |