-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add dashboard search filter support (#112)
* feat: Add search filter support dashboard * fix mypy * keep table filter endpoint the same for now * fix issue * pass index by default * remove index and keep page_index * update tag name * update per feedback * update version
- Loading branch information
Showing
13 changed files
with
448 additions
and
280 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from http import HTTPStatus | ||
from typing import Any, Dict, Iterable # noqa: F401 | ||
|
||
from flask_restful import Resource, reqparse | ||
from marshmallow_annotations.ext.attrs import AttrsSchema | ||
|
||
from search_service.proxy import get_proxy_client | ||
|
||
|
||
class BaseFilterAPI(Resource): | ||
""" | ||
Base Filter API for search filtering | ||
This API should be generic enough to support every search filter use case. | ||
""" | ||
|
||
def __init__(self, *, schema: AttrsSchema, index: str) -> None: | ||
self.proxy = get_proxy_client() | ||
self.schema = schema | ||
self.index = index | ||
self.parser = reqparse.RequestParser(bundle_errors=True) | ||
|
||
self.parser.add_argument('page_index', required=False, default=0, type=int) | ||
self.parser.add_argument('query_term', required=False, type=str) | ||
self.parser.add_argument('search_request', type=dict) | ||
|
||
super(BaseFilterAPI, self).__init__() | ||
|
||
def post(self) -> Iterable[Any]: | ||
""" | ||
Fetch search results based on the page_index, query_term, and | ||
search_request dictionary posted in the request JSON. | ||
:return: json payload of schema. | ||
doesn't match any tables | ||
""" | ||
args = self.parser.parse_args(strict=True) | ||
page_index = args.get('page_index') # type: int | ||
|
||
search_request = args.get('search_request') # type: Dict | ||
if search_request is None: | ||
msg = 'The search request payload is not available in the request' | ||
return {'message': msg}, HTTPStatus.BAD_REQUEST | ||
|
||
query_term = args.get('query_term') # type: str | ||
if ':' in query_term: | ||
msg = 'The query term contains an invalid character' | ||
return {'message': msg}, HTTPStatus.BAD_REQUEST | ||
|
||
try: | ||
results = self.proxy.fetch_search_results_with_filter( | ||
search_request=search_request, | ||
query_term=query_term, | ||
page_index=page_index, | ||
index=self.index | ||
) | ||
|
||
return self.schema().dump(results).data, HTTPStatus.OK | ||
except RuntimeError as e: | ||
raise e |
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
38 changes: 38 additions & 0 deletions
38
search_service/api/swagger_doc/dashboard/search_dashboard_filter.yml
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,38 @@ | ||
Dashboard search | ||
This is used by the frontend API to search dashboard information. | ||
--- | ||
tags: | ||
- 'search_dashboard_filter' | ||
paths: | ||
/search_dashboard: | ||
post: | ||
summary: This is used by the frontend API to search dashboard information. | ||
requestBody: | ||
description: The json data passed from the frontend API to execute a search. | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
index: | ||
type: string | ||
page_index: | ||
type: integer | ||
query_term: | ||
type: string | ||
search_request: | ||
type: object | ||
responses: | ||
200: | ||
description: dashboard result information with query string | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/SearchDashboardResults' | ||
500: | ||
description: Exception encountered while searching | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/ErrorResponse' |
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
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
Oops, something went wrong.