commit 68ca1fc9130ea7714412a7b381159e4b3dd711d9
parent f35f205192ee39133633457c652e0c05a45386c9
Author: William Morgan <wmorgan-sup@masanjin.net>
Date: Mon, 18 May 2009 13:25:52 -0400
make a Index#run_query method, update sup-tweak-labels
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.
Diffstat:
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/bin/sup-tweak-labels b/bin/sup-tweak-labels
@@ -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
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
@@ -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