Sha256: 78e0128e4930183ca6871d33cab0cb369c00feb629e3634512f7258a2e7cd53b

Contents?: true

Size: 795 Bytes

Versions: 17

Compression:

Stored size: 795 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

class ThinkingSphinx::Search::Query
  attr_reader :keywords, :conditions, :star

  def initialize(keywords = '', conditions = {}, star = false)
    @keywords, @conditions, @star = keywords, conditions, star
  end

  def to_s
    (star_keyword(keywords || '') + ' ' + conditions.keys.collect { |key|
       next if conditions[key].blank?

      "#{expand_key key} #{star_keyword conditions[key], key}"
    }.join(' ')).strip
  end

  private

  def expand_key(key)
    return "@#{key}" unless key.is_a?(Array)

    "@(#{key.join(',')})"
  end

  def star_keyword(keyword, key = nil)
    return keyword.to_s unless star
    return keyword.to_s if key.to_s == 'sphinx_internal_class_name'

    ThinkingSphinx::Query.wildcard keyword, star
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/search/query.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/search/query.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/search/query.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/search/query.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/search/query.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/search/query.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/search/query.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/search/query.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/search/query.rb
thinking-sphinx-4.4.1 lib/thinking_sphinx/search/query.rb
thinking-sphinx-4.4.0 lib/thinking_sphinx/search/query.rb
thinking-sphinx-4.3.2 lib/thinking_sphinx/search/query.rb
thinking-sphinx-4.3.1 lib/thinking_sphinx/search/query.rb
thinking-sphinx-4.3.0 lib/thinking_sphinx/search/query.rb
thinking-sphinx-4.2.0 lib/thinking_sphinx/search/query.rb
thinking-sphinx-4.1.0 lib/thinking_sphinx/search/query.rb
thinking-sphinx-4.0.0 lib/thinking_sphinx/search/query.rb