]> git.cworth.org Git - sup/blobdiff - lib/sup/modes/search-results-mode.rb
Allow thread index view to sort oldest first
[sup] / lib / sup / modes / search-results-mode.rb
index 6fdc58a0c9da1f0df907ce8e29d786a36db9b4d7..da03b5125e7c6c1f02e99dd226707e59a2a2428b 100644 (file)
@@ -1,11 +1,10 @@
 module Redwood
 
 class SearchResultsMode < ThreadIndexMode
-  def initialize qobj, qopts = nil
-    @qobj = qobj
-    @qopts = qopts
-
-    super [], { :qobj => @qobj }.merge(@qopts)
+  def initialize query, newest_first
+    @query = query
+    super [], query
+    @newest_first = newest_first
   end
 
   register_keymap do |k|
@@ -13,9 +12,9 @@ class SearchResultsMode < ThreadIndexMode
   end
 
   def refine_search
-    query = BufferManager.ask :search, "refine query: ", (@qobj.to_s + " ")
-    return unless query && query !~ /^\s*$/
-    SearchResultsMode.spawn_from_query query
+    text = BufferManager.ask :search, "refine query: ", (@query[:text] + " ")
+    return unless text && text !~ /^\s*$/
+    SearchResultsMode.spawn_from_query text, @newest_first
   end
 
   ## a proper is_relevant? method requires some way of asking ferret
@@ -24,16 +23,16 @@ class SearchResultsMode < ThreadIndexMode
   ## the message, and search against it to see if i have > 0 results,
   ## but that seems pretty insane.
 
-  def self.spawn_from_query text
+  def self.spawn_from_query text, newest_first
     begin
-      qobj, extraopts = Index.parse_user_query_string(text)
-      return unless qobj
+      query = Index.parse_query(text)
+      return unless query
       short_text = text.length < 20 ? text : text[0 ... 20] + "..."
-      mode = SearchResultsMode.new qobj, extraopts
+      mode = SearchResultsMode.new query, newest_first
       BufferManager.spawn "search: \"#{short_text}\"", mode
       mode.load_threads :num => mode.buffer.content_height
-    rescue Ferret::QueryParser::QueryParseException => e
-      BufferManager.flash "Couldn't parse query."
+    rescue Index::ParseError => e
+      BufferManager.flash "Problem: #{e.message}!"
     end
   end
 end