Changeset View
Changeset View
Standalone View
Standalone View
swh/search/api/server.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import logging | import logging | ||||
import os | import os | ||||
from swh.core import config | from swh.core import config | ||||
from swh.core.api import RPCServerApp, error_handler, encode_data_server as encode_data | from swh.core.api import RPCServerApp, error_handler, encode_data_server as encode_data | ||||
from .. import get_search | from .. import get_search | ||||
from ..elasticsearch import ElasticSearch | from ..interface import SearchInterface | ||||
def _get_search(): | def _get_search(): | ||||
global search | global search | ||||
if not search: | if not search: | ||||
search = get_search(**app.config["search"]) | search = get_search(**app.config["search"]) | ||||
return search | return search | ||||
app = RPCServerApp(__name__, backend_class=ElasticSearch, backend_factory=_get_search) | app = RPCServerApp(__name__, backend_class=SearchInterface, backend_factory=_get_search) | ||||
search = None | search = None | ||||
@app.errorhandler(Exception) | @app.errorhandler(Exception) | ||||
def my_error_handler(exception): | def my_error_handler(exception): | ||||
return error_handler(exception, encode_data) | return error_handler(exception, encode_data) | ||||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |