Class: ChefZero::Solr::SolrDoc
- Inherits:
-
Object
- Object
- ChefZero::Solr::SolrDoc
- Defined in:
- lib/chef_zero/solr/solr_doc.rb
Overview
This does what expander does, flattening the json doc into keys and values so that solr can search them.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(json, id) ⇒ SolrDoc
constructor
A new instance of SolrDoc.
- #matching_values(&block) ⇒ Object
Constructor Details
#initialize(json, id) ⇒ SolrDoc
Returns a new instance of SolrDoc.
6 7 8 9 |
# File 'lib/chef_zero/solr/solr_doc.rb', line 6 def initialize(json, id) @json = json @id = id end |
Instance Method Details
#[](key) ⇒ Object
11 12 13 |
# File 'lib/chef_zero/solr/solr_doc.rb', line 11 def [](key) matching_values { |match_key| match_key == key } end |
#matching_values(&block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/chef_zero/solr/solr_doc.rb', line 15 def matching_values(&block) result = [] key_values(nil, @json) do |key, value| if yield(key) result << value.to_s end end # Handle manufactured value(s) if yield("X_CHEF_id_CHEF_X") result << @id.to_s end result.uniq end |