require 'rubygems'
require 'trollop'
+require 'enumerator'
require "sup"
class Float
source_ids =
if opts[:all_sources]
- index.sources
+ Redwood::SourceManager.sources
else
ARGV.map do |uri|
- index.source_for uri or Trollop::die "Unknown source: #{uri}. Did you add it with sup-add first?"
+ Redwood::SourceManager.source_for uri or Trollop::die "Unknown source: #{uri}. Did you add it with sup-add first?"
end
end.map { |s| s.id }
Trollop::die "nothing to do: no sources" if source_ids.empty?
end
query += ' ' + opts[:query] if opts[:query]
- qobj, opts = Redwood::Index.parse_user_query_string query
- query = Redwood::Index.build_query opts.merge(:qobj => qobj)
-
- results = index.ferret.search query, :limit => :all
- num_total = results.total_hits
+ parsed_query = index.parse_query query
+ parsed_query.merge! :load_spam => true, :load_deleted => true, :load_killed => true
+ ids = Enumerable::Enumerator.new(index, :each_id, parsed_query).map
+ num_total = ids.size
$stderr.puts "Found #{num_total} documents across #{source_ids.length} sources. Scanning..."
num_changed = num_scanned = 0
last_info_time = start_time = Time.now
- results.hits.each do |hit|
+ ids.each do |id|
num_scanned += 1
- id = hit.doc
m = index.build_message id
old_labels = m.labels.clone
unless num_changed == 0
$stderr.puts "Optimizing index..."
- index.ferret.optimize unless opts[:dry_run]
+ index.optimize unless opts[:dry_run]
end
rescue Exception => e