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.15.0 lib/picky/index_facets.rb
picky-4.14.0 lib/picky/index_facets.rb
picky-4.13.1 lib/picky/index_facets.rb
picky-4.13.0 lib/picky/index_facets.rb
picky-4.12.13 lib/picky/index_facets.rb
picky-4.12.12 lib/picky/index_facets.rb
picky-4.12.11 lib/picky/index_facets.rb
picky-4.12.10 lib/picky/index_facets.rb
picky-4.12.8 lib/picky/index_facets.rb
picky-4.12.7 lib/picky/index_facets.rb
picky-4.12.6 lib/picky/index_facets.rb
picky-4.12.5 lib/picky/index_facets.rb
picky-4.12.4 lib/picky/index_facets.rb
picky-4.12.3 lib/picky/index_facets.rb
picky-4.12.2 lib/picky/index_facets.rb
picky-4.12.1 lib/picky/index_facets.rb
picky-4.12.0 lib/picky/index_facets.rb
picky-4.11.3 lib/picky/index_facets.rb
picky-4.11.2 lib/picky/index_facets.rb
picky-4.11.1 lib/picky/index_facets.rb