Skip to content

Commit 3f8d02b

Browse files
committed
feat: enhance search functionality by adding projectId support in SearchDialog
1 parent 84704c0 commit 3f8d02b

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

docs/Voxy/v1/Commands/Management.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ Core plugin management.
5656

5757
| Subcommand | Description |
5858
|-----------|-------------|
59+
| `logs` | Uploads latest.log to pastes.dev |
5960
| `reload` | Reloads all config files, messages, and ladders |
6061
| `debug` | Toggles debug logging |
6162
| `migrate` | Runs pending permission migrations (e.g. from LuckPerms) |
62-
| `logs` | Uploads latest.log to pastes.dev |
6363

6464
## /rank
6565

src/components/docs/SearchDialog.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { cn } from '@/lib/utils';
2121
import { searchDocs, fetchSearchIndex } from '@/lib/docs';
2222
import type { SearchResult } from '@/types/docs';
2323

24-
export function SearchDialog() {
24+
export function SearchDialog({ projectId }: { projectId?: string }) {
2525
const [open, setOpen] = useState(false);
2626
const [query, setQuery] = useState('');
2727
const [results, setResults] = useState<SearchResult[]>([]);
@@ -55,7 +55,7 @@ export function SearchDialog() {
5555
useEffect(() => {
5656
let isActive = true;
5757
if (query.trim()) {
58-
searchDocs(query).then((searchResults) => {
58+
searchDocs(query, projectId).then((searchResults) => {
5959
if (isActive) {
6060
setResults(searchResults);
6161
setSelectedIndex(0);
@@ -67,7 +67,7 @@ export function SearchDialog() {
6767
return () => {
6868
isActive = false;
6969
};
70-
}, [query]);
70+
}, [query, projectId]);
7171

7272
const handleSelect = useCallback((result: SearchResult) => {
7373
navigate(result.href);

src/lib/docs.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ function searchFlexIndex(query: string, limit: number): EnrichedHit[] {
386386

387387
function mergeSearchHits(hits: EnrichedHit[], limit: number, query: string) {
388388
const seen = new Set<number>();
389-
const results: { title: string; excerpt: string; href: string; project: string }[] = [];
389+
const results: { title: string; excerpt: string; href: string; project: string; projectId: string }[] = [];
390390

391391
for (const bucket of hits) {
392392
for (const item of bucket.result) {
@@ -398,6 +398,7 @@ function mergeSearchHits(hits: EnrichedHit[], limit: number, query: string) {
398398
excerpt: buildExcerpt(doc.content, query),
399399
href: doc.href,
400400
project: doc.project,
401+
projectId: doc.projectId,
401402
});
402403
if (results.length >= limit) return results;
403404
}
@@ -406,7 +407,7 @@ function mergeSearchHits(hits: EnrichedHit[], limit: number, query: string) {
406407
return results;
407408
}
408409

409-
export async function searchDocs(query: string) {
410+
export async function searchDocs(query: string, projectId?: string) {
410411
const docs = await fetchSearchIndex();
411412
const normalizedQuery = normalizeSearchQuery(query);
412413
if (!docs.length || !flexIndex || !normalizedQuery) return [];
@@ -423,6 +424,10 @@ export async function searchDocs(query: string) {
423424
}
424425
}
425426

427+
if (projectId) {
428+
results = results.filter(r => r.projectId === projectId);
429+
}
430+
426431
return results;
427432
}
428433

src/pages/Docs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ export function Docs() {
169169
{/* Mobile Header */}
170170
<div className="lg:hidden flex items-center justify-between mb-6">
171171
<MobileSidebar project={project} version={activeVersion} />
172-
<SearchDialog />
172+
<SearchDialog projectId={project.id} />
173173
</div>
174174

175175
{/* Desktop Search */}
176176
<div className="hidden lg:flex justify-end mb-6">
177-
<SearchDialog />
177+
<SearchDialog projectId={project.id} />
178178
</div>
179179

180180
{isLoading ? (

0 commit comments

Comments
 (0)