Commit d8c97adf authored by Nicolas Gelot's avatar Nicolas Gelot

Remove host parameter of all redis handlers

parent 4f251786
......@@ -185,18 +185,18 @@ def default_request_params():
}
def search(request, host):
def search(request):
""" Entry point to perform search request on engines
"""
search = Search()
search_query = search.get_search_query_from_webapp(request.preferences, request.form)
searchData = search_database.read(search_query, host)
searchData = search_database.read(search_query)
if searchData is None:
result_container = search.search(search_query)
searchData = search.create_search_data(search_query, result_container)
threading.Thread(
target=search_database.save,
args=(searchData, host),
args=(searchData,),
name='save_search_' + str(searchData)
).start()
......
......@@ -9,19 +9,19 @@ from searx.plugins import plugins
from searx.query import SearchQuery
from searx.url_utils import urlparse
from searx.results import SearchData
from searx import settings
def _get_connection(host):
host = host if host else settings['redis']['host']
return redis.StrictRedis(host=host, decode_responses=True)
def _get_connection(decode_responses=True):
return redis.StrictRedis(host=settings['redis']['host'], decode_responses=decode_responses)
def read(q, host):
def read(q):
time_range = q.time_range
if q.time_range is None:
q.time_range = ""
conn = _get_connection(host)
conn = _get_connection()
key = "SEARCH_HISTORY:{}:{}:{}:{}:{}:{}:{}".format(
e(q.query), je(q.engines), q.categories[0], q.lang, q.safesearch, q.pageno, time_range)
response = conn.hgetall(key)
......@@ -35,8 +35,8 @@ def read(q, host):
jds(response['suggestions']), jds(response['unresponsive_engines']))
def save(d, host):
conn = _get_connection(host)
def save(d):
conn = _get_connection()
key = "SEARCH_HISTORY:{}:{}:{}:{}:{}:{}:{}".format(
e(d.query), je(d.engines), d.categories[0], d.language, d.safe_search, d.pageno, d.time_range)
mapping = {
......@@ -50,10 +50,10 @@ def save(d, host):
conn.hmset(key, mapping)
def get_twenty_queries(x, host):
def get_twenty_queries(x):
result = []
conn = _get_connection(host)
conn = _get_connection()
keys = conn.zrange('SEARCH_HISTORY_KEYS', int(x), int(x) + 20)
if not keys:
return result
......@@ -93,8 +93,8 @@ def jds(coded):
return jd(coded)
def update(d, host):
conn = redis.StrictRedis(host)
def update(d):
conn = _get_connection(decode_responses=False)
key = "SEARCH_HISTORY:{}:{}:{}:{}:{}:{}:{}".format(
e(d.query), je(d.engines), d.categories[0], d.language, d.safe_search, d.pageno, d.time_range)
current = conn.hgetall(key)
......
......@@ -503,7 +503,7 @@ def index():
request.form['categories'] = ['general', 'videos', 'images']
else:
request.form['categories'] = [selected_category]
search_data = search(request, settings['redis']['host'])
search_data = search(request)
except Exception as e:
# log exception
......@@ -846,12 +846,11 @@ def update_results():
start_time = time.time()
x = 0
while not running.is_set():
host = settings['redis']['host']
queries = get_twenty_queries(x, host)
queries = get_twenty_queries(x)
for query in queries:
result_container = search.search(query)
searchData = search.create_search_data(query, result_container)
search_database.update(searchData, host)
search_database.update(searchData)
if running.is_set():
return
x += 20
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment