summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2013-08-08 16:38:52 -0700
committerJohn Keiser <jkeiser@opscode.com>2013-08-08 16:38:52 -0700
commit98c2f7148ccaad1af3f237094f9f664368c2a024 (patch)
tree223090f39d07ac9837ec3b97e5f9e63bd9ff981d
parent25ed925573c05f84c279decc8f8a039801ebccf1 (diff)
downloadchef-zero-98c2f7148ccaad1af3f237094f9f664368c2a024.tar.gz
Fix #31: Allow - in search terms rather then interpreting it as an operator
-rw-r--r--lib/chef_zero/solr/query/regexpable_query.rb1
-rw-r--r--lib/chef_zero/solr/solr_parser.rb10
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/chef_zero/solr/query/regexpable_query.rb b/lib/chef_zero/solr/query/regexpable_query.rb
index 7435fab..241e675 100644
--- a/lib/chef_zero/solr/query/regexpable_query.rb
+++ b/lib/chef_zero/solr/query/regexpable_query.rb
@@ -20,6 +20,7 @@ module ChefZero
values.any? { |value| !@regexp.match(value).nil? }
end
+ DEFAULT_FIELD = "text"
WORD_CHARACTER = "[A-Za-z0-9@._':]"
NON_WORD_CHARACTER = "[^A-Za-z0-9@._':]"
end
diff --git a/lib/chef_zero/solr/solr_parser.rb b/lib/chef_zero/solr/solr_parser.rb
index e237025..936ead1 100644
--- a/lib/chef_zero/solr/solr_parser.rb
+++ b/lib/chef_zero/solr/solr_parser.rb
@@ -49,18 +49,24 @@ module ChefZero
@index+=1
end
@index+=1 if !eof?
- end until eof? || @query_string[@index] =~ /\s/ || peek_operator_token
+ end while !eof? && peek_term_token
@query_string[start_index..@index-1]
end
end
def skip_whitespace
if @query_string[@index] =~ /\s/
- whitespace = /\s+/.match(@query_string, @index)
+ whitespace = /\s+/.match(@query_string, @index) || peek
@index += whitespace[0].length
end
end
+ def peek_term_token
+ return nil if @query_string[@index] =~ /\s/
+ op = peek_operator_token
+ return !op || op == '-'
+ end
+
def peek_operator_token
if ['"', '+', '-', '!', '(', ')', '{', '}', '[', ']', '^', ':'].include?(@query_string[@index])
return @query_string[@index]