This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
forked from HHS/simpler-grants-gov
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Summary Fixes #16 ### Time to review: __10 mins__ ## Changes proposed Make the v1 search opportunity endpoint connect to the search index and return results. Adjust the structure of the response to be more flexible going forward. ## Context for reviewers The actual building of the search request / parsing the response is pretty simple. Other than having to map some field names, that logic is mostly contained in the builder I made in the prior PR. However, there is a lot of configuration and other API components that had to be modified as part of this including: * Adjusting the API response schema (to better support facet counts) * Piping through the search client + index alias name configuration. * A monumental amount of test cases to verify everything is connected / behavior works in a way we expect - note that I did not test relevancy as that'll break anytime we adjust something. ## Additional information Note that the change in API schema means the API does not work with the frontend, but there are a few hacky changes you can make to connect them. In [BaseApi.ts](https://github.com/navapbc/simpler-grants-gov/blob/main/frontend/src/app/api/BaseApi.ts#L47) change the version to `v1`. In [SearchOpportunityAPI.ts](https://github.com/navapbc/simpler-grants-gov/blob/main/frontend/src/app/api/SearchOpportunityAPI.ts#L56) add `response.data = response.data.opportunities;` to the end of the `searchOpportunities` method. With that, the local frontend will work. To actually get everything running locally, you can run: ```sh make db-recreate make init make db-seed-local args="--iterations 10" poetry run flask load-search-data load-opportunity-data make run-logs # and also to run the frontend npm run dev ``` Then go to http://localhost:3000/search --------- Co-authored-by: nava-platform-bot <[email protected]>
- Loading branch information
1 parent
817a1d3
commit cbccbed
Showing
15 changed files
with
1,375 additions
and
120 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from src.adapters.search.opensearch_client import SearchClient | ||
from src.adapters.search.opensearch_config import get_opensearch_config | ||
from src.adapters.search.opensearch_query_builder import SearchQueryBuilder | ||
|
||
__all__ = ["SearchClient", "get_opensearch_config"] | ||
__all__ = ["SearchClient", "get_opensearch_config", "SearchQueryBuilder"] |
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,47 @@ | ||
from functools import wraps | ||
from typing import Callable, Concatenate, ParamSpec, TypeVar | ||
|
||
from flask import Flask, current_app | ||
|
||
from src.adapters.search import SearchClient | ||
|
||
_SEARCH_CLIENT_KEY = "search-client" | ||
|
||
|
||
def register_search_client(search_client: SearchClient, app: Flask) -> None: | ||
app.extensions[_SEARCH_CLIENT_KEY] = search_client | ||
|
||
|
||
def get_search_client(app: Flask) -> SearchClient: | ||
return app.extensions[_SEARCH_CLIENT_KEY] | ||
|
||
|
||
P = ParamSpec("P") | ||
T = TypeVar("T") | ||
|
||
|
||
def with_search_client() -> Callable[[Callable[Concatenate[SearchClient, P], T]], Callable[P, T]]: | ||
""" | ||
Decorator for functions that need a search client. | ||
This decorator will return the shared search client object which | ||
has an internal connection pool that is shared. | ||
Usage: | ||
@with_search_client() | ||
def foo(search_client: search.SearchClient): | ||
... | ||
@with_search_client() | ||
def bar(search_client: search.SearchClient, x: int, y: int): | ||
... | ||
""" | ||
|
||
def decorator(f: Callable[Concatenate[SearchClient, P], T]) -> Callable[P, T]: | ||
@wraps(f) | ||
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T: | ||
return f(get_search_client(current_app), *args, **kwargs) | ||
|
||
return wrapper | ||
|
||
return decorator |
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.