Module: NaiveSearch::NaiveSearchOn
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/naive-search/naive_search_on.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#relevance_for(query) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/naive-search/naive_search_on.rb', line 38 def relevance_for(query) query = ::UnicodeUtils.downcase query.to_s @naive_relevance ||= {} return @naive_relevance[query] if @naive_relevance[query] words = query.split " " score = self.naive_search_fields.map do |field| content = ::UnicodeUtils.downcase self.send(field).to_s words.map do |w| # one point for partial word matches (content.scan(w).size + # one point for partial query matches content.scan(query).size + # two points for exact word match (content == w ? 2 : 0) + # two points for exact query match (content == query ? 2 : 0)) end.sum end.sum @naive_relevance[query] = score end |