mirror of
https://github.com/koniu/recoll-webui.git
synced 2025-10-06 03:50:09 +02:00
Let the user choose the fields included for CSV extraction
This commit is contained in:
parent
967590b620
commit
66321af8a3
2 changed files with 17 additions and 5 deletions
|
@ -22,6 +22,9 @@
|
||||||
<small>{{d}}</small><input name="mount_{{d}}" value={{mounts[d]}}>
|
<small>{{d}}</small><input name="mount_{{d}}" value={{mounts[d]}}>
|
||||||
%end
|
%end
|
||||||
<hr>
|
<hr>
|
||||||
|
<b>CSV fields</b> <small class="gray">({{fields}})</small><br>
|
||||||
|
<input name="csvfields" value="{{csvfields}}">
|
||||||
|
<hr>
|
||||||
<b>Add to browser</b>
|
<b>Add to browser</b>
|
||||||
<br>
|
<br>
|
||||||
<a href="#" onClick="addOpenSearch();return false">Register recoll into browser search engines</a>
|
<a href="#" onClick="addOpenSearch();return false">Register recoll into browser search engines</a>
|
||||||
|
|
17
webui.py
17
webui.py
|
@ -38,6 +38,7 @@ DEFAULTS = {
|
||||||
'maxchars': 500,
|
'maxchars': 500,
|
||||||
'maxresults': 0,
|
'maxresults': 0,
|
||||||
'perpage': 25,
|
'perpage': 25,
|
||||||
|
'csvfields': 'filename title author size time mtype url',
|
||||||
}
|
}
|
||||||
|
|
||||||
# sort fields/labels
|
# sort fields/labels
|
||||||
|
@ -111,6 +112,11 @@ def get_config():
|
||||||
for k, v in DEFAULTS.items():
|
for k, v in DEFAULTS.items():
|
||||||
value = select([bottle.request.get_cookie(k), v])
|
value = select([bottle.request.get_cookie(k), v])
|
||||||
config[k] = type(v)(value)
|
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
|
# get mountpoints
|
||||||
config['mounts'] = {}
|
config['mounts'] = {}
|
||||||
for d in config['dirs']:
|
for d in config['dirs']:
|
||||||
|
@ -175,7 +181,7 @@ class HlMeths:
|
||||||
return '</span>'
|
return '</span>'
|
||||||
#}}}
|
#}}}
|
||||||
#{{{ recoll_search
|
#{{{ recoll_search
|
||||||
def recoll_search(q):
|
def recoll_search(q, dosnippets=True):
|
||||||
config = get_config()
|
config = get_config()
|
||||||
tstart = datetime.datetime.now()
|
tstart = datetime.datetime.now()
|
||||||
results = []
|
results = []
|
||||||
|
@ -213,6 +219,7 @@ def recoll_search(q):
|
||||||
d['label'] = select([d['title'], d['filename'], '?'], [None, ''])
|
d['label'] = select([d['title'], d['filename'], '?'], [None, ''])
|
||||||
d['sha'] = hashlib.sha1(d['url']+d['ipath']).hexdigest()
|
d['sha'] = hashlib.sha1(d['url']+d['ipath']).hexdigest()
|
||||||
d['time'] = timestr(d['mtime'], config['timefmt'])
|
d['time'] = timestr(d['mtime'], config['timefmt'])
|
||||||
|
if dosnippets:
|
||||||
d['snippet'] = query.makedocabstract(doc, highlighter).encode('utf-8')
|
d['snippet'] = query.makedocabstract(doc, highlighter).encode('utf-8')
|
||||||
results.append(d)
|
results.append(d)
|
||||||
tend = datetime.datetime.now()
|
tend = datetime.datetime.now()
|
||||||
|
@ -317,18 +324,20 @@ def get_json():
|
||||||
#{{{ csv
|
#{{{ csv
|
||||||
@bottle.route('/csv')
|
@bottle.route('/csv')
|
||||||
def get_csv():
|
def get_csv():
|
||||||
|
config = get_config()
|
||||||
query = get_query()
|
query = get_query()
|
||||||
query['page'] = 0
|
query['page'] = 0
|
||||||
qs = query_to_recoll_string(query)
|
qs = query_to_recoll_string(query)
|
||||||
bottle.response.headers['Content-Type'] = 'text/csv'
|
bottle.response.headers['Content-Type'] = 'text/csv'
|
||||||
bottle.response.headers['Content-Disposition'] = 'attachment; filename=recoll-%s.csv' % normalise_filename(qs)
|
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()
|
si = StringIO.StringIO()
|
||||||
cw = csv.writer(si)
|
cw = csv.writer(si)
|
||||||
cw.writerow(FIELDS)
|
fields = config['csvfields'].split()
|
||||||
|
cw.writerow(fields)
|
||||||
for doc in res:
|
for doc in res:
|
||||||
row = []
|
row = []
|
||||||
for f in FIELDS:
|
for f in fields:
|
||||||
row.append(doc[f])
|
row.append(doc[f])
|
||||||
cw.writerow(row)
|
cw.writerow(row)
|
||||||
return si.getvalue().strip("\r\n")
|
return si.getvalue().strip("\r\n")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue