Skip to content
This repository
tag: v4.5.8
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 27 lines (22 sloc) 0.715 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
module Picky

  class Search

    # Returns a list of filtered facets.
    #
    # Params
    # category: The category whose facets to return.
    # filter_query: (optional) A query to filter the facets with.
    #
    # Usage:
    # search.facets :name, 'surname:peter'
    #
    def facets category_identifier, filter_query = nil
      raise "#{__method__} cannot be used on searches with more than 1 index yet. Sorry!" if indexes.size > 1
      index = indexes.first
      weights = index.facets category_identifier
      return weights unless filter_query
      weights.select do |key, weight|
        search("#{filter_query} #{category_identifier}:#{key}", 0, 0).total > 0
      end
    end

  end

end
Something went wrong with that request. Please try again.