Sha256: 8803c19490556235b267123ebcefc5d135621987177101615f13eebd636730af

Contents?: true

Size: 962 Bytes

Versions: 61

Compression:

Stored size: 962 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]
      
      if no_counts
        text_ids.inject([]) do |result, (text, ids)|
          next result if minimal_counts && ids.size < minimal_counts
          result << text
        end
      else
        text_ids.inject({}) do |result, (text, ids)|
          size = ids.size
          next result if minimal_counts && size < minimal_counts
          result[text] = size; result
        end
      end
    end

  end

end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
picky-4.31.3 lib/picky/index_facets.rb
picky-4.31.2 lib/picky/index_facets.rb
picky-4.31.1 lib/picky/index_facets.rb
picky-4.31.0 lib/picky/index_facets.rb
picky-4.30.0 lib/picky/index_facets.rb
picky-4.29.0 lib/picky/index_facets.rb
picky-4.28.1 lib/picky/index_facets.rb
picky-4.27.1 lib/picky/index_facets.rb
picky-4.27.0 lib/picky/index_facets.rb
picky-4.26.2 lib/picky/index_facets.rb
picky-4.26.1 lib/picky/index_facets.rb
picky-4.26.0 lib/picky/index_facets.rb
picky-4.25.3 lib/picky/index_facets.rb
picky-4.25.2 lib/picky/index_facets.rb
picky-4.25.1 lib/picky/index_facets.rb
picky-4.25.0 lib/picky/index_facets.rb
picky-4.24.0 lib/picky/index_facets.rb
picky-4.23.2 lib/picky/index_facets.rb
picky-4.23.1 lib/picky/index_facets.rb
picky-4.23.0 lib/picky/index_facets.rb