Class: Komainu::SearchesText

Inherits:
Object
  • Object
show all
Defined in:
lib/komainu/searches_text.rb

Instance Method Summary collapse

Constructor Details

#initialize(data_to_search) ⇒ SearchesText

Returns a new instance of SearchesText.



15
16
17
# File 'lib/komainu/searches_text.rb', line 15

def initialize data_to_search
  @data_to_search = data_to_search
end

Instance Method Details

#search(query) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/komainu/searches_text.rb', line 19

def search query
  results = SearchResults.new
  @data_to_search.each do |searchable|
    matches = find_matches(searchable.text, query)
    if matches.any?
      results.items << SearchResult.new(searchable, matches)
    end
  end

  results.suggestion = calculate_suggestion(query)
  results
end