mirror of
https://github.com/searxng/searxng.git
synced 2024-11-19 02:40:11 +01:00
[enh] engine statistics
This commit is contained in:
parent
4ebf8389e8
commit
b8191f43e7
@ -67,6 +67,7 @@ for section in engines_config.sections():
|
|||||||
print '[E] Engine config error: Missing attribute "{0}.{1}"'.format(engine.name, engine_attr)
|
print '[E] Engine config error: Missing attribute "{0}.{1}"'.format(engine.name, engine_attr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
engines[engine.name] = engine
|
engines[engine.name] = engine
|
||||||
|
engine.stats = {'result_count': 0, 'search_count': 0}
|
||||||
if hasattr(engine, 'categories'):
|
if hasattr(engine, 'categories'):
|
||||||
for category_name in engine.categories:
|
for category_name in engine.categories:
|
||||||
categories.setdefault(category_name, []).append(engine)
|
categories.setdefault(category_name, []).append(engine)
|
||||||
@ -120,6 +121,9 @@ def search(query, request, selected_categories):
|
|||||||
)
|
)
|
||||||
requests.append(req)
|
requests.append(req)
|
||||||
grequests.map(requests)
|
grequests.map(requests)
|
||||||
|
for engine_name,engine_results in results.items():
|
||||||
|
engines[engine_name].stats['search_count'] += 1
|
||||||
|
engines[engine_name].stats['result_count'] += len(engine_results)
|
||||||
flat_res = filter(None, chain.from_iterable(izip_longest(*results.values())))
|
flat_res = filter(None, chain.from_iterable(izip_longest(*results.values())))
|
||||||
flat_len = len(flat_res)
|
flat_len = len(flat_res)
|
||||||
results = []
|
results = []
|
||||||
@ -150,3 +154,13 @@ def search(query, request, selected_categories):
|
|||||||
results.append(res)
|
results.append(res)
|
||||||
|
|
||||||
return sorted(results, key=itemgetter('score'), reverse=True)
|
return sorted(results, key=itemgetter('score'), reverse=True)
|
||||||
|
|
||||||
|
def get_engines_stats():
|
||||||
|
stats = {}
|
||||||
|
|
||||||
|
for engine in engines.values():
|
||||||
|
if engine.stats['search_count'] == 0:
|
||||||
|
continue
|
||||||
|
stats[engine.name] = {'Average number of results': engine.stats['result_count']/float(engine.stats['search_count'])}
|
||||||
|
|
||||||
|
return stats
|
||||||
|
Loading…
Reference in New Issue
Block a user