Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

[Issue #16] Connect the API to use the search index #63

Merged
merged 20 commits into from
Jun 27, 2024

Conversation

chouinar
Copy link
Collaborator

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 change the version to v1. In SearchOpportunityAPI.ts 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:

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

# with a lot of our IDs that have dashes in them.
# see: https://opensearch.org/docs/latest/analyzers/tokenizers/index/
"tokenizer": "whitespace",
"tokenizer": "standard",
Copy link
Member

@acouch acouch Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to match the stemmer chosen in the utils?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the utils, I found some issues with what I had configured in the prior PR when setting it up with our actual data and fixed it here.

acouch
acouch previously approved these changes Jun 25, 2024
Base automatically changed from chouinar/14-req-resp-tools to main June 25, 2024 14:15
@chouinar chouinar dismissed acouch’s stale review June 25, 2024 14:15

The base branch was changed.

Copy link
Member

@acouch acouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested locally, but didn't get a chance to mentally dig in and review the code/approach but looks good AFAICT.

@chouinar chouinar merged commit cbccbed into main Jun 27, 2024
8 checks passed
@chouinar chouinar deleted the chouinar/16-actual-impl branch June 27, 2024 20:07
acouch pushed a commit that referenced this pull request Sep 18, 2024
Fixes HHS#2084

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.

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.

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
npm run dev
```
Then go to http://localhost:3000/search

---------

Co-authored-by: nava-platform-bot <platform-admins@navapbc.com>
acouch pushed a commit that referenced this pull request Sep 18, 2024
Fixes HHS#2084

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.

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.

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
npm run dev
```
Then go to http://localhost:3000/search

---------

Co-authored-by: nava-platform-bot <platform-admins@navapbc.com>
acouch pushed a commit to HHS/simpler-grants-gov that referenced this pull request Sep 18, 2024
Fixes #2084

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.

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.

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
npm run dev
```
Then go to http://localhost:3000/search

---------

Co-authored-by: nava-platform-bot <platform-admins@navapbc.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Make the search API actually call OpenSearch and return results
3 participants