class Query::Parser

Public Instance Methods

parse_exact_phrase(querystring, phrases) click to toggle source
# File lib/generators/hayfork/templates/query/parser.rb, line 12
def parse_exact_phrase(querystring, phrases)
  phrases << Query::ExactPhrase.new(tokenize_words(querystring))
end
parse_phrase(querystring, phrases) click to toggle source
# File lib/generators/hayfork/templates/query/parser.rb, line 6
def parse_phrase(querystring, phrases)
  tokenize_words(querystring).each do |word|
    phrases << Query::ExactPhrase.new([ word ])
  end
end
tokenize_words(querystring) click to toggle source
# File lib/generators/hayfork/templates/query/parser.rb, line 16
def tokenize_words(querystring)
  # Postgres does not handle hyphens well.
  #
  # Notice how, in the following example, the way it breaks up
  # the hyphenated word throws off the index (Jesus is the fifth word
  # not the third or fourth). This prevents you from constructing
  # an exact-phrase query for a hyphenated word:
  #
  #   > select to_tsvector('hayfork', 'thou long-expected jesus');
  #   { 'expect':4 'jesus':5 'long':3 'long-expect':2 'thou':1 }
  #
  #
  # We'll coerce Postgres into treating hyphenated words as two words.
  querystring.to_s.scan(/\w+/)
end