add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
--- a/handlers.py Mon Feb 09 11:46:17 2009 +0200
+++ b/handlers.py Mon Feb 09 12:07:01 2009 +0200
@@ -155,7 +155,7 @@
)
@preferences.handler(prefs.formatter)
-def channel_search (request, channel, formatter, q=None) :
+def channel_search (request, channel, formatter, q=None, count=None, skip=None) :
"""
Display the search form for the channel for GET, or do the search for POST
"""
@@ -163,7 +163,7 @@
# got a search query?
if q :
# do search
- lines = search_index.search_simple(channel, q)
+ lines = search_index.search_simple(channel, q, count, skip)
# format
lines = formatter.format_html(lines, full_timestamps=True)
--- a/log_search.py Mon Feb 09 11:46:17 2009 +0200
+++ b/log_search.py Mon Feb 09 12:07:01 2009 +0200
@@ -122,32 +122,76 @@
source = doc.attr('@source')
data = doc.cat_texts().decode('utf8')
- # build+yield to (channel_id, LogLine) tuple
- yield (channel_id, log_line.LogLine(None, type, timestamp, source, data))
+ # build+yield to as LogLine
+ # XXX: ignore channel_id for now
+ yield log_line.LogLine(None, type, timestamp, source, data)
+
+ def search (self, options=None, channel=None, phrase=None, order=None, max=None, skip=None) :
+ """
+ Search with flexible parameters
- def search_simple (self, channel, query) :
- """
- Search for lines from the given channel for the given simple query
+ options - bitmask of hype.Condition.*
+ channel - LogChannel object
+ phrase - the search query phrase
+ order - order attribute expression
+ max - number of results to return
+ skip - number of results to skip
"""
# build condition
cond = hype.Condition()
-
- # simplified phrase
- cond.set_options(hype.Condition.SIMPLE)
-
- # add channel attribute
- cond.add_attr("@channel STREQ %s" % (channel.id, ))
+
+ if options :
+ # set options
+ cond.set_options(options)
+
+ if channel :
+ # add channel attribute
+ cond.add_attr("@channel STREQ %s" % (channel.id, ))
+
+ if phrase :
+ # add phrase
+ cond.set_phrase(phrase)
+
+ if order :
+ # set order
+ cond.set_order(order)
+
+ if max :
+ # set max
+ cond.set_max(max)
- # add phrase
- cond.set_phrase(query)
-
- # set order
- cond.set_order("@timestamp NUMA")
+ if skip :
+ # set skip
+ cond.set_skip(skip)
- # search with cond
- for channel_id, line in self.search_cond(cond) :
- assert channel_id == channel.id
+ # execute
+ return self.search_cond(cond)
- yield line
+ def search_simple (self, channel, query, count=None, offset=None) :
+ """
+ Search for lines from the given channel for the given simple query
+ """
+
+ # use search(), backwards
+ results = list(self.search(
+ # simplified phrase
+ options = hype.Condition.SIMPLE,
+ # specific channel
+ channel = channel,
+
+ # given phrase
+ phrase = query,
+
+ # order by timestamp
+ order = "@timestamp NUMD",
+
+ # count/offset
+ max = count,
+ skip = offset,
+ ))
+
+ # reverse
+ return reversed(results)
+
--- a/urls.py Mon Feb 09 11:46:17 2009 +0200
+++ b/urls.py Mon Feb 09 12:07:01 2009 +0200
@@ -34,7 +34,7 @@
channel_last = url('/channels/{channel:cid}/last/{count:int=100}/{format=html}', handlers.channel_last )
channel_calendar = url('/channels/{channel:cid}/calendar/{year:int=0}/{month:int=0}', handlers.channel_calendar )
channel_date = url('/channels/{channel:cid}/date/{date:date}', handlers.channel_date )
-channel_search = url('/channels/{channel:cid}/search/?q=', handlers.channel_search )
+channel_search = url('/channels/{channel:cid}/search/?q=&count:int=&skip:int=', handlers.channel_search )
# mapper
mapper = urltree.URLTree(urls)