Class: MiniSearch::SynonymsFilter
- Inherits:
-
Object
- Object
- MiniSearch::SynonymsFilter
- Defined in:
- lib/mini_search/synonyms_filter.rb
Instance Method Summary collapse
- #execute(tokens) ⇒ Object
-
#initialize(synonyms_map) ⇒ SynonymsFilter
constructor
A new instance of SynonymsFilter.
Constructor Details
#initialize(synonyms_map) ⇒ SynonymsFilter
Returns a new instance of SynonymsFilter.
5 6 7 8 9 10 11 |
# File 'lib/mini_search/synonyms_filter.rb', line 5 def initialize(synonyms_map) @flatten_synonyms_map = synonyms_map.keys.each_with_object({}) do |key, hash| synonyms_map[key].each do |value| hash[value] = key end end end |
Instance Method Details
#execute(tokens) ⇒ Object
13 14 15 16 17 |
# File 'lib/mini_search/synonyms_filter.rb', line 13 def execute(tokens) synonyms = tokens.map { |token| @flatten_synonyms_map[token] }.reject(&:nil?) tokens + synonyms end |