class Chewie::Query::FullText

Attributes

attribute[R]
clause[R]
options[R]
query[R]
strategy[R]
value[R]
with[R]

Public Class Methods

new(handler, filters) click to toggle source
# File lib/chewie/query/full_text.rb, line 8
def initialize(handler, filters)
  @attribute = handler[:attribute]
  @with = handler[:with]
  @query = handler[:query]
  @clause = handler[:clause]
  @value = filters[attribute] || filters[:query]
  @options = handler.fetch(:options, {})
  @strategy = clause.present? ? 'clause' : 'attribute'
end

Public Instance Methods

build() click to toggle source
# File lib/chewie/query/full_text.rb, line 18
def build
  return {} if value.nil?
  return [] if [value].flatten.empty?

  send("create_with_#{strategy}")
end

Private Instance Methods

attribute_query() click to toggle source
# File lib/chewie/query/full_text.rb, line 51
def attribute_query
  { attribute => { query: value }.merge(options) }
end
create_with_attribute() click to toggle source
# File lib/chewie/query/full_text.rb, line 35
def create_with_attribute
  return multimatch_query if multimatch_query?

  context(attribute) do
    if !value.is_a? Hash
      { query: value }.merge(options)
    else
      value.merge(options)
    end
  end
end
create_with_clause() click to toggle source
# File lib/chewie/query/full_text.rb, line 29
def create_with_clause
  context(query) do
    multimatch_query? ? multimatch_query : attribute_query
  end
end
multimatch_query() click to toggle source
# File lib/chewie/query/full_text.rb, line 55
def multimatch_query
  { fields: with, query: value }.merge(options)
end
multimatch_query?() click to toggle source
# File lib/chewie/query/full_text.rb, line 47
def multimatch_query?
  with.present?
end