summaryrefslogtreecommitdiff
path: root/lib/chef_zero
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2013-06-06 12:43:37 -0700
committerJohn Keiser <jkeiser@opscode.com>2013-06-06 12:43:37 -0700
commit1e282ca735d9790fb9dbc4f3f46253082c511fe1 (patch)
treee383a694b0ab1b21971e944afc2b9630639194e4 /lib/chef_zero
parent9257598ecc89c58f21471d3c3e47acd42d4d0723 (diff)
downloadchef-zero-1e282ca735d9790fb9dbc4f3f46253082c511fe1.tar.gz
Fix issue with multiple identical keys, speed up search
Diffstat (limited to 'lib/chef_zero')
-rw-r--r--lib/chef_zero/solr/query/binary_operator.rb5
-rw-r--r--lib/chef_zero/solr/query/regexpable_query.rb3
-rw-r--r--lib/chef_zero/solr/solr_doc.rb19
3 files changed, 8 insertions, 19 deletions
diff --git a/lib/chef_zero/solr/query/binary_operator.rb b/lib/chef_zero/solr/query/binary_operator.rb
index bd8fa4c..6d9b219 100644
--- a/lib/chef_zero/solr/query/binary_operator.rb
+++ b/lib/chef_zero/solr/query/binary_operator.rb
@@ -26,12 +26,11 @@ module ChefZero
left.matches_doc?(doc)
when ':'
if left.respond_to?(:literal_string) && left.literal_string
- value = doc[left.literal_string]
- right.matches_values?([value])
+ values = doc[left.literal_string]
else
values = doc.matching_values { |key| left.matches_values?([key]) }
- right.matches_values?(values)
end
+ right.matches_values?(values)
end
end
diff --git a/lib/chef_zero/solr/query/regexpable_query.rb b/lib/chef_zero/solr/query/regexpable_query.rb
index 5166309..7435fab 100644
--- a/lib/chef_zero/solr/query/regexpable_query.rb
+++ b/lib/chef_zero/solr/query/regexpable_query.rb
@@ -14,8 +14,7 @@ module ChefZero
attr_reader :regexp
def matches_doc?(doc)
- value = doc[DEFAULT_FIELD]
- return value ? matches_values?([value]) : false
+ matches_values?(doc[DEFAULT_FIELD])
end
def matches_values?(values)
values.any? { |value| !@regexp.match(value).nil? }
diff --git a/lib/chef_zero/solr/solr_doc.rb b/lib/chef_zero/solr/solr_doc.rb
index d61a7d5..6476d48 100644
--- a/lib/chef_zero/solr/solr_doc.rb
+++ b/lib/chef_zero/solr/solr_doc.rb
@@ -9,31 +9,22 @@ module ChefZero
end
def [](key)
- values = matching_values { |match_key| match_key == key }
- values[0]
+ matching_values { |match_key| match_key == key }
end
def matching_values(&block)
- result = {}
+ result = []
key_values(nil, @json) do |key, value|
if block.call(key)
- if result.has_key?(key)
- result[key] << value.to_s
- else
- result[key] = value.to_s.clone
- end
+ result << value.to_s
end
end
# Handle manufactured value(s)
if block.call('X_CHEF_id_CHEF_X')
- if result.has_key?('X_CHEF_id_CHEF_X')
- result['X_CHEF_id_CHEF_X'] << @id.to_s
- else
- result['X_CHEF_id_CHEF_X'] = @id.to_s.clone
- end
+ result << @id.to_s
end
- result.values
+ result.uniq
end
private