Commit b842cb40 authored by Nicolas Gelot's avatar Nicolas Gelot

Move search entry point in search module

parent 4b382c65
...@@ -24,6 +24,7 @@ import requests.exceptions ...@@ -24,6 +24,7 @@ import requests.exceptions
from flask_babel import gettext from flask_babel import gettext
import searx.poolrequests as requests_lib import searx.poolrequests as requests_lib
from searx import search_database
from searx import logger from searx import logger
from searx.answerers import ask from searx.answerers import ask
from searx.engines import ( from searx.engines import (
...@@ -34,6 +35,7 @@ from searx.plugins import plugins ...@@ -34,6 +35,7 @@ from searx.plugins import plugins
from searx.query import RawTextQuery, SearchQuery, VALID_LANGUAGE_CODE from searx.query import RawTextQuery, SearchQuery, VALID_LANGUAGE_CODE
from searx.results import ResultContainer from searx.results import ResultContainer
from searx.utils import gen_useragent from searx.utils import gen_useragent
from searx.plugins import plugins
from _thread import start_new_thread from _thread import start_new_thread
...@@ -266,6 +268,28 @@ def get_search_query_from_webapp(preferences, form): ...@@ -266,6 +268,28 @@ def get_search_query_from_webapp(preferences, form):
query_time_range) query_time_range)
def search(request, host):
""" Entry point to perform search request on engines
"""
search_query = get_search_query_from_webapp(request.preferences, request.form)
searchData = search_database.read(search_query, host)
if searchData is None:
result_container = Search(search_query).search()
searchData = search_database.get_search_data(search_query, result_container)
threading.Thread(
target=search_database.save,
args=(searchData, host),
name='save_search_' + str(searchData)
).start()
ordered_plugin = request.user_plugins
plugins.call(ordered_plugin, 'post_search', request, searchData)
for result in searchData.results:
plugins.call(ordered_plugin, 'on_result', request, searchData, result)
return searchData
class Search(object): class Search(object):
"""Search information container""" """Search information container"""
......
...@@ -7,7 +7,6 @@ import redis ...@@ -7,7 +7,6 @@ import redis
from searx import settings from searx import settings
from searx.plugins import plugins from searx.plugins import plugins
from searx.query import SearchQuery from searx.query import SearchQuery
from searx.search import Search, get_search_query_from_webapp
from searx.url_utils import urlparse from searx.url_utils import urlparse
...@@ -131,22 +130,6 @@ def get_search_data(q, r): ...@@ -131,22 +130,6 @@ def get_search_data(q, r):
r.infoboxes, r.suggestions, r.unresponsive_engines) r.infoboxes, r.suggestions, r.unresponsive_engines)
def search(request, host):
search_query = get_search_query_from_webapp(request.preferences, request.form)
searchData = read(search_query, host)
if searchData is None:
result_container = Search(search_query).search()
searchData = get_search_data(search_query, result_container)
threading.Thread(target=save, args=(searchData, host), name='save_search_' + str(searchData)).start()
ordered_plugin = request.user_plugins
plugins.call(ordered_plugin, 'post_search', request, searchData)
for result in searchData.results:
plugins.call(ordered_plugin, 'on_result', request, searchData, result)
return searchData
def update(d, host): def update(d, host):
conn = redis.StrictRedis(host) conn = redis.StrictRedis(host)
key = "SEARCH_HISTORY:{}:{}:{}:{}:{}:{}:{}".format( key = "SEARCH_HISTORY:{}:{}:{}:{}:{}:{}:{}".format(
......
...@@ -68,7 +68,7 @@ from searx.utils import ( ...@@ -68,7 +68,7 @@ from searx.utils import (
) )
from searx.version import VERSION_STRING from searx.version import VERSION_STRING
from searx.languages import language_codes as languages from searx.languages import language_codes as languages
from searx.search import Search from searx.search import Search, search
from searx.query import RawTextQuery from searx.query import RawTextQuery
from searx.autocomplete import searx_bang, backends as autocomplete_backends from searx.autocomplete import searx_bang, backends as autocomplete_backends
from searx.plugins import plugins from searx.plugins import plugins
...@@ -77,7 +77,7 @@ from searx.preferences import Preferences, ValidationException, LANGUAGE_CODES ...@@ -77,7 +77,7 @@ from searx.preferences import Preferences, ValidationException, LANGUAGE_CODES
from searx.answerers import answerers from searx.answerers import answerers
from searx.url_utils import urlencode, urlparse, urljoin from searx.url_utils import urlencode, urlparse, urljoin
from searx.utils import new_hmac from searx.utils import new_hmac
from searx.search_database import get_twenty_queries, search from searx.search_database import get_twenty_queries
import threading import threading
# check if the pyopenssl package is installed. # check if the pyopenssl package is installed.
......
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