From: nicolas.pouillard@gmail.com (Nicolas Pouillard)
Subject: [sup-talk] [PATCH] Add a limit:<int> search operator to limit the number of results
Date: Sun, 16 Nov 2008 18:17:59 +0100 [thread overview]
Message-ID: <1226855879-69629-1-git-send-email-nicolas.pouillard@gmail.com> (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
next reply other threads:[~2008-11-16 17:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-16 17:17 Nicolas Pouillard [this message]
2008-11-26 23:48 ` William Morgan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1226855879-69629-1-git-send-email-nicolas.pouillard@gmail.com \
--to=nicolas.pouillard@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox