Skip to content

Search suggestions - #85

Merged
brendan-kellam merged 20 commits into
mainfrom
bkellam/search_suggestions
Nov 23, 2024
Merged

brendan-kellam merged 20 commits into
mainfrom
bkellam/search_suggestions

Conversation

@brendan-kellam

@brendan-kellam brendan-kellam commented Nov 21, 2024 •

Copy link
Copy Markdown
Contributor

The following PR introduces search suggestions:

Screen.Recording.2024-11-21.at.4.22.05.PM.mov

The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.

The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).

The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.

Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..

Comment thread packages/web/src/app/components/searchBar/searchSuggestionsBox.tsx Outdated
@brendan-kellam
brendan-kellam marked this pull request as ready for review November 22, 2024 01:01
@brendan-kellam brendan-kellam changed the title [wip] Search suggestions Search suggestions Nov 22, 2024
@msukkari
msukkari self-requested a review November 22, 2024 23:59
@brendan-kellam
brendan-kellam merged commit 7f952ce into main Nov 23, 2024
@brendan-kellam
brendan-kellam deleted the bkellam/search_suggestions branch November 23, 2024 02:50
@brendan-kellam brendan-kellam mentioned this pull request Nov 24, 2024
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.

2 participants