Class: Atlasq::Util::WordMap
- Inherits:
-
Object
- Object
- Atlasq::Util::WordMap
- Defined in:
- lib/atlasq/util/word_map.rb
Overview
This data structure provides partial match support for words in sentences.
For example, if we take a country like “Bonaire, Sint Eustatius and Saba” the searches “Bonaire”, “Sint Eustatius” and “saba bonaire” should all match while the searches “bonaire france” and “saba bolivia” should not because they include words not found in the original sentence.
Instance Method Summary collapse
-
#initialize(index:) ⇒ WordMap
constructor
A new instance of WordMap.
-
#search(search_term) ⇒ Array<String>
Search for ids that include all of the search term words.
Constructor Details
#initialize(index:) ⇒ WordMap
Returns a new instance of WordMap.
16 17 18 |
# File 'lib/atlasq/util/word_map.rb', line 16 def initialize(index:) @index = index end |
Instance Method Details
#search(search_term) ⇒ Array<String>
Search for ids that include all of the search term words.
24 25 26 27 28 29 30 31 |
# File 'lib/atlasq/util/word_map.rb', line 24 def search(search_term) search_term .then(&Util::String.method(:word_split)) .uniq .map { |word| @index.fetch(word, []) } .inject(&:intersection) .sort end |