Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
* [sup-talk] [PATCH] Add a limit:<int> search operator to limit the number of results
@ 2008-11-16 17:17 Nicolas Pouillard
  2008-11-26 23:48 ` William Morgan
  0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Pouillard @ 2008-11-16 17:17 UTC (permalink / raw)


---
 lib/sup/index.rb |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/lib/sup/index.rb b/lib/sup/index.rb
index cda5cee..8af4edd 100644
--- a/lib/sup/index.rb
+++ b/lib/sup/index.rb
@@ -282,13 +282,15 @@ EOS
     query = build_query opts
     offset = 0
     while true
-      results = @index_mutex.synchronize { @index.search query, :sort => "date DESC", :limit => EACH_BY_DATE_NUM, :offset => offset }
+      limit = (opts[:limit])? [EACH_BY_DATE_NUM, opts[:limit] - offset].min : EACH_BY_DATE_NUM
+      results = @index_mutex.synchronize { @index.search query, :sort => "date DESC", :limit => limit, :offset => offset }
       Redwood::log "got #{results.total_hits} results for query (offset #{offset}) #{query.inspect}"
       results.hits.each do |hit|
         yield @index_mutex.synchronize { @index[hit.doc][:message_id] }, lambda { build_message hit.doc }
       end
-      break if offset >= results.total_hits - EACH_BY_DATE_NUM
-      offset += EACH_BY_DATE_NUM
+      break if opts[:limit] and offset >= opts[:limit] - limit
+      break if offset >= results.total_hits - limit
+      offset += limit
     end
   end
 
@@ -561,6 +563,18 @@ protected
       end
       subs = nil if chronic_failure
     end
+
+    ## limit:42 restrict the search to 42 results
+    subs = subs.gsub(/\blimit:(\S+)\b/) do
+      lim = $1
+      if lim =~ /^\d+$/
+        extraopts[:limit] = lim.to_i
+        ''
+      else
+        BufferManager.flash "Can't understand limit #{lim.inspect}!"
+        subs = nil
+      end
+    end
     
     if subs
       [@qparser.parse(subs), extraopts]
-- 
1.5.5.rc3



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [sup-talk] [PATCH] Add a limit:<int> search operator to limit the number of results
  2008-11-16 17:17 [sup-talk] [PATCH] Add a limit:<int> search operator to limit the number of results Nicolas Pouillard
@ 2008-11-26 23:48 ` William Morgan
  0 siblings, 0 replies; 2+ messages in thread
From: William Morgan @ 2008-11-26 23:48 UTC (permalink / raw)


Applied, thanks!
-- 
William <wmorgan-sup at masanjin.net>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-11-26 23:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-16 17:17 [sup-talk] [PATCH] Add a limit:<int> search operator to limit the number of results Nicolas Pouillard
2008-11-26 23:48 ` William Morgan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox