--- a/handlers.py Thu Feb 12 00:57:39 2009 +0200
+++ b/handlers.py Thu Feb 12 01:53:52 2009 +0200
@@ -20,7 +20,7 @@
)
# return a http.Response for the given text in the given format
-def _render_type (request, channel, lines, type) :
+def _render_type (request, channel, lines, type, full_timestamps=False) :
"""
Render the given LogLines as a http.Response in the given format, which is one of:
html - XXX: not supported
@@ -38,7 +38,7 @@
elif type == 'txt' :
# plaintext
- lines = formatter.format_txt(lines)
+ lines = formatter.format_txt(lines, full_timestamps)
# build data
data = '\n'.join(data for line, data in lines)
@@ -47,13 +47,13 @@
elif type == 'png' :
# PNG image
- png_data = formatter.format_png(lines)
+ png_data = formatter.format_png(lines, full_timestamps)
return http.Response(png_data, 'image/png', charset=None)
elif type == 'rss' :
# RSS feed
- rss_data = formatter.format_rss(lines)
+ rss_data = formatter.format_rss(lines, full_timestamps)
# XXX: fix to render as unicode?
return http.Response(rss_data, 'application/rss+xml', charset=None)
@@ -224,7 +224,7 @@
return _render_date (request, channel, date, lines, type, count, page, max)
@preferences.handler(prefs.formatter, prefs.count)
-def channel_search (request, channel, formatter, count, q=None, page=1, max=1, type=None) :
+def channel_search (request, channel, formatter, count, q=None, page=1, max=1, type=None, t=None) :
"""
Display the search form for the channel for GET, or do the search for POST.
"""
@@ -234,9 +234,12 @@
# got a search query?
if q :
+ # attribute targets
+ targets = dict(('search_%s' % target, True) for target in t if target in ('msg', 'nick')) if t else {}
+
try :
# do search
- lines = log_search.get_index().search_simple(channel, q, count, skip)
+ lines = log_search.get_index().search_simple(channel, q, count, skip, **targets)
# update max?
if max and page > max :
@@ -253,7 +256,7 @@
# type?
if type and lines :
# special type
- return _render_type(request, channel, lines, type)
+ return _render_type(request, channel, lines, type, full_timestamps=True)
else :
# format lines to HTML if any
@@ -267,6 +270,7 @@
prefs = request.prefs,
channel = channel,
search_query = q,
+ search_targets = t,
count = count,
page = page,
skip = skip,
--- a/log_search.py Thu Feb 12 00:57:39 2009 +0200
+++ b/log_search.py Thu Feb 12 01:53:52 2009 +0200
@@ -242,16 +242,16 @@
if channel :
# add channel attribute
- cond.add_attr("channel STREQ %s" % (channel.id, ))
+ cond.add_attr(("channel STREQ %s" % channel.id).encode('utf8'))
if attrs :
# add attributes
for attr in attrs :
- cond.add_attr(attr)
+ cond.add_attr(attr.encode('utf8'))
if phrase :
# add phrase
- cond.set_phrase(phrase)
+ cond.set_phrase(phrase.encode('utf8'))
if order :
# set order
@@ -268,11 +268,22 @@
# execute
return self.search_cond(cond)
- def search_simple (self, channel, query, count=None, offset=None) :
+ def search_simple (self, channel, query, count=None, offset=None, search_msg=True, search_nick=False) :
"""
- Search for lines from the given channel for the given simple query
+ Search for lines from the given channel for the given simple query.
+
+ The search_* params define which attributes to search for (using fulltext search for the message, STROR for
+ attributes).
"""
+ # search attributes
+ attrs = []
+
+ # nickname target query
+ if search_nick :
+ attrs.append("source_nickname STRINC %s" % query)
+# attrs.append("target_nickname STRINC %s" % query)
+
# use search(), backwards
results = list(self.search(
# simplified phrase
@@ -282,7 +293,10 @@
channel = channel,
# given phrase
- phrase = query,
+ phrase = query if search_msg else None,
+
+ # attributes defined above
+ attrs = attrs,
# order by timestamp, descending (backwards)
order = "timestamp NUMD",
--- a/static/irclogs.css Thu Feb 12 00:57:39 2009 +0200
+++ b/static/irclogs.css Thu Feb 12 01:53:52 2009 +0200
@@ -278,7 +278,7 @@
}
/* Search form */
-div#search {
+div#search-form {
padding: 25px;
text-align: center;
@@ -292,8 +292,11 @@
}
+div#search div.indent {
+ margin-left: 8.5em;
+}
+
div#search-help {
- text-align: left;
}
div#search-error {
--- a/templates/channel_search.tmpl Thu Feb 12 00:57:39 2009 +0200
+++ b/templates/channel_search.tmpl Thu Feb 12 01:53:52 2009 +0200
@@ -6,12 +6,21 @@
<div id="search">
<form action="${h.build_url(urls.channel_search, channel=channel)}" method="GET">
- <input type="text" name="q" />
- <input type="submit" value="Search" />
+
+ <div id="search-form">
+ <input type="text" name="q" />
+ <input type="submit" value="Search" />
+ </div>
- Results/page: <select name="count">
+<p>
+ <label for="count">Results/page:</label>
+ <select name="count">
${h.select_options(((cc, cc_label) for cc, cc_label in config.SEARCH_LINE_COUNT_OPTIONS), count)}
</select>
+</p>
+ <label for="t">Search in:</label><br/>
+ <div class="indent"><input type="radio" name="t" value="msg" checked="checked" /> Messages</div>
+ <div class="indent"><input type="radio" name="t" value="nick" /> Nicknames</div>
</form>
<div id="search-help">
@@ -30,11 +39,11 @@
% else :
<div id="title">${channel.title} :: Search '${search_query}'</div>
-${paginate(urls.channel_search, count, page, max, channel=channel, q=search_query, _more=True, _last=not(bool(lines)))}
+${paginate(urls.channel_search, count, page, max, channel=channel, q=search_query, t=search_targets, _more=True, _last=not(bool(lines)))}
% if lines :
<%include file="lines.tmpl" />
% else :
<div id="search-error">No results found</div>
% endif
-${paginate(urls.channel_search, count, page, max, channel=channel, q=search_query, _more=True, _last=not(bool(lines)))}
+${paginate(urls.channel_search, count, page, max, channel=channel, q=search_query, t=search_targets, _more=True, _last=not(bool(lines)))}
% endif
--- a/urls.py Thu Feb 12 00:57:39 2009 +0200
+++ b/urls.py Thu Feb 12 01:53:52 2009 +0200
@@ -39,7 +39,7 @@
channel_link = url('/channels/{channel:cid}/link/{timestamp:ts}/?type=', handlers.channel_link )
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}/?page:int=1&type=', handlers.channel_date )
-channel_search = url('/channels/{channel:cid}/search/?q=&page:int=1&max:int=1&type=', handlers.channel_search )
+channel_search = url('/channels/{channel:cid}/search/?q=&page:int=1&max:int=1&type=&t:list=', handlers.channel_search )
# mapper
mapper = urltree.URLTree(urls)