Sha256: dbdaf8289ef29817c8dd0099307bdd6e0b852cb82279fa3c8e18c50981093eff

Contents?: true

Size: 599 Bytes

Versions: 8

Compression:

Stored size: 599 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[ThinkingSphinx::SphinxQL.count[:column]]
      hash
    }
  end

  private

  def group_column
    @properties.any?(&:multi?) ?
      ThinkingSphinx::SphinxQL.group_by[:column] : 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.4.2 lib/thinking_sphinx/facet.rb
thinking-sphinx-3.4.1 lib/thinking_sphinx/facet.rb
thinking-sphinx-3.4.0 lib/thinking_sphinx/facet.rb
thinking-sphinx-3.3.0 lib/thinking_sphinx/facet.rb
thinking-sphinx-3.2.0 lib/thinking_sphinx/facet.rb
thinking-sphinx-3.1.4 lib/thinking_sphinx/facet.rb
thinking-sphinx-3.1.3 lib/thinking_sphinx/facet.rb
thinking-sphinx-3.1.2 lib/thinking_sphinx/facet.rb