Sha256: 83a44b96d1dd1ed6e61b6dc261745d7277639d0b69b8a99a37f401a36a71c879

Contents?: true

Size: 530 Bytes

Versions: 8

Compression:

Stored size: 530 Bytes

Contents

class ThinkingSphinx::Facet
  attr_reader :name

  def initialize(name, properties)
    @name, @properties = name, properties
  end

  def filter_type
    use_field? ? :conditions : :with
  end

  def results_from(raw)
    raw.inject({}) { |hash, row|
      hash[row[group_column]] = row['@count']
      hash
    }
  end

  private

  def group_column
    @properties.any?(&:multi?) ? '@groupby' : name
  end

  def use_field?
    @properties.any? { |property|
      property.type.nil? || property.type == :string
    }
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
thinking-sphinx-3.0.5 lib/thinking_sphinx/facet.rb
thinking-sphinx-3.0.4 lib/thinking_sphinx/facet.rb
thinking-sphinx-3.0.3 lib/thinking_sphinx/facet.rb
thinking-sphinx-3.0.2 lib/thinking_sphinx/facet.rb
thinking-sphinx-3.0.1 lib/thinking_sphinx/facet.rb
thinking-sphinx-3.0.0 lib/thinking_sphinx/facet.rb
thinking-sphinx-3.0.0.rc lib/thinking_sphinx/facet.rb
thinking-sphinx-3.0.0.pre lib/thinking_sphinx/facet.rb