Commit 66321af8 authored by Jean-Francois Dockes's avatar Jean-Francois Dockes Committed by koniu
Browse files

Let the user choose the fields included for CSV extraction

parent 967590b6
......@@ -22,6 +22,9 @@
<small>{{d}}</small><input name="mount_{{d}}" value={{mounts[d]}}>
%end
<hr>
<b>CSV fields</b> <small class="gray">({{fields}})</small><br>
<input name="csvfields" value="{{csvfields}}">
<hr>
<b>Add to browser</b>
<br>
<a href="#" onClick="addOpenSearch();return false">Register recoll into browser search engines</a>
......
......@@ -38,6 +38,7 @@ DEFAULTS = {
'maxchars': 500,
'maxresults': 0,
'perpage': 25,
'csvfields': 'filename title author size time mtype url',
}
# sort fields/labels
......@@ -111,6 +112,11 @@ def get_config():
for k, v in DEFAULTS.items():
value = select([bottle.request.get_cookie(k), v])
config[k] = type(v)(value)
# Fix csvfields: get rid of invalid ones to avoid needing tests in the dump function
cf = config['csvfields'].split()
ncf = [f for f in cf if f in FIELDS]
config['csvfields'] = ' '.join(ncf)
config['fields'] = ' '.join(FIELDS)
# get mountpoints
config['mounts'] = {}
for d in config['dirs']:
......@@ -175,7 +181,7 @@ class HlMeths:
return '</span>'
#}}}
#{{{ recoll_search
def recoll_search(q):
def recoll_search(q, dosnippets=True):
config = get_config()
tstart = datetime.datetime.now()
results = []
......@@ -213,7 +219,8 @@ 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'] = query.makedocabstract(doc, highlighter).encode('utf-8')
if dosnippets:
d['snippet'] = query.makedocabstract(doc, highlighter).encode('utf-8')
results.append(d)
tend = datetime.datetime.now()
return results, nres, tend - tstart
......@@ -317,18 +324,20 @@ def get_json():
#{{{ csv
@bottle.route('/csv')
def get_csv():
config = get_config()
query = get_query()
query['page'] = 0
qs = query_to_recoll_string(query)
bottle.response.headers['Content-Type'] = 'text/csv'
bottle.response.headers['Content-Disposition'] = 'attachment; filename=recoll-%s.csv' % normalise_filename(qs)
res, nres, timer = recoll_search(query)
res, nres, timer = recoll_search(query, False)
si = StringIO.StringIO()
cw = csv.writer(si)
cw.writerow(FIELDS)
fields = config['csvfields'].split()
cw.writerow(fields)
for doc in res:
row = []
for f in FIELDS:
for f in fields:
row.append(doc[f])
cw.writerow(row)
return si.getvalue().strip("\r\n")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment