diff options
author | Seth Falcon <seth@opscode.com> | 2010-09-20 21:04:54 -0700 |
---|---|---|
committer | Daniel DeLeo <dan@opscode.com> | 2011-02-02 12:12:05 -0800 |
commit | e800da85cc4170fa672a9d459fa0df5cd57c2edf (patch) | |
tree | b9482c947873801d4cd0e84d5219f6d94574d140 /chef-solr | |
parent | cbd87c9167173d0a76f4a82e4f7c4338b085fcbb (diff) | |
download | chef-e800da85cc4170fa672a9d459fa0df5cd57c2edf.tar.gz |
Catch more cases of nested range queries
Diffstat (limited to 'chef-solr')
-rw-r--r-- | chef-solr/lib/chef/solr/query.rb | 23 | ||||
-rw-r--r-- | chef-solr/spec/data/search_queries_to_transform.txt | 7 |
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 ee4de0cb31..c88f44635c 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\]) + |