mirror of
https://github.com/koniu/recoll-webui.git
synced 2025-10-03 09:49:25 +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
19
webui.py
19
webui.py
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue