]> git.cworth.org Git - sup/blob - lib/sup/modes/search-results-mode.rb
Allow thread index view to sort oldest first
[sup] / lib / sup / modes / search-results-mode.rb
1 module Redwood
2
3 class SearchResultsMode < ThreadIndexMode
4   def initialize query, newest_first
5     @query = query
6     super [], query
7     @newest_first = newest_first
8   end
9
10   register_keymap do |k|
11     k.add :refine_search, "Refine search", '|'
12   end
13
14   def refine_search
15     text = BufferManager.ask :search, "refine query: ", (@query[:text] + " ")
16     return unless text && text !~ /^\s*$/
17     SearchResultsMode.spawn_from_query text, @newest_first
18   end
19
20   ## a proper is_relevant? method requires some way of asking ferret
21   ## if an in-memory object satisfies a query. i'm not sure how to do
22   ## that yet. in the worst case i can make an in-memory index, add
23   ## the message, and search against it to see if i have > 0 results,
24   ## but that seems pretty insane.
25
26   def self.spawn_from_query text, newest_first
27     begin
28       query = Index.parse_query(text)
29       return unless query
30       short_text = text.length < 20 ? text : text[0 ... 20] + "..."
31       mode = SearchResultsMode.new query, newest_first
32       BufferManager.spawn "search: \"#{short_text}\"", mode
33       mode.load_threads :num => mode.buffer.content_height
34     rescue Index::ParseError => e
35       BufferManager.flash "Problem: #{e.message}!"
36     end
37   end
38 end
39
40 end