Revision d1f014733b6a7c880fcc2211ef96d012582568d8 authored by Robert Newson on 17 March 2009, 00:09:33 UTC, committed by Robert Newson on 17 March 2009, 00:09:33 UTC
1 parent 521cc62
federation.rb
#!/usr/bin/ruby
require 'net/http'
require 'json'
servers = %w(localhost localhost)
result = {}
threads=[]
for server in servers
threads << Thread.new(server) do |url|
h = Net::HTTP.new(url, 5984)
resp = h.get('/' + ARGV[0] + '/_fti?' + ARGV[1])
json = JSON.parse(resp.body)
if (!result.has_key?('q')) then
result = json
else
# Accounting
result['total_rows'] += json['total_rows']
# Merge in new rows
result['rows'].concat json['rows']
if json.has_key?('sort_order')
result['rows'].sort!{|a,b| a['sort_order'] <=> b['sort_order']}
else
result['rows'].sort!{|b,a| [a['score'],a['_id']] <=> [b['score'],b['_id']]}
end
# Drop extraneous rows.
result['rows'].slice!(result['limit']..result['rows'].size)
end
end
end
# Wait for all responses
threads.each{|thr| thr.join}
puts JSON.generate result
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...