summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Gleeson <mgleeson@atlassian.com>2013-09-30 16:32:56 -0700
committerMatt Gleeson <mgleeson@atlassian.com>2013-09-30 16:32:56 -0700
commit49f6be7fcd62cdf8f2f6acd4c343c88789ecee1a (patch)
tree5e88134c7fe06aa5aa5ed440661e62f5f70ce2de
parent57f02150013c08bd121c51999ac2bbfb468e9f7b (diff)
downloadchef-zero-49f6be7fcd62cdf8f2f6acd4c343c88789ecee1a.tar.gz
add support for wildcards
-rw-r--r--lib/chef_zero/solr/query/range_query.rb24
-rw-r--r--spec/search_spec.rb19
2 files changed, 27 insertions, 16 deletions
diff --git a/lib/chef_zero/solr/query/range_query.rb b/lib/chef_zero/solr/query/range_query.rb
index 5428a6f..625c0bb 100644
--- a/lib/chef_zero/solr/query/range_query.rb
+++ b/lib/chef_zero/solr/query/range_query.rb
@@ -15,17 +15,21 @@ module ChefZero
def matches_values?(values)
values.any? do |value|
- case @from <=> value
- when -1
- return false
- when 0
- return false if !@from_inclusive
+ unless @from == '*'
+ case @from <=> value
+ when -1
+ return false
+ when 0
+ return false if !@from_inclusive
+ end
end
- case value <=> @to
- when 1
- return false
- when 0
- return false if !@to_inclusive
+ unless @to == '*'
+ case value <=> @to
+ when 1
+ return false
+ when 0
+ return false if !@to_inclusive
+ end
end
return true
end
diff --git a/spec/search_spec.rb b/spec/search_spec.rb
index 32d56e4..df0522c 100644
--- a/spec/search_spec.rb
+++ b/spec/search_spec.rb
@@ -11,15 +11,22 @@ describe ChefZero::Solr::SolrParser do
docs
end
+ def search_for(query)
+ q = ChefZero::Solr::SolrParser.new(query).parse
+ all_docs.select {|doc| q.matches_doc?(doc) }
+ end
+
it "handles terms" do
- q = ChefZero::Solr::SolrParser.new('foo:d').parse
- results = all_docs.select {|doc| q.matches_doc?(doc) }
- results.size.should eq(1)
+ search_for('foo:d').size.should eq(1)
end
it "handles ranges" do
- q = ChefZero::Solr::SolrParser.new('foo:[a TO c]').parse
- results = all_docs.select {|doc| q.matches_doc?(doc) }
- results.size.should eq(1)
+ search_for('foo:[a TO c]').size.should eq(1)
+ end
+
+ it "handles wildcard ranges" do
+ search_for('foo:[* TO c]').size.should eq(1)
+ search_for('foo:[c TO *]').size.should eq(1)
+ search_for('foo:[* TO *]').size.should eq(2)
end
end