Sha256: ad62b4cb20a9b953f652809be5bc2cdb27160e5b24c6df2937b247590b9ce49a

Contents?: true

Size: 862 Bytes

Versions: 2

Compression:

Stored size: 862 Bytes

Contents

module Picky

  class Index
    
    # Return facets for a category in the form:
    #   { text => count }
    #
    # Options
    #   counts: Whether you want counts or not.
    #   at_least: A minimum count a facet needs to have (inclusive). 
    #
    # TODO Think about having a separate index for counts to reduce the complexity of this.
    #
    def facets category_identifier, options = {}
      text_ids = self[category_identifier].exact.inverted
      no_counts = options[:counts] == false
      minimal_counts = options[:at_least]
      text_ids.inject(no_counts ? [] : {}) do |result, text_ids|
        text, ids = text_ids
        size = ids.size
        next result if minimal_counts && size < minimal_counts
        if no_counts
          result << text
        else
          result[text] = size; result
        end
      end
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
picky-4.6.0 lib/picky/index_facets.rb
picky-4.5.12 lib/picky/index_facets.rb