Sha256: 5b998373f99c67b1424b88b998ed6452bb0621fe2dd17c7f5df31a183f360922

Contents?: true

Size: 835 Bytes

Versions: 2

Compression:

Stored size: 835 Bytes

Contents

module Picky

  class Search

    # Returns a list of filtered facets.
    # 
    # Params
    #   category: The category whose facets to return.
    # 
    # Options
    #   more_than: A minimum weight a facet needs to have (exclusive). 
    #   filter: A query to filter the facets with.
    #
    # Usage:
    #   search.facets :name, filter: 'surname:peter', more_than: 0
    #
    def facets category_identifier, options = {}
      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, options
      return weights unless filter_query = options[:filter]
      weights.select do |key, weight|
        search("#{filter_query} #{category_identifier}:#{key}", 0, 0).total > 0
      end
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
picky-4.5.9 lib/picky/search_facets.rb
picky-4.5.8 lib/picky/search_facets.rb