4 # This index implementation connects to a remote ferret server instance. It
5 # basically forwards all calls to the remote server.
6 class RemoteIndex < AbstractIndex
10 @server = DRbObject.new(nil, config[:remote])
13 def method_missing(method_name, *args)
14 args.unshift model_class_name
15 handle_drb_error { @server.send(method_name, *args) }
18 # Proxy any methods that require special return values in case of errors
21 }.each do |method_name, default_result|
22 define_method method_name do |*args|
23 args.unshift model_class_name
24 handle_drb_error(default_result) { @server.send method_name, *args }
28 def find_id_by_contents(q, options = {}, &proc)
29 total_hits, results = handle_drb_error([0, []]) { @server.find_id_by_contents(model_class_name, q, options) }
30 block_given? ? yield_results(total_hits, results, &proc) : [ total_hits, results ]
33 def id_multi_search(query, models, options, &proc)
34 total_hits, results = handle_drb_error([0, []]) { @server.id_multi_search(model_class_name, query, models, options) }
35 block_given? ? yield_results(total_hits, results, &proc) : [ total_hits, results ]
40 handle_drb_error { @server.add record.class.name, record.to_doc }
46 def handle_drb_error(return_value_in_case_of_error = false)
48 rescue DRb::DRbConnError => e
49 logger.error "DRb connection error: #{e}"
50 logger.warn e.backtrace.join("\n")
51 raise e if aaf_configuration[:raise_drb_errors]
52 return_value_in_case_of_error
55 def yield_results(total_hits, results)
56 results.each do |result|
57 yield result[:model], result[:id], result[:score], result[:data]
63 aaf_configuration[:class_name]