Sha256: 84b2fc66bb99f6c598bd1bea11798c9676eb075697fbf6d271abe95b11d27f1a

Contents?: true

Size: 1.17 KB

Versions: 78

Compression:

Stored size: 1.17 KB

Contents

module Scrivito

class ObjSearchBuilder < Struct.new(:query)

  def build
    reset_enumerator

    set_predicates
    set_offset
    set_order
    set_batch_size
    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|
      values = deserialize_values(p[:value])
      if p[:negate]
        enumerator.and_not(p[:field], p[:operator], values)
      else
        enumerator.and(p[:field], p[:operator], values, p[:boost])
      end
    end
  end

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

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

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

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

  def deserialize_values(values)
    values.map do |(type, value)|
      if type == 'date'
        DateConversion.deserialize_from_client(value)
      else
        value
      end
    end
  end
end

end

Version data entries

78 entries across 78 versions & 1 rubygems

Version Path
scrivito_sdk-1.5.1 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.5.1.rc2 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.5.1.rc1 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.5.0 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.5.0.rc2 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.5.0.rc1 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.4.2 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.4.1 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.4.1.rc1 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.4.0 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.4.0.rc2 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.4.0.rc1 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.3.1 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.3.1.rc1 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.3.0 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.3.0.rc3 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.3.0.rc2 lib/scrivito/obj_search_builder.rb
scrivito_sdk-1.3.0.rc1 lib/scrivito/obj_search_builder.rb