diff --git a/static/style.css b/static/style.css index 0cb1231..89efeaf 100644 --- a/static/style.css +++ b/static/style.css @@ -75,6 +75,7 @@ body { margin: 0; font-family: sans-serif } } .search-result-url { clear:left; } .search-result-url a { color: #5a5; font-size: 8pt; float: left; margin-right: 1em;} +.search-result-links {color: #aaf; font-size: 8pt; float: left; margin-right: 1em} .search-result-date { color: #777; font-size: 8pt; float: right; margin-bottom: 7px; } .search-result-size { color: #777; font-size: 8pt; float: right; display: none; } .search-result-highlight { color: #7E1212; font-weight: bold; } diff --git a/views/result.tpl b/views/result.tpl index 4f3d1d7..0d91e80 100644 --- a/views/result.tpl +++ b/views/result.tpl @@ -11,7 +11,7 @@ %if len(d['ipath']) > 0:
[{{d['ipath']}}]
%end - %if d.has_key('author') and len(d['author']) > 0: + %if d.has_key('author') and len(d['author']) > 0:
{{d['author']}}
%end
@@ -21,6 +21,12 @@ %end {{urllabel}}
+%if hasrclextract: + +%end
{{d['time']}}
%for q in shlex.split(query['query'].replace("'","\\'")): %if not q == "OR": diff --git a/views/results.tpl b/views/results.tpl index bf65117..3d0db6b 100644 --- a/views/results.tpl +++ b/views/results.tpl @@ -16,7 +16,7 @@ %include pages query=query, config=config, nres=nres
%for i in range(0, len(res)): - %include result d=res[i], i=i, query=query, config=config, + %include result d=res[i], i=i, query=query, config=config, query_string=query_string, hasrclextract=hasrclextract %end
%include pages query=query, config=config, nres=nres diff --git a/webui.py b/webui.py index abad996..acda463 100755 --- a/webui.py +++ b/webui.py @@ -3,10 +3,15 @@ import os import bottle import time +import sys + try: from recoll import recoll + from recoll import rclextract + hasrclextract = True except: import recoll + hasrclextract = False import datetime import glob @@ -166,20 +171,28 @@ def query_to_recoll_string(q): qs += " dir:\"%s\" " % q['dir'] return qs #}}} -#{{{ recoll_search -def recoll_search(q): +#{{{ recoll_initsearch +def recoll_initsearch(q): config = get_config() - tstart = datetime.datetime.now() - results = [] db = recoll.connect(config['confdir']) db.setAbstractParams(config['maxchars'], config['context']) query = db.query() query.sortby(q['sort'], q['ascending']) try: qs = query_to_recoll_string(q) - nres = query.execute(qs, config['stem']) + query.execute(qs, config['stem']) except: - nres = 0 + pass + return query +#}}} +#{{{ recoll_search +def recoll_search(q): + config = get_config() + tstart = datetime.datetime.now() + results = [] + query = recoll_initsearch(q) + nres = query.rowcount + if config['maxresults'] == 0: config['maxresults'] = nres if nres > config['maxresults']: @@ -189,10 +202,12 @@ def recoll_search(q): q['page'] = 1 offset = (q['page'] - 1) * config['perpage'] - if type(query.next) == int: - query.next = offset - else: - query.scroll(offset) + if query.rowcount > 0: + if type(query.next) == int: + query.next = offset + else: + query.scroll(offset, mode='absolute') + for i in range(config['perpage']): try: doc = query.fetchone() @@ -208,7 +223,7 @@ def recoll_search(q): d['label'] = select([d['title'], d['filename'], '?'], [None, '']) d['sha'] = hashlib.sha1(d['url']+d['ipath']).hexdigest() d['time'] = timestr(d['mtime'], config['timefmt']) - d['snippet'] = db.makeDocAbstract(doc, query).encode('utf-8') + d['snippet'] = query.makedocabstract(doc).encode('utf-8') results.append(d) tend = datetime.datetime.now() return results, nres, tend - tstart @@ -241,8 +256,57 @@ def results(): if config['perpage'] == 0: config['perpage'] = nres return { 'res': res, 'time': timer, 'query': query, 'dirs': - get_dirs(config['dirs'], config['dirdepth']),'qs': qs, 'sorts': SORTS, 'config': config, - 'query_string': bottle.request.query_string, 'nres': nres } + get_dirs(config['dirs'], config['dirdepth']), + 'qs': qs, 'sorts': SORTS, 'config': config, + 'query_string': bottle.request.query_string, 'nres': nres, + 'hasrclextract': hasrclextract } +#}}} +#{{{ preview +@bottle.route('/preview/') +def preview(resnum): + if not hasrclextract: + return 'Sorry, needs recoll version 1.19 or later' + query = get_query() + qs = query_to_recoll_string(query) + rclq = recoll_initsearch(query) + if resnum > rclq.rowcount - 1: + return 'Bad result index %d' % resnum + rclq.scroll(resnum) + doc = rclq.fetchone() + xt = rclextract.Extractor(doc) + tdoc = xt.textextract(doc.ipath) + if tdoc.mimetype == 'text/html': + bottle.response.content_type = 'text/html; charset=utf-8' + else: + bottle.response.content_type = 'text/plain; charset=utf-8' + return tdoc.text +#}}} +#{{{ edit +@bottle.route('/edit/') +def edit(resnum): + if not hasrclextract: + return 'Sorry, needs recoll version 1.19 or later' + query = get_query() + qs = query_to_recoll_string(query) + rclq = recoll_initsearch(query) + if resnum > rclq.rowcount - 1: + return 'Bad result index %d' % resnum + rclq.scroll(resnum) + doc = rclq.fetchone() + bottle.response.content_type = doc.mimetype + # If ipath is null, we can just return the file + pathismine = False + if doc.ipath == '': + path = doc.url.replace('file://','') + else: + xt = rclextract.Extractor(doc) + path = xt.idoctofile(doc.ipath, doc.mimetype) + pathismine = True + print >> sys.stderr, "Sending %s with mimetype %s" % (path, doc.mimetype) + f = open(path, 'r') + if pathismine: + os.unlink(path) + return f #}}} #{{{ json @bottle.route('/json')