Skip to content

feat(website): Add search suggestions to OSV database #3660

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

Merged
merged 18 commits into from
Jul 22, 2025

Conversation

dizzydroid
Copy link
Contributor

@dizzydroid dizzydroid commented Jul 11, 2025

This PR introduces a new /api/search_suggestions endpoint that aims to provide real-time search suggestions for the OSV vulnerability database.

This PR is part of a larger effort to enhance the search experience across the website (see PR #3657)
Addresses issue #382

@dizzydroid dizzydroid changed the title Add search suggestions API endpoint to frontend handlers feat(website): Add search suggestions API endpoint Jul 11, 2025
@dizzydroid
Copy link
Contributor Author

image dropdown suggestions should now work on the Vulnerability Database page.

@cuixq cuixq requested a review from jess-lowe July 13, 2025 23:40
@jess-lowe
Copy link
Contributor

This may be due to the merge conflicts but this is what it currently looks like on my end:
image

@dizzydroid
Copy link
Contributor Author

I'll resolve the conflicts and look into this, but I have a feeling this could be related to Turbo's cache, did you try a hard reload?

@dizzydroid
Copy link
Contributor Author

I'm facing the same issue actually but it goes away when I do a hard reload or try in incognito somehow which is strange XD - I will investigate this further and also try to add the dropdown feature to the navbar search too.

@dizzydroid dizzydroid changed the title feat(website): Add search suggestions API endpoint feat(website): Add search suggestions to OSV database Jul 14, 2025
- Address page initialization errors by applying retry and defensive mechanisms
- Add orphaned DOM element cleanup to prevent layout interference
- Refactor search modules
@dizzydroid
Copy link
Contributor Author

I've pushed a fix (hopefully), implemented a few retry mechanisms and fallbacks to ensure the page loads well on the first try. Also restructured the modules by exporting the Search Suggestions class to search.js instead of cluttering index.js. Let me know if this works now - next step should be implementing the dropdown on the navbar's searchbox.

@dizzydroid
Copy link
Contributor Author

dizzydroid commented Jul 15, 2025

image image

Suggestions are currently working well on the website emulator, both frontend and backend seem to be stable on my end - frontend renders well on first load and backend returns the suggestions array in the response body as expected. Let me know if it works on your end too.

(About the styling, I've went with this change because I didn't like the older one especially the white border because it looked strange in the navbar 😅, I've experimented a few styles and this is the one that looked best but feel free to ask for any specific styling changes!)

@jess-lowe
Copy link
Contributor

Awesome! My small nit would be - would it be possible to show the ids in the search suggestion in uppercase instead of lower? - most vuln IDs present as uppercase :). I'll review the rest of the code when I get the chance!

Copy link
Contributor

@another-rex another-rex left a comment

Choose a reason for hiding this comment

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

Thanks, very nice! Made a bunch of comments.

I do have a question on why the searchSuggestionsManager need to be cleanedup and recreated so much (at least code length wise), is it just because of the "turbo" load?

@dizzydroid
Copy link
Contributor Author

@another-rex thanks for the review, I'm going through them now and will update! Yes, I've added those retries because of the Turbo cache bug, it seemed that this was the way I got it to stabilize and not load unstyled without needing a forced reload. Weird bug but that seemed to work :)

@dizzydroid
Copy link
Contributor Author

dizzydroid commented Jul 17, 2025

I've modified the styles, this is how the suggestion dropdowns should look like as of now,
image
image

edit: it may not be clearly visible here but the main searchbox (and the navbar's) has a scrollbar when focused on to scroll through suggestions (currently a max of 10 are displayed).

@dizzydroid
Copy link
Contributor Author

Applied the required linter formatting. The CI check should now pass.

@another-rex
Copy link
Contributor

Looks amazing!

@another-rex
Copy link
Contributor

/gcbrun

another-rex
another-rex previously approved these changes Jul 18, 2025
@jess-lowe
Copy link
Contributor

LGTM! Great work! We will aim to merge this on Tuesday (Sydney time) after this week's release so we have a week to observe it in the test instance, and make sure the database changes happen smoothly :)

@jess-lowe
Copy link
Contributor

/gcbrun

@jess-lowe
Copy link
Contributor

Ah it looks like the worker tests are failing because of the added search_tags field. Are you able to run make worker-tests locally and see the missing tags? If not I can push a commit with the updated testcases.

@dizzydroid
Copy link
Contributor Author

Thanks for the heads up, I'll run the tests locally and update you shortly!

@dizzydroid
Copy link
Contributor Author

@jess-lowe I've updated the test data and the tests are passing for me now. Let me know if this works!

@jess-lowe
Copy link
Contributor

/gcbrun

@jess-lowe jess-lowe merged commit 58388bd into google:master Jul 22, 2025
16 checks passed
@another-rex
Copy link
Contributor

It's now live on test.osv.dev! Only some records are showing up as we populate the search_tags.

I did find a bug though, if you scroll down a little bit and try to search, the search dropdown will be offset in the wrong spot. (I think one of the offset calculations in javascript has a sign flipped?)

@dizzydroid
Copy link
Contributor Author

Awesome, Thanks for the update! Yes it seems like this is happening on both dropdowns, I will look into this and patch it shortly.

@dizzydroid
Copy link
Contributor Author

Checked the code, calculations look correct, it just didnt account for the relative position of the document.
Should be fixed in #3712

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