Class: IndexedSearch::Query

Inherits:
Array
  • Object
show all
Defined in:
lib/indexed_search/query.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Query

for now the query parsing is just split_into_words, and making it unique



37
38
39
# File 'lib/indexed_search/query.rb', line 37

def initialize(str)
  super(self.class.split_into_words(str).uniq)
end

Class Method Details

.split_into_words(txt) ⇒ Object

split a string or array of strings into an array of individual word strings, ignoring any blank data used equally well by parsing a simple search query, and by parsing data for indexing



43
44
45
46
47
48
49
50
51
# File 'lib/indexed_search/query.rb', line 43

def self.split_into_words(txt)
  if txt.blank?
    []
  elsif txt.class == Array
    txt.collect { |a| a.blank? ? [] : UnicodeUtils.casefold(a).scan(word_match_regex) }.flatten
  else
    UnicodeUtils.casefold(txt).scan(word_match_regex)
  end.collect { |w| w[0...IndexedSearch::Word.max_length] }
end

Instance Method Details

#resultsObject

lookup (and cache) word id data on this word query



54
55
56
# File 'lib/indexed_search/query.rb', line 54

def results
  @results ||= IndexedSearch::Match::ResultList.new(self)
end