Sha256: 575ba742bf3df674e932768d32af81fba7f4e5722bb48addf7fd03e3e22e5c0a

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

module Scrivito

class ObjSearchBuilder < Struct.new(:query)

  def build
    reset_enumerator

    set_predicates
    set_offset
    set_order
    set_batch_size
    set_format
    set_include_deleted

    enumerator
  end

  private

  def reset_enumerator
    @enumerator = nil
  end

  def enumerator
    @enumerator ||= ObjSearchEnumerator.new(Workspace.current)
  end

  def set_predicates
    query[:predicates].each do |p|
      if p[:negate]
        enumerator.and_not(p[:field], p[:operator], p[:value])
      else
        enumerator.and(p[:field], p[:operator], p[:value], p[:boost])
      end
    end
  end

  def set_offset
    enumerator.offset(query[:offset].to_i) if query[:offset]
  end

  def set_order
    enumerator.order(query[:order]) if query[:order]
    enumerator.reverse_order if query[:reverse_order]
  end

  def set_batch_size
    enumerator.batch_size(query[:batch_size]) if query[:batch_size]
  end

  def set_format
    enumerator.format(query[:format]) if query[:format]
  end

  def set_include_deleted
    enumerator.include_deleted if query[:include_deleted]
  end

end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scrivito_sdk-0.17.0 lib/scrivito/obj_search_builder.rb