Module: Droonga::Searcher::RecordsFormattable

Included in:
ComplexRecordsFormatter, SimpleRecordsFormatter
Defined in:
lib/droonga/searcher.rb

Instance Method Summary collapse

Instance Method Details

#format_records(output_target_attributes, records, output_limit, output_offset) ⇒ Object



464
465
466
467
468
469
470
471
472
473
474
475
476
# File 'lib/droonga/searcher.rb', line 464

def format_records(output_target_attributes, records, output_limit, output_offset)
  cursor_options = {
    :offset => output_offset,
    :limit => output_limit
  }
  formatted_records = nil
  records.open_cursor(cursor_options) do |cursor|
    formatted_records = cursor.collect do |record|
      format_record(output_target_attributes, record)
    end
  end
  formatted_records
end

#record_value(record, attribute) ⇒ Object



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/droonga/searcher.rb', line 441

def record_value(record, attribute)
  if attribute[:source] == "_subrecs"
    record.sub_records.collect do |sub_record|
      sub_attributes = attribute[:attributes]
      format_record(sub_attributes, sub_record)
    end
  else
    expression = attribute[:expression]
    if expression
      variable = attribute[:variable]
      variable.value = record
      expression.execute
    else
      value = record[attribute[:source]]
      if value.is_a?(Groonga::Record)
        value.record_id
      else
        value
      end
    end
  end
end