From: William Morgan Date: Mon, 18 May 2009 17:25:52 +0000 (-0400) Subject: make a Index#run_query method, update sup-tweak-labels X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=68ca1fc9130ea7714412a7b381159e4b3dd711d9;p=sup 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. --- diff --git a/bin/sup-tweak-labels b/bin/sup-tweak-labels index 0beb77e..b717359 100755 --- 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 index 8c9ddc8..44ecb8b 100644 --- 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