lib/ultrasphinx/search/parser.rb in ultrasphinx-1.5 vs lib/ultrasphinx/search/parser.rb in ultrasphinx-1.5.1

- old
+ new

@@ -56,20 +56,31 @@ end def query_to_token_stream(query) # First, split query on spaces that are not inside sets of quotes or parens + query = query.scan(/[^"() ]*["(][^")]*[")]|[^"() ]+/) token_stream = [] has_operator = false query.each_with_index do |subtoken, index| # recurse for parens, if necessary if subtoken =~ /^(.*?)\((.*)\)(.*?$)/ subtoken = query[index] = "#{$1}(#{parse $2})#{$3}" - end + end + + # reappend missing closing quotes + if subtoken =~ /(^|\:)\"/ + subtoken = subtoken.chomp('"') + '"' + end + + # strip parentheses within quoted strings + if subtoken =~ /\"(.*)\"/ + subtoken.sub!($1, $1.gsub(/[()]/, '')) + end # add to the stream, converting the operator if !has_operator if OPERATORS.to_a.flatten.include? subtoken and index != (query.size - 1) # operators at the end of the string are not parsed token_stream << OPERATORS[subtoken] || subtoken \ No newline at end of file