-
-
Notifications
You must be signed in to change notification settings - Fork 179
feat(spotlight): rework !bang search UX #4813
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
Open
ajnart
wants to merge
20
commits into
dev
Choose a base branch
from
feat/rework-search
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
436b291
fix(db): update default search engine URL template in seed migration
ajnart 21ce992
feat(api): add DuckDuckGo bangs search endpoint
ajnart f380f4a
feat(spotlight): make launcher default and support in-place query upd…
ajnart 005fe49
feat(spotlight): support !bang search with DDG fallback
ajnart 0375a1d
feat(spotlight): remove redundant home search-engine switch action
ajnart 8dc8987
perf(spotlight): debounce integration and bang searches
ajnart 802f791
perf(spotlight): debounce integration search engine children results
ajnart 7ed557e
perf(spotlight): tune debounce timings
ajnart 1640a09
Revert "perf(spotlight): tune debounce timings"
ajnart 7967fbc
Revert "perf(spotlight): debounce integration search engine children …
ajnart 074a219
Revert "perf(spotlight): debounce integration and bang searches"
ajnart f35197b
feat(request-handler): cache DuckDuckGo bangs with schema parsing
ajnart 7df1ea3
refactor(api): serve DuckDuckGo bangs via cached request-handler
ajnart 90bb760
fix(spotlight): improve !bang UX and reduce query spam
ajnart fb15e1e
feat(user): add support for ddg bangs feature
ajnart 4e4c02c
Merge branch 'dev' into feat/rework-search
ajnart 742f0e0
fix(request-handler): use ResponseError instead of generic Error
ajnart d0569a2
docs(api): explain binary search benefit over findIndex
ajnart c640a05
refactor(user): move ddgBangs toggle into search preferences
ajnart bc296f3
chore(db): add mysql and postgresql migrations for ddgBangs column
ajnart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { z } from "zod/v4"; | ||
|
|
||
| import { searchDuckDuckGoBangsAsync } from "../../services/duckduckgo-bangs"; | ||
| import { createTRPCRouter, publicProcedure } from "../../trpc"; | ||
|
|
||
| export const bangsRouter = createTRPCRouter({ | ||
| search: publicProcedure | ||
| .input( | ||
| z.object({ | ||
| query: z.string(), | ||
| limit: z.number().int().min(1).max(50).default(20), | ||
| }), | ||
| ) | ||
| .query(async ({ input }) => { | ||
| return await searchDuckDuckGoBangsAsync({ query: input.query, limit: input.limit }); | ||
| }), | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { duckDuckGoBangsRequestHandler } from "@homarr/request-handler/duckduckgo-bangs"; | ||
| import type { DuckDuckGoBang } from "@homarr/request-handler/duckduckgo-bangs"; | ||
|
|
||
| // DuckDuckGo bang keys are intentionally short: | ||
| // - `t`: token (e.g. "yt"), `s`: display name, `u`: URL template (contains `{{{s}}}`) | ||
| // - `d`: domain, `c`: category, `sc`: subcategory, `r`: rank (optional) | ||
|
|
||
| const normalizeBangToken = (token: string) => token.toLowerCase().trim(); | ||
|
|
||
| /** | ||
| * Binary search to find the first index where bang.t >= tokenPrefix. | ||
| * This is O(log n) vs O(n) for findIndex, which matters because DuckDuckGo | ||
| * has ~13,000+ bangs. Combined with the pre-sorted data, this allows | ||
| * efficient prefix matching by finding the start position and iterating | ||
| * only through consecutive matches. | ||
| */ | ||
| const lowerBound = (arr: DuckDuckGoBang[], tokenPrefix: string) => { | ||
| let low = 0; | ||
| let high = arr.length; | ||
| while (low < high) { | ||
| const mid = (low + high) >> 1; | ||
| const midBang = arr[mid]; | ||
| // Must use the same ordering as the source list sort (localeCompare), | ||
| // otherwise binary search can miss tokens with symbols like "&" or "_". | ||
| if (!midBang || midBang.t.localeCompare(tokenPrefix) >= 0) { | ||
| high = mid; | ||
| continue; | ||
| } | ||
|
|
||
| low = mid + 1; | ||
| } | ||
| return low; | ||
| }; | ||
|
|
||
| export const searchDuckDuckGoBangsAsync = async (input: { | ||
| query: string; | ||
| limit: number; | ||
| }): Promise<DuckDuckGoBang[]> => { | ||
| const queryTokenPrefix = normalizeBangToken(input.query); | ||
| if (!queryTokenPrefix) return []; | ||
|
|
||
| const { data: allBangs } = await duckDuckGoBangsRequestHandler.handler({}).getCachedOrUpdatedDataAsync({}); | ||
| const startIndex = lowerBound(allBangs, queryTokenPrefix); | ||
ajnart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const matches: DuckDuckGoBang[] = []; | ||
|
|
||
| for (let index = startIndex; index < allBangs.length; index++) { | ||
| const bang = allBangs[index]; | ||
| if (!bang) break; | ||
| if (!bang.t.startsWith(queryTokenPrefix)) break; | ||
| matches.push(bang); | ||
| if (matches.length >= input.limit) break; | ||
| } | ||
|
|
||
| return matches; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE `user` ADD `ddg_bangs` boolean DEFAULT true NOT NULL; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.