Skip to content

feat: Add ability to Filter Search results by Author#896

Open
syazah wants to merge 2 commits intosourcebot-dev:mainfrom
syazah:syazah/ability-to-filter-results-by-author
Open

feat: Add ability to Filter Search results by Author#896
syazah wants to merge 2 commits intosourcebot-dev:mainfrom
syazah:syazah/ability-to-filter-results-by-author

Conversation

@syazah
Copy link

@syazah syazah commented Feb 15, 2026

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

  • New Features
    • Filter search results by author using "author:" or "a:" prefixes in the search bar.
    • Author suggestions appear in the refine/search suggestions to streamline selecting an author; suggestions load on demand and integrate with existing suggestion behavior.
    • Search parsing and prefix handling updated to recognize and apply author-based filters.

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
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 15, 2026

Walkthrough

Adds 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

Cohort / File(s) Summary
Parser term & table changes
packages/queryLanguage/src/parser.terms.ts, packages/queryLanguage/src/parser.ts
Introduce AuthorExpr token/term and authorKw token; shift several token indices (e.g., negate 23→24, openParen 24→25, word 25→26, closeParen 26→27, or 27→28); update parser states, goto, stateData, tokenData, tokenPrec, termNames/nodeNames to align with new term.
Grammar & tokenizer
packages/queryLanguage/src/query.grammar, packages/queryLanguage/src/tokens.ts
Add AuthorExpr production (AuthorExpr { authorKw value }) and authorKw (`"author:"
Search UI constants & rendering
packages/web/src/app/[domain]/components/searchBar/constants.ts, packages/web/src/app/[domain]/components/searchBar/searchSuggestionsBox.tsx
Add author and a to SearchPrefix enum; add author suggestion mode, authorSuggestions prop on SearchSuggestionsBox, and rendering case for author suggestions.
Suggestion mapping & refine mode
packages/web/src/app/[domain]/components/searchBar/useRefineModeSuggestions.ts, packages/web/src/app/[domain]/components/searchBar/useSuggestionModeMappings.ts
Add author entry to refined suggestions and suggestion-mode mappings (prefixes author, -author, a, -a).
Suggestion data fetching
packages/web/src/app/[domain]/components/searchBar/useSuggestionsData.ts
Add authorSuggestions useQuery that derives author names from repos (dedupe by author segment); expose isLoadingAuthors and include in overall loading state.
Query transformer
packages/web/src/features/search/parser.ts
Handle AuthorExpr in transformPrefixExpr by emitting a repo filter with regexp anchored to author segment (^[^/]+/${value}/) and returning repo as the query scope.

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • sourcebot-dev/sourcebot#623: Modifies the generated query-language parser/term/token definitions (parser.terms.ts, parser.ts, query.grammar, tokens) to add AuthorExpr and adjust token indices — strong overlap at code-level.
  • #788: Earlier changes to queryLanguage parser/token definitions that shift term/token constants and tokenizer behavior — related at the parser/tokenization layer.

Suggested labels

sourcebot-team

Suggested reviewers

  • msukkari
  • brendan-kellam
🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: Add ability to Filter Search results by Author' is concise and clearly describes the main feature addition throughout the changeset.
Linked Issues check ✅ Passed The pull request successfully implements all coding requirements from issue #889: adds author prefix support via parser/grammar changes, implements autocomplete suggestions via useSuggestionsData, translates author filter to repo regex format, and supports combined filters.
Out of Scope Changes check ✅ Passed All changes are directly related to adding author filtering: grammar/parser updates, autocomplete infrastructure, UI suggestion components, and token handling are all necessary for the stated feature.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 | 🟡 Minor

Missing suggestionModeText label for the "author" suggestion mode.

The suggestionModeText switch (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 types author: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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +78 to +100
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"
});
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 15, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

Copy link
Author

Choose a reason for hiding this comment

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

@msukkari do we need a dedicated author lookup since currently we are able to filter by author

Copy link
Contributor

Choose a reason for hiding this comment

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

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!

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.

[FR] Add ability to filter search results by author

1 participant