app/lib/search.rb
# Split query on non-paren enclosed spaces
Split query on non-paren enclosed spaces
Split query on non - paren enclosed spaces
def psplit(query)
    split = []
    depth = 0
    current = ""
    query.chars.each_with_index do |ch, i|
      if i == query.length-1
        split << current+ch
      elsif ch == ' ' && depth == 0
        split << current
        current = ""
      else
        current << ch
        if ch == '('
          depth += 1
        elsif ch == ')'
          depth -= 1
        end
      end
    end
    split
  end
def psplit ( query ) split = [ ] depth = 0 current = "" query . chars . each_with_index do | ch , i | if i == query . length - 1 split << current + ch elsif ch == ' ' && depth == 0 split << current current = "" else current << ch if ch == '(' depth += 1 elsif ch == ')' depth -= 1 end end end split end
Split query on non-paren enclosed spaces
Split query on non - paren enclosed spaces
query