summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth Falcon <seth@opscode.com>2010-09-20 21:04:54 -0700
committersdelano <stephen@opscode.com>2010-11-04 14:00:52 -0700
commitbdec8fee8721716e3d2906edcea1d3f4e3f60525 (patch)
tree7ad77e1bd077cb354ae1ce1030ae2bd38a59ff84
parentc1aedbe4d6c1b0cd447dd4c7e1605d7c12f17d47 (diff)
downloadchef-bdec8fee8721716e3d2906edcea1d3f4e3f60525.tar.gz
Catch more cases of nested range queries
-rw-r--r--chef-solr/lib/chef/solr/query.rb23
-rw-r--r--chef-solr/spec/data/search_queries_to_transform.txt7
2 files changed, 18 insertions, 12 deletions
diff --git a/chef-solr/lib/chef/solr/query.rb b/chef-solr/lib/chef/solr/query.rb
index 8c5514577f..87bb66c939 100644
--- a/chef-solr/lib/chef/solr/query.rb
+++ b/chef-solr/lib/chef/solr/query.rb
@@ -102,27 +102,26 @@ class Chef
# TODO: this is a rough first attempt. should verify edge cases for
# query encoding and other special characters, e.g. %20
return q if q == "*:*"
+
# a:[* TO *] => a*
q = q.gsub(/\[\*[+ ]TO[+ ]\*\]/, '*')
keyp = '[^ \\+()]+'
lbrak = '[\[{]'
rbrak = '[\]}]'
- # a:[blah TO *] => content\001[a__=__blah\002TO\002a__=__\ufff0]
- q = q.gsub(/(#{keyp}):(#{lbrak})(.+)[+ ]TO[+ ]\*(#{rbrak})/) do |m|
- "content#{TEMP_SEP}#{$2}#{$1}__=__#{$3}#{SPC_SEP}TO#{SPC_SEP}#{$1}__=__\\ufff0#{$4}"
- end
-
- # a:[* TO blah] => content\001[a__=__\002TO\002a__=__blah]
- q = q.gsub(/(#{keyp}):(#{lbrak})\*[+ ]TO[+ ]([^\]]+)(#{rbrak})/) do |m|
- "content#{TEMP_SEP}#{$2}#{$1}__=__#{SPC_SEP}TO#{SPC_SEP}#{$1}__=__#{$3}#{$4}"
- end
# a:[blah TO zah] =>
# content\001[a__=__blah\002TO\002a__=__zah]
-
- q = q.gsub(/(#{keyp}):(#{lbrak})([^\]}]+)[+ ]TO[+ ]([^\]]+)(#{rbrak})/) do |m|
- "content#{TEMP_SEP}#{$2}#{$1}__=__#{$3}#{SPC_SEP}TO#{SPC_SEP}#{$1}__=__#{$4}#{$5}"
+ # includes the cases a:[* TO zah] and a:[blah TO *], but not
+ # [* TO *]; that is caught above
+ q = q.gsub(/(#{keyp}):(#{lbrak})([^\]}]+)[+ ]TO[+ ]([^\]}]+)(#{rbrak})/) do |m|
+ if $3 == "*"
+ "content#{TEMP_SEP}#{$2}#{$1}__=__#{SPC_SEP}TO#{SPC_SEP}#{$1}__=__#{$4}#{$5}"
+ elsif $4 == "*"
+ "content#{TEMP_SEP}#{$2}#{$1}__=__#{$3}#{SPC_SEP}TO#{SPC_SEP}#{$1}__=__\\ufff0#{$5}"
+ else
+ "content#{TEMP_SEP}#{$2}#{$1}__=__#{$3}#{SPC_SEP}TO#{SPC_SEP}#{$1}__=__#{$4}#{$5}"
+ end
end
# foo:bar => content:foo__=__bar
diff --git a/chef-solr/spec/data/search_queries_to_transform.txt b/chef-solr/spec/data/search_queries_to_transform.txt
index b38435e146..65b36571f5 100644
--- a/chef-solr/spec/data/search_queries_to_transform.txt
+++ b/chef-solr/spec/data/search_queries_to_transform.txt
@@ -54,3 +54,10 @@ content:[animal__=__ape TO animal__=__zebra]
animal:{ape TO zebra}
content:{animal__=__ape TO animal__=__zebra}
+
+((value:[1 TO 3] OR nested_b1_a2_a3:B1_A2_A3-c) OR value:[5 TO *])
+((content:[value__=__1 TO value__=__3] OR content:nested_b1_a2_a3__=__B1_A2_A3-c) OR content:[value__=__5 TO value__=__\ufff0])
+
+((value:{1 TO 3} OR value:{1 TO 3}) OR run_list:recipe\[alpha\])
+((content:{value__=__1 TO value__=__3} OR content:{value__=__1 TO value__=__3}) OR content:run_list__=__recipe\[alpha\])
+