Module: Ansr::Facets
- Defined in:
- lib/ansr/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_pivot ⇒ Object
Returns all of the facet queries.
-
#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
77 78 79 80 81 82 |
# File 'lib/ansr/facets.rb', line 77 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
84 85 86 |
# File 'lib/ansr/facets.rb', line 84 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]
89 90 91 |
# File 'lib/ansr/facets.rb', line 89 def facet_fields @facet_fields ||= facet_counts['facet_fields'] || {} end |
#facet_pivot ⇒ Object
Returns all of the facet queries
99 100 101 |
# File 'lib/ansr/facets.rb', line 99 def facet_pivot @facet_pivot ||= facet_counts['facet_pivot'] || {} end |
#facet_queries ⇒ Object
Returns all of the facet queries
94 95 96 |
# File 'lib/ansr/facets.rb', line 94 def facet_queries @facet_queries ||= facet_counts['facet_queries'] || {} end |
#facets ⇒ Object
end “caches” the result in the @facets instance var
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ansr/facets.rb', line 55 def facets @facets ||= begin facet_fields.map do |(facet_field_name,values_and_hits)| items = [] = {} values_and_hits.each_slice(2) do |k,v| items << FacetItem.new(:value => k, :hits => v) end [:sort] = (params[:"f.#{facet_field_name}.facet.sort"] || params[:'facet.sort']) if params[:"f.#{facet_field_name}.facet.limit"] || params[:"facet.limit"] [:limit] = (params[:"f.#{facet_field_name}.facet.limit"] || params[:"facet.limit"]).to_i end if params[:"f.#{facet_field_name}.facet.offset"] || params[:'facet.offset'] [:offset] = (params[:"f.#{facet_field_name}.facet.offset"] || params[:'facet.offset']).to_i end FacetField.new(facet_field_name, items, ) end end end |