feat: Add ability to Filter Search results by Author#896
feat: Add ability to Filter Search results by Author#896syazah wants to merge 2 commits intosourcebot-dev:mainfrom
Conversation
Closes sourcebot-dev#889 What I've Done: Added a new "author: " prefix to zoekt, when used, it translates to a repo: regex matching the owner segment of the repo name (e.g., author:sourcebot-dev becomes repo:^[^/]+/sourcebot-dev/). Also added autocomplete suggestions in the search bar that extract unique owners from repo names via the listRepos API. What Could've Also be Done: DB lookup - repo_set, querying prisma for repos, but this could add unnecessary DB calls. Loom: https://www.loom.com/share/e6a84150870a4036be9cbd60f81ab139
WalkthroughAdds author filtering to search: new AuthorExpr grammar/token, parser/table updates, tokenizer prefix additions, UI suggestion support and data fetching for authors, and transformer handling to convert author expressions into repo-scoped filters. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant UI as "SearchBar UI"
participant Hook as "useSuggestionsData"
participant RepoSvc as "RepoService (listRepos)"
participant Parser as "Query Parser/Transformer"
participant Search as "Search Engine"
User->>UI: type "author:ma"
UI->>Hook: request authorSuggestions (suggestionMode=author)
Hook->>RepoSvc: listRepos()
RepoSvc-->>Hook: repos list
Hook-->>UI: authorSuggestions (deduped)
User->>UI: select suggestion "author:ma"
UI->>Parser: parse/transform AuthorExpr
Parser-->>UI: repo filter / query
UI->>Search: execute search with repo filter
Search-->>UI: results
UI-->>User: display results
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/web/src/app/[domain]/components/searchBar/searchSuggestionsBox.tsx (1)
291-313:⚠️ Potential issue | 🟡 MinorMissing
suggestionModeTextlabel for the "author" suggestion mode.The
suggestionModeTextswitch (Lines 295-311) has no case for"author", so the suggestion box header will be blank when showing author suggestions. Other modes like "repo", "file", "symbol" all have labels.♻️ Proposed fix
case "context": return "Search contexts" + case "author": + return "Authors" default: return "";
🤖 Fix all issues with AI agents
In
`@packages/web/src/app/`[domain]/components/searchBar/useSuggestionModeMappings.ts:
- Around line 46-51: The author suggestion mapping in useSuggestionModeMappings
currently lists only SearchPrefix.author (and its negation); add the short alias
SearchPrefix.a and its negation (negate(SearchPrefix.a)) to the prefixes array
for the mapping with suggestionMode "author" so that typing "a:" triggers author
suggestions; update the prefixes for that mapping to include both
SearchPrefix.author and SearchPrefix.a (and their negations) alongside the
existing entries.
In `@packages/web/src/app/`[domain]/components/searchBar/useSuggestionsData.ts:
- Around line 78-103: The select handler in the useSuggestionsData query for
authorSuggestions contains a dead isServiceError guard because
unwrapServiceError already throws; update the authorSuggestions useQuery
(function/symbols: useSuggestionsData, authorSuggestions, unwrapServiceError,
select) to remove the isServiceError check and treat data as the successful
array directly (compute unique authors from data.map(...).map(a => ({ value: a
})) ), mirroring the repoSuggestions pattern so the select is reachable and
concise.
In `@packages/web/src/features/search/parser.ts`:
- Around line 264-270: The AuthorExpr branch composes a repo regex using a value
that may already be regex-escaped (and contain anchors) which creates invalid
nested-anchors; change the flow to stop escaping in the UI and escape in the
parser: remove the regexEscaped flag for the author suggestion in the
searchSuggestionsBox suggestion handler so autocomplete returns plain text, then
in the parser (the AuthorExpr case) apply a proper escape function (e.g.,
escapeRegExp) to value before embedding it into the composed regex and ensure
any leading ^ or trailing $ from manual input are stripped or ignored so you
never insert nested anchors when building the string `^[^/]+/${escaped}/`.
🧹 Nitpick comments (2)
packages/web/src/app/[domain]/components/searchBar/useRefineModeSuggestions.ts (1)
37-41: Consider adding a negated-author:suggestion for consistency.Other prefix suggestions (repo, lang, file, rev, sym, content) all include a negated variant. If author negation is supported by the grammar (it is, via
NegateExpr), users might expect to see-author:in the refine suggestions as well.packages/web/src/app/[domain]/components/searchBar/useSuggestionsData.ts (1)
91-99: Author suggestion quality may be poor — query filters repos by name, not by owner.
listRepos({ query: suggestionQuery })searches repos by name. When a user typesauthor:source, this fetches repos with "source" in the repo name, then extracts owner names — which may not include owners actually named "source". Consider either a dedicated author/owner search API or fetching a broader repo list and filtering owners client-side.
packages/web/src/app/[domain]/components/searchBar/useSuggestionModeMappings.ts
Show resolved
Hide resolved
packages/web/src/app/[domain]/components/searchBar/useSuggestionsData.ts
Show resolved
Hide resolved
packages/web/src/app/[domain]/components/searchBar/useSuggestionsData.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/web/src/app/`[domain]/components/searchBar/useSuggestionsData.ts:
- Around line 78-100: The authorSuggestions code in useSuggestionsData.ts
currently calls listRepos(query: suggestionQuery) which searches repo names, so
typing author: will not match owner names and deduping over perPage: 15 can miss
owners; change the queryFn for the authorSuggestions useQuery to either call a
dedicated owner/author lookup endpoint (e.g., listOwners/listUsers) if
available, or implement paginated collection logic: call listRepos repeatedly
(or increase perPage) and aggregate unique repo owners
(repo.repoDisplayName.split("/")[0] or repo.repoName.split("/")[1]) until you
have the desired number of unique authors, then return that list; ensure the
query is only enabled when suggestionMode === "author" and preserve the
Suggestion[] mapping.
| const { data: authorSuggestions, isLoading: _isLoadingAuthors } = useQuery({ | ||
| queryKey: ["authorSuggestions", suggestionQuery, domain], | ||
| queryFn: () => unwrapServiceError(listRepos({ | ||
| query: `${suggestionQuery}`, | ||
| page: 1, | ||
| direction: "asc", | ||
| sort: "name", | ||
| perPage: 15, | ||
| })), | ||
| select: (data): Suggestion[] => { | ||
| const authors = [ | ||
| ...new Set( | ||
| data.map(repo => | ||
| repo.repoDisplayName | ||
| ? repo.repoDisplayName.split("/")[0] | ||
| : repo.repoName.split("/")[1] | ||
| ) | ||
| ) | ||
| ].map(a => ({ value: a })); | ||
| return authors; | ||
| }, | ||
| enabled: suggestionMode === "author" | ||
| }); |
There was a problem hiding this comment.
Author suggestions are filtered by repo name, not by author name.
The listRepos query uses suggestionQuery to search repos by name (query: suggestionQuery). This means typing an author name into author: will only surface authors who happen to have repos whose names match the typed text — not authors whose names match. Additionally, perPage: 15 caps results, so deduplication may miss authors whose repos aren't in the first page.
Consider fetching a broader set or implementing a dedicated author/owner lookup to improve suggestion relevance.
🤖 Prompt for AI Agents
In `@packages/web/src/app/`[domain]/components/searchBar/useSuggestionsData.ts
around lines 78 - 100, The authorSuggestions code in useSuggestionsData.ts
currently calls listRepos(query: suggestionQuery) which searches repo names, so
typing author: will not match owner names and deduping over perPage: 15 can miss
owners; change the queryFn for the authorSuggestions useQuery to either call a
dedicated owner/author lookup endpoint (e.g., listOwners/listUsers) if
available, or implement paginated collection logic: call listRepos repeatedly
(or increase perPage) and aggregate unique repo owners
(repo.repoDisplayName.split("/")[0] or repo.repoName.split("/")[1]) until you
have the desired number of unique authors, then return that list; ensure the
query is only enabled when suggestionMode === "author" and preserve the
Suggestion[] mapping.
There was a problem hiding this comment.
@msukkari do we need a dedicated author lookup since currently we are able to filter by author
There was a problem hiding this comment.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
Closes #889
Solution: Added a new "author: " prefix to zoekt, when used, it translates to a repo: regex matching the owner segment of the repo name (e.g., author:sourcebot-dev becomes repo:^[^/]+/sourcebot-dev/). Also added autocomplete suggestions in the search bar that extract unique owners from repo names via the listRepos API.
Alternate Solution: DB lookup - repo_set, querying prisma for repos, but this could add unnecessary DB calls.
Loom: https://www.loom.com/share/e6a84150870a4036be9cbd60f81ab139
Summary by CodeRabbit