3 class SearchResultsMode < ThreadIndexMode
4 def initialize qobj, qopts = nil
8 super [], { :qobj => @qobj }.merge(@qopts)
11 register_keymap do |k|
12 k.add :refine_search, "Refine search", '.'
16 query = BufferManager.ask :search, "query: ", (@qobj.to_s + " ")
17 return unless query && query !~ /^\s*$/
18 SearchResultsMode.spawn_from_query query, @qopts
21 ## a proper is_relevant? method requires some way of asking ferret
22 ## if an in-memory object satisfies a query. i'm not sure how to do
23 ## that yet. in the worst case i can make an in-memory index, add
24 ## the message, and search against it to see if i have > 0 results,
25 ## but that seems pretty insane.
27 def self.spawn_from_query text
29 qobj, extraopts = Index.parse_user_query_string(text)
31 short_text = text.length < 20 ? text : text[0 ... 20] + "..."
32 mode = SearchResultsMode.new qobj, extraopts
33 BufferManager.spawn "search: \"#{short_text}\"", mode
34 mode.load_threads :num => mode.buffer.content_height
35 rescue Ferret::QueryParser::QueryParseException => e
36 BufferManager.flash "Couldn't parse query."