forked from Ponysearch/Ponysearch
[mod] searching by selected engines
This commit is contained in:
parent
d2a952ecdf
commit
70278567ec
2 changed files with 12 additions and 10 deletions
|
@ -97,20 +97,13 @@ def make_callback(engine_name, results, callback, params):
|
||||||
results[engine_name] = cb_res
|
results[engine_name] = cb_res
|
||||||
return process_callback
|
return process_callback
|
||||||
|
|
||||||
def search(query, request, selected_categories):
|
def search(query, request, selected_engines):
|
||||||
global engines, categories, number_of_searches
|
global engines, categories, number_of_searches
|
||||||
requests = []
|
requests = []
|
||||||
results = {}
|
results = {}
|
||||||
selected_engines = []
|
|
||||||
number_of_searches += 1
|
number_of_searches += 1
|
||||||
user_agent = request.headers.get('User-Agent', '')
|
user_agent = request.headers.get('User-Agent', '')
|
||||||
|
|
||||||
if not len(selected_categories):
|
|
||||||
selected_categories = ['general']
|
|
||||||
|
|
||||||
for categ in selected_categories:
|
|
||||||
selected_engines.extend({'category': categ, 'name': x.name} for x in categories[categ])
|
|
||||||
|
|
||||||
for selected_engine in selected_engines:
|
for selected_engine in selected_engines:
|
||||||
if selected_engine['name'] not in engines:
|
if selected_engine['name'] not in engines:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -65,6 +65,9 @@ def index():
|
||||||
request_data = request.args
|
request_data = request.args
|
||||||
if not request_data.get('q'):
|
if not request_data.get('q'):
|
||||||
return render('index.html')
|
return render('index.html')
|
||||||
|
|
||||||
|
query = request_data['q'].encode('utf-8')
|
||||||
|
|
||||||
selected_categories = []
|
selected_categories = []
|
||||||
for pd_name,pd in request_data.items():
|
for pd_name,pd in request_data.items():
|
||||||
if pd_name.startswith('category_'):
|
if pd_name.startswith('category_'):
|
||||||
|
@ -77,8 +80,14 @@ def index():
|
||||||
for ccateg in cookie_categories:
|
for ccateg in cookie_categories:
|
||||||
if ccateg in categories:
|
if ccateg in categories:
|
||||||
selected_categories.append(ccateg)
|
selected_categories.append(ccateg)
|
||||||
query = request_data['q'].encode('utf-8')
|
if not len(selected_categories):
|
||||||
results = search(query, request, selected_categories)
|
selected_categories = ['general']
|
||||||
|
|
||||||
|
selected_engines = []
|
||||||
|
for categ in selected_categories:
|
||||||
|
selected_engines.extend({'category': categ, 'name': x.name} for x in categories[categ])
|
||||||
|
|
||||||
|
results = search(query, request, selected_engines)
|
||||||
for result in results:
|
for result in results:
|
||||||
if len(result['url']) > 74:
|
if len(result['url']) > 74:
|
||||||
result['pretty_url'] = result['url'][:35] + '[..]' + result['url'][-35:]
|
result['pretty_url'] = result['url'][:35] + '[..]' + result['url'][-35:]
|
||||||
|
|
Loading…
Reference in a new issue