]> git.cworth.org Git - sup/commitdiff
make a Index#run_query method, update sup-tweak-labels
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 18 May 2009 17:25:52 +0000 (13:25 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 18 May 2009 17:25:52 +0000 (13:25 -0400)
Index#run_query is now a way of running a query through Sup's
query-parsing and execution framework without being in a
curses context.

bin/sup-tweak-labels
lib/sup/index.rb

index 0beb77e2c57858f03d7b33e59c23ca5dadd8d5e9..b71735922bf60f1e364a543a058ab038ca4c13d4 100755 (executable)
@@ -79,19 +79,15 @@ 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
+  docs = Redwood::Index.run_query query
+  num_total = docs.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|
+  docs.each do |id|
     num_scanned += 1
-    id = hit.doc
 
     m = index.build_message id
     old_labels = m.labels.clone
index 8c9ddc86a1092b385885abcf7bf4f1d31361843a..44ecb8bb8549afc3b494a48b347fe1e7877b582e 100644 (file)
@@ -483,6 +483,19 @@ EOS
     @index_mutex.synchronize { @index.search(q, :limit => 1).total_hits > 0 }
   end
 
+  ## takes a user query string and returns the list of docids for messages
+  ## that match the query.
+  ##
+  ## messages can then be loaded from the index with #build_message.
+  ##
+  ## raises a ParseError if the parsing failed.
+  def run_query query
+    qobj, opts = Redwood::Index.parse_user_query_string query
+    query = Redwood::Index.build_query opts.merge(:qobj => qobj)
+    results = @index.search query, :limit => (opts[:limit] || :all)
+    results.hits.map { |hit| hit.doc }
+  end
+
 protected
 
   class ParseError < StandardError; end