Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Search endpoint #35

Merged
merged 10 commits into from
Jan 23, 2024
Merged

feat: Search endpoint #35

merged 10 commits into from
Jan 23, 2024

Conversation

KaylaBrady
Copy link
Collaborator

@KaylaBrady KaylaBrady commented Jan 12, 2024

ticket: https://app.asana.com/0/1205425564113216/1206267623655566/f

This is heavily inspired by how dotcom does algolia search. My goal was to extract the pieces that are most relevant for what we know now about how search will work in the app.

Some differences from dotcom:
functionality

  • Parses out minimal stop & route data from the algolia responses
  • Does not use algolia facets. Dotcom searches different facets of data for different pages, see FACET_MAP
  • This does not pull over caching logic. I think that is worth splitting into a separate ticket to be individually refined. Cache hits are 10-40% of requests based on dotcom's current configuration

organization

  • Moves more pieces into environment config, like index name and base url function
  • Updated query parameter encoding logic. There was some specific encoding logic logic, but I think HttpPoison.encode_query covers what we need.

TODO:

  • Finish writing tests for API
  • Add tests for search controller
  • Add ALGOLIA_BASE_URL env var

Comment on lines 36 to 38
base_url_fn: fn ->
"https://#{Application.get_env(:mobile_app_backend, MobileAppBackend.Search.Algolia)[:app_id]}-dsn.algolia.net"
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't love this as a function - probably would be nicer as an environment variable passed at runtime

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like mix release doesn't support configuring functions in config! Going the env var approach - will open a PR in the devops repo

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@EmmaSimon EmmaSimon Jan 22, 2024

Choose a reason for hiding this comment

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

Should we add an .envrc.template so devs know what needs to be set locally?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added in 0b352df

Copy link

Coverage of commit 7f54d20

Summary coverage rate:
  lines......: 57.6% (537 of 932 lines)
  functions..: 54.1% (282 of 521 functions)
  branches...: no data found

Files changed coverage rate:
                                                              |Lines       |Functions  |Branches    
  Filename                                                    |Rate     Num|Rate    Num|Rate     Num
  ==================================================================================================
  lib/mobile_app_backend/search/algolia/api.ex                |92.9%     28| 100%     7|    -      0
  lib/mobile_app_backend/search/algolia/index.ex              | 100%      2| 100%     1|    -      0
  lib/mobile_app_backend/search/algolia/query_payload.ex      | 100%      8| 100%     5|    -      0
  lib/mobile_app_backend/search/algolia/route_result.ex       | 100%      2| 100%     3|    -      0
  lib/mobile_app_backend/search/algolia/stop_result.ex        | 100%      3| 100%     3|    -      0
  lib/mobile_app_backend_web/controllers/search_controller.ex | 100%      8|85.7%     7|    -      0
  lib/mobile_app_backend_web/router.ex                        |81.8%     11|71.4%    14|    -      0

Download coverage report

@KaylaBrady KaylaBrady marked this pull request as ready for review January 16, 2024 21:20
@KaylaBrady KaylaBrady requested a review from a team as a code owner January 16, 2024 21:20
@KaylaBrady KaylaBrady requested review from boringcactus and removed request for a team January 16, 2024 21:20
Copy link

Coverage of commit 002f5bc

Summary coverage rate:
  lines......: 58.5% (545 of 932 lines)
  functions..: 54.3% (283 of 521 functions)
  branches...: no data found

Files changed coverage rate:
                                                              |Lines       |Functions  |Branches    
  Filename                                                    |Rate     Num|Rate    Num|Rate     Num
  ==================================================================================================
  lib/mobile_app_backend/search/algolia/api.ex                |92.9%     28| 100%     7|    -      0
  lib/mobile_app_backend/search/algolia/index.ex              | 100%      2| 100%     1|    -      0
  lib/mobile_app_backend/search/algolia/query_payload.ex      | 100%      8| 100%     5|    -      0
  lib/mobile_app_backend/search/algolia/route_result.ex       | 100%      2| 100%     3|    -      0
  lib/mobile_app_backend/search/algolia/stop_result.ex        | 100%      3| 100%     3|    -      0
  lib/mobile_app_backend_web/controllers/search_controller.ex | 100%      8|85.7%     7|    -      0
  lib/mobile_app_backend_web/router.ex                        |81.8%     11|71.4%    14|    -      0

Download coverage report

Copy link
Member

@boringcactus boringcactus left a comment

Choose a reason for hiding this comment

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

I think it feels a little weird to be mocking the network call both via the application config and via options passed as a separate argument, and in a vacuum I'd rather stick to one or the other (maybe application config with something like Mox), but I think we already don't have a coherent approach to mocking, so adding one will be a separate task anyway, and this PR doesn't necessarily need to be blocked on taking care of that.

lib/mobile_app_backend/search/algolia/api.ex Outdated Show resolved Hide resolved
test/mobile_app_backend/search/algolia/api_test.exs Outdated Show resolved Hide resolved
Copy link

Coverage of commit ddefc1a

Summary coverage rate:
  lines......: 57.5% (535 of 930 lines)
  functions..: 54.0% (281 of 520 functions)
  branches...: no data found

Files changed coverage rate:
                                                              |Lines       |Functions  |Branches    
  Filename                                                    |Rate     Num|Rate    Num|Rate     Num
  ==================================================================================================
  lib/mobile_app_backend/search/algolia/api.ex                |92.3%     26| 100%     6|    -      0
  lib/mobile_app_backend/search/algolia/index.ex              | 100%      2| 100%     1|    -      0
  lib/mobile_app_backend/search/algolia/query_payload.ex      | 100%      8| 100%     5|    -      0
  lib/mobile_app_backend/search/algolia/route_result.ex       | 100%      2| 100%     3|    -      0
  lib/mobile_app_backend/search/algolia/stop_result.ex        | 100%      3| 100%     3|    -      0
  lib/mobile_app_backend_web/controllers/search_controller.ex | 100%      8|85.7%     7|    -      0
  lib/mobile_app_backend_web/router.ex                        |81.8%     11|71.4%    14|    -      0

Download coverage report

Copy link

Coverage of commit 301cde3

Summary coverage rate:
  lines......: 52.9% (175 of 331 lines)
  functions..: 49.8% (100 of 201 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/mobile_app_backend/search/algolia/api.ex               |88.9%     27|85.7%     7|    -      0
  lib/mobile_app_backend/search/algolia/index.ex             | 100%      2| 100%     1|    -      0
  lib/mobile_app_backend/search/algolia/query_payload.ex     | 100%      8| 100%     5|    -      0
  lib/mobile_app_backend/search/algolia/route_result.ex      | 100%      2| 100%     3|    -      0
  lib/mobile_app_backend/search/algolia/stop_result.ex       | 100%      3| 100%     3|    -      0
  lib/mobile_app_backend_web/controllers/search_controller.ex| 100%      8|85.7%     7|    -      0
  lib/mobile_app_backend_web/router.ex                       | 100%      6|66.7%    12|    -      0

Download coverage report

Copy link

Coverage of commit f1aea49

Summary coverage rate:
  lines......: 53.0% (176 of 332 lines)
  functions..: 49.8% (100 of 201 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/mobile_app_backend/search/algolia/api.ex               |89.3%     28|85.7%     7|    -      0
  lib/mobile_app_backend/search/algolia/index.ex             | 100%      2| 100%     1|    -      0
  lib/mobile_app_backend/search/algolia/query_payload.ex     | 100%      8| 100%     5|    -      0
  lib/mobile_app_backend/search/algolia/route_result.ex      | 100%      2| 100%     3|    -      0
  lib/mobile_app_backend/search/algolia/stop_result.ex       | 100%      3| 100%     3|    -      0
  lib/mobile_app_backend_web/controllers/search_controller.ex| 100%      8|85.7%     7|    -      0
  lib/mobile_app_backend_web/router.ex                       | 100%      6|66.7%    12|    -      0

Download coverage report

This way the defined API url can be used for organizing test files without being relient on what is configured in the envrc.template
Copy link

Coverage of commit 13c8fc0

Summary coverage rate:
  lines......: 57.7% (311 of 539 lines)
  functions..: 58.3% (158 of 271 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/mobile_app_backend/search/algolia/api.ex               |89.3%     28|85.7%     7|    -      0
  lib/mobile_app_backend/search/algolia/index.ex             | 100%      2| 100%     1|    -      0
  lib/mobile_app_backend/search/algolia/query_payload.ex     | 100%      8| 100%     5|    -      0
  lib/mobile_app_backend/search/algolia/route_result.ex      | 100%      2| 100%     3|    -      0
  lib/mobile_app_backend/search/algolia/stop_result.ex       | 100%      3| 100%     3|    -      0
  lib/mobile_app_backend_web/controllers/search_controller.ex| 100%      8|85.7%     7|    -      0
  lib/mobile_app_backend_web/router.ex                       | 100%      7|66.7%    12|    -      0

Download coverage report

@KaylaBrady KaylaBrady merged commit fd5bedf into main Jan 23, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants