Module: RSolrExt::Response::Select::Facets
- Included in:
- RSolrExt::Response::Select
- Defined in:
- lib/rsolr_ext/response/select.rb
Defined Under Namespace
Classes: Facet, FacetValue
Instance Method Summary collapse
-
#facet_by_field_name(name) ⇒ Object
pass in a facet field name and get back a Facet instance.
- #facet_counts ⇒ Object
-
#facet_fields ⇒ Object
Returns the hash of all the facet_fields (ie: => [‘true’, 123, ‘false’, 20].
-
#facet_queries ⇒ Object
Returns all of the facet queries.
-
#facets ⇒ Object
end “caches” the result in the @facets instance var.
Instance Method Details
#facet_by_field_name(name) ⇒ Object
pass in a facet field name and get back a Facet instance
84 85 86 87 88 89 |
# File 'lib/rsolr_ext/response/select.rb', line 84 def facet_by_field_name(name) @facets_by_field_name ||= {} @facets_by_field_name[name] ||= ( facets.detect{|facet|facet.field.to_s == name.to_s} ) end |
#facet_counts ⇒ Object
91 92 93 |
# File 'lib/rsolr_ext/response/select.rb', line 91 def facet_counts @facet_counts ||= self[:facet_counts] || {} end |
#facet_fields ⇒ Object
Returns the hash of all the facet_fields (ie: => [‘true’, 123, ‘false’, 20]
96 97 98 |
# File 'lib/rsolr_ext/response/select.rb', line 96 def facet_fields @facet_fields ||= facet_counts[:facet_fields] || {} end |
#facet_queries ⇒ Object
Returns all of the facet queries
101 102 103 |
# File 'lib/rsolr_ext/response/select.rb', line 101 def facet_queries @facet_queries ||= facet_counts[:facet_queries] || {} end |
#facets ⇒ Object
end “caches” the result in the @facets instance var
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rsolr_ext/response/select.rb', line 66 def facets # memoize! @facets ||= ( facet_fields.inject([]) do |acc,(facet_field_name,values_and_hits_list)| acc << facet = Facet.new(facet_field_name) # the values_and_hits_list is an array where a value is immediately followed by it's hit count # so we shift off an item (the value) while value = values_and_hits_list.shift # and then shift off the next to get the hit value facet.values << FacetValue.new(value, values_and_hits_list.shift) # repeat until there are no more pairs in the values_and_hits_list array end acc end ) end |