module RailsConnector 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(nil) 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