Sha256: e826a8537d797ef5fac36aeb110d07c7c408e566d393fe5e6565a70d0aac9614

Contents?: true

Size: 836 Bytes

Versions: 11

Compression:

Stored size: 836 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)|
        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

11 entries across 11 versions & 1 rubygems

Version Path
picky-4.10.0 lib/picky/index_facets.rb
picky-4.9.0 lib/picky/index_facets.rb
picky-4.8.1 lib/picky/index_facets.rb
picky-4.8.0 lib/picky/index_facets.rb
picky-4.7.0 lib/picky/index_facets.rb
picky-4.6.6 lib/picky/index_facets.rb
picky-4.6.5 lib/picky/index_facets.rb
picky-4.6.4 lib/picky/index_facets.rb
picky-4.6.3 lib/picky/index_facets.rb
picky-4.6.2 lib/picky/index_facets.rb
picky-4.6.1 lib/picky/index_facets.rb