module Ansr::Facets
Public Instance Methods
facet_by_field_name(name)
click to toggle source
pass in a facet field name and get back a Facet instance
# 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()
click to toggle source
# File lib/ansr/facets.rb, line 84 def facet_counts @facet_counts ||= self['facet_counts'] || {} end
facet_fields()
click to toggle source
Returns the hash of all the facet_fields
(ie: {‘instock_b’ => [‘true’, 123, ‘false’, 20]}
# File lib/ansr/facets.rb, line 89 def facet_fields @facet_fields ||= facet_counts['facet_fields'] || {} end
facet_pivot()
click to toggle source
Returns all of the facet queries
# File lib/ansr/facets.rb, line 99 def facet_pivot @facet_pivot ||= facet_counts['facet_pivot'] || {} end
facet_queries()
click to toggle source
Returns all of the facet queries
# File lib/ansr/facets.rb, line 94 def facet_queries @facet_queries ||= facet_counts['facet_queries'] || {} end
facets()
click to toggle source
@response.facets.each do |facet|
facet.name facet.items
end “caches” the result in the @facets instance var
# File lib/ansr/facets.rb, line 55 def facets @facets ||= begin facet_fields.map do |(facet_field_name,values_and_hits)| items = [] options = {} values_and_hits.each_slice(2) do |k,v| items << FacetItem.new(:value => k, :hits => v) end options[:sort] = (params[:"f.#{facet_field_name}.facet.sort"] || params[:'facet.sort']) if params[:"f.#{facet_field_name}.facet.limit"] || params[:"facet.limit"] options[: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'] options[:offset] = (params[:"f.#{facet_field_name}.facet.offset"] || params[:'facet.offset']).to_i end FacetField.new(facet_field_name, items, options) end end end