3 class SearchResultsMode < ThreadIndexMode
4 def initialize query, newest_first
7 @newest_first = newest_first
10 register_keymap do |k|
11 k.add :refine_search, "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
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.
26 def self.spawn_from_query text, newest_first
28 query = Index.parse_query(text)
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}!"