-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add base proxy behind elastic search to support other search engines
- Loading branch information
Showing
5 changed files
with
86 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from threading import Lock | ||
|
||
from flask import current_app | ||
|
||
from search_service import config | ||
from search_service.proxy.base import BaseProxy | ||
from werkzeug.utils import import_string | ||
|
||
_proxy_client = None | ||
_proxy_client_lock = Lock() | ||
|
||
|
||
def get_proxy_client() -> BaseProxy: | ||
""" | ||
Provides singleton proxy client based on the config | ||
:return: Proxy instance of any subclass of BaseProxy | ||
""" | ||
global _proxy_client | ||
|
||
if _proxy_client: | ||
return _proxy_client | ||
|
||
with _proxy_client_lock: | ||
if _proxy_client: | ||
return _proxy_client | ||
else: | ||
# Gather all the configuration to create a Proxy Client | ||
host = current_app.config[config.PROXY_ENDPOINT] | ||
user = current_app.config[config.PROXY_USER] | ||
password = current_app.config[config.PROXY_PASSWORD] | ||
|
||
client = import_string(current_app.config[config.PROXY_CLIENT]) | ||
_proxy_client = client(host=host, index=None, user=user, password=password) | ||
|
||
return _proxy_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from abc import ABCMeta, abstractmethod | ||
|
||
from typing import Union, List, Dict, Any | ||
|
||
from search_service.models.search_result import SearchResult | ||
|
||
|
||
class BaseProxy(metaclass=ABCMeta): | ||
""" | ||
Base Proxy, which behaves like an interface for all | ||
the proxy clients available in the amundsen search service | ||
""" | ||
|
||
@abstractmethod | ||
def fetch_search_results_with_field(self, *, | ||
query_term: str, | ||
field_name: str, | ||
field_value: str, | ||
page_index: int = 0) -> SearchResult: | ||
pass | ||
|
||
@abstractmethod | ||
def fetch_search_results(self, *, | ||
query_term: str, | ||
page_index: int = 0) -> SearchResult: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters