# HG changeset patch # User Tero Marttila # Date 1234396432 -7200 # Node ID f530c158aa079b57cc6e2a2f23e5792d40f9e233 # Parent f0b4097f5781538b28dec66c861cc463ebba75cc implement some basic search-targets for message and nickname diff -r f0b4097f5781 -r f530c158aa07 handlers.py --- 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, diff -r f0b4097f5781 -r f530c158aa07 log_search.py --- 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", diff -r f0b4097f5781 -r f530c158aa07 static/irclogs.css --- 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 { diff -r f0b4097f5781 -r f530c158aa07 templates/channel_search.tmpl --- 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 @@