Module: RSolr::Ext::Response::Facets
- Defined in:
- lib/rsolr-ext/response/facets.rb
Defined Under Namespace
Classes: FacetField, FacetItem
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
41 42 43 44 45 46 |
# File 'lib/rsolr-ext/response/facets.rb', line 41 def facet_by_field_name(name) @facets_by_field_name ||= {} @facets_by_field_name[name] ||= ( facets.detect{|facet|facet.name.to_s == name.to_s} ) end |
#facet_counts ⇒ Object
48 49 50 |
# File 'lib/rsolr-ext/response/facets.rb', line 48 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]
53 54 55 |
# File 'lib/rsolr-ext/response/facets.rb', line 53 def facet_fields @facet_fields ||= facet_counts['facet_fields'] || {} end |
#facet_queries ⇒ Object
Returns all of the facet queries
58 59 60 |
# File 'lib/rsolr-ext/response/facets.rb', line 58 def facet_queries @facet_queries ||= facet_counts['facet_queries'] || {} end |
#facets ⇒ Object
end “caches” the result in the @facets instance var
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rsolr-ext/response/facets.rb', line 15 def facets # memoize! @facets ||= ( all = facet_fields.collect do |(facet_field_name,values_and_hits_list)| facet = FacetField.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.items << FacetItem.new(value, values_and_hits_list.shift) # repeat until there are no more pairs in the values_and_hits_list array end facet end #all.extend RSolr::Ext::Response::Docs::Pageable #all.start = header['params']['facet.offset'].to_s.to_i #all.per_page = header['params']['facet.limit'].to_s.to_i - 1 #all.total = -1 ## override the has_next? method -- when paging through facets, ## it's not possible to know how many "pages" there are #all.instance_eval "def has_next?; #{all.size == all.per_page+1} end" all ) end |