Class: Chef::Search
- Inherits:
-
Object
- Object
- Chef::Search
- Defined in:
- lib/chef/search.rb,
lib/chef/search/result.rb
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
Instance Method Summary collapse
- #has_index?(index) ⇒ Boolean
-
#initialize ⇒ Search
constructor
A new instance of Search.
- #list_indexes ⇒ Object
- #search(type, query = "*", attributes = [], &block) ⇒ Object
Constructor Details
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
25 26 27 |
# File 'lib/chef/search.rb', line 25 def index @index end |
Instance Method Details
#has_index?(index) ⇒ Boolean
70 71 72 |
# File 'lib/chef/search.rb', line 70 def has_index?(index) list_indexes.detect { |i| i == index } end |
#list_indexes ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/chef/search.rb', line 62 def list_indexes indexes = Hash.new @index.search_each("index_name:*", :limit => :all) do |id, score| indexes[@index.doc(id)["index_name"]] = true end indexes.keys end |
#search(type, query = "*", attributes = [], &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/chef/search.rb', line 31 def search(type, query="*", attributes=[], &block) search_query = build_search_query(type, query) start_time = Time.now results = [] block ||= lambda { |b| b } @index.search_each(search_query, :limit => :all) do |id, score| results << block.call(build_hash(@index.doc(id))) end Chef::Log.debug("Search #{search_query} complete in #{Time.now - start_time} seconds") attributes.empty? ? results : filter_by_attributes(results,attributes) end |