summaryrefslogtreecommitdiff
path: root/searx/engines/__init__.py
diff options
context:
space:
mode:
authorasciimoo <asciimoo@gmail.com>2013-11-10 21:16:25 +0100
committerasciimoo <asciimoo@gmail.com>2013-11-10 21:16:25 +0100
commit6d956a7d1de6f213ad32044e1d1074cf0aab7219 (patch)
tree7a977ec62fbf72c5e5e95a836c4801c349575a93 /searx/engines/__init__.py
parent36fd51227806927db5c452f6c08eadc24a90d487 (diff)
downloadsearxng-6d956a7d1de6f213ad32044e1d1074cf0aab7219.tar.gz
searxng-6d956a7d1de6f213ad32044e1d1074cf0aab7219.zip
[enh] engine score weight support @ config and engines
Diffstat (limited to 'searx/engines/__init__.py')
-rw-r--r--searx/engines/__init__.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py
index 14d688c6d..2abf1610c 100644
--- a/searx/engines/__init__.py
+++ b/searx/engines/__init__.py
@@ -51,20 +51,20 @@ if not engines_config.sections():
print '[E] Error no engines found. Edit your engines.cfg'
exit(2)
-for section in engines_config.sections():
- engine_data = engines_config.options(section)
- engine = load_module(engines_config.get(section, 'engine')+'.py')
- engine.name = section
+for engine_config_name in engines_config.sections():
+ engine_data = engines_config.options(engine_config_name)
+ engine = load_module(engines_config.get(engine_config_name, 'engine')+'.py')
+ engine.name = engine_config_name
for param_name in engine_data:
if param_name == 'engine':
continue
if param_name == 'categories':
- if engines_config.get(section, param_name) == 'none':
+ if engines_config.get(engine_config_name, param_name) == 'none':
engine.categories = []
else:
- engine.categories = map(str.strip, engines_config.get(section, param_name).split(','))
+ engine.categories = map(str.strip, engines_config.get(engine_config_name, param_name).split(','))
continue
- setattr(engine, param_name, engines_config.get(section, param_name))
+ setattr(engine, param_name, engines_config.get(engine_config_name, param_name))
for engine_attr in dir(engine):
if engine_attr.startswith('_'):
continue
@@ -161,7 +161,12 @@ def search(query, request, selected_engines):
for i,res in enumerate(flat_res):
res['parsed_url'] = urlparse(res['url'])
res['engines'] = [res['engine']]
- score = int((flat_len - i)/engines_len)*settings.weights.get(res['engine'], 1)+1
+ weight = 1.0
+ if hasattr(engines[res['engine']], 'weight'):
+ weight = float(engines[res['engine']].weight)
+ elif res['engine'] in settings.weights:
+ weight = float(settings.weights[res['engine']])
+ score = int((flat_len - i)/engines_len)*weight+1
duplicated = False
for new_res in results:
p1 = res['parsed_url'].path[:-1] if res['parsed_url'].path.endswith('/') else res['parsed_url'].path