]> git.cworth.org Git - sup/blobdiff - bin/sup-tweak-labels
remove use of Object#tap
[sup] / bin / sup-tweak-labels
index 8a8152d60b18db9c0a0dcfd45637e9070ece1293..8ae5c26f9054c841ad612bdaf29c79f300cab753 100755 (executable)
@@ -2,6 +2,7 @@
 
 require 'rubygems'
 require 'trollop'
+require 'enumerator'
 require "sup"
 
 class Float
@@ -65,10 +66,10 @@ begin
 
   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?
@@ -81,19 +82,17 @@ begin
   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
@@ -122,7 +121,7 @@ begin
 
   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