Skip to content

Commit

Permalink
feat(website): add type field to search index to sort by (#10212)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qjuh committed Apr 14, 2024
1 parent afb97fb commit 7baa9e4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/website/src/components/ui/CmdK.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export function CmdK({ dependencies }: { readonly dependencies: string[] }) {
q: searchString,
limit: 25,
attributesToSearchOn: ['name'],
sort: ['type:asc'],
})),
});
setSearchResults(result.results.flatMap((res) => res.hits));
Expand Down
5 changes: 4 additions & 1 deletion packages/actions/src/uploadSearchIndices/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ try {
await client.waitForTask(task.taskUid);
}

await client.index(index.index).addDocuments(index.data);
const searchIndex = client.index(index.index);
await searchIndex.updateSettings({ sortableAttributes: ['type'] });

await searchIndex.addDocuments(index.data);
}),
);
} catch {}
Expand Down
26 changes: 26 additions & 0 deletions packages/scripts/src/generateIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface MemberJSON {
name: string;
path: string;
summary: string | null;
type: number;
}

let idx = 0;
Expand Down Expand Up @@ -89,6 +90,30 @@ export function tryResolveSummaryText(item: ApiDeclaredItem): string | null {
return retVal;
}

export enum SearchOrderType {
Class,
Interface,
TypeAlias,
Function,
Enum,
Variable,
Event,
Method,
Property,
MethodSignature,
PropertySignature,
EnumMember,
Package,
Namespace,
IndexSignature,
CallSignature,
Constructor,
ConstructSignature,
EntryPoint,
Model,
None,
}

export function visitNodes(item: ApiItem, tag: string) {
const members: (MemberJSON & { id: number })[] = [];

Expand All @@ -111,6 +136,7 @@ export function visitNodes(item: ApiItem, tag: string) {
kind: member.kind,
summary: tryResolveSummaryText(member) ?? '',
path: generatePath(member.getHierarchy(), tag),
type: SearchOrderType[member.kind as keyof typeof SearchOrderType],
});
}

Expand Down

0 comments on commit 7baa9e4

Please sign in to comment.