Skip to content

Commit d1ae3e8

Browse files
committed
Core: concentrate search API utils
1 parent f9e1f10 commit d1ae3e8

File tree

19 files changed

+56
-38
lines changed

19 files changed

+56
-38
lines changed

.changeset/light-pants-pump.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'fumadocs-core': minor
3+
---
4+
5+
**Move `SortedResult` and other search-related types to `fumadocs-core/search`**
6+
7+
This also exposed the search result highlighter API, you may now use it for highlighting results of your own search integration
8+
9+
Old export will be kept until the next major release.

apps/docs/content/docs/headless/props.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type * as Breadcrumb from 'fumadocs-core/breadcrumb';
22
import type * as TOC from 'fumadocs-core/toc';
33
import type * as Server from 'fumadocs-core/server';
4+
import type * as Search from 'fumadocs-core/search';
45
import type * as Sidebar from 'fumadocs-core/sidebar';
56
import type { ElementType } from 'react';
67
import type * as MDX from 'fumadocs-core/mdx-plugins';
78

8-
export type SortedResult = Server.SortedResult;
9+
export type SortedResult = Search.SortedResult;
910

1011
export type StructureOptions = MDX.StructureOptions;
1112

packages/core/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
"import": "./dist/hide-if-empty.js",
3333
"types": "./dist/hide-if-empty.d.ts"
3434
},
35+
"./search": {
36+
"import": "./dist/search/index.js",
37+
"types": "./dist/search/index.d.ts"
38+
},
3539
"./search/*": {
3640
"import": "./dist/search/*.js",
3741
"types": "./dist/search/*.d.ts"

packages/core/src/search/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { type StaticOptions } from '@/search/client/static';
66
import { type AlgoliaOptions } from '@/search/client/algolia';
77
import { type OramaCloudOptions } from '@/search/client/orama-cloud';
88
import { type MixedbreadOptions } from '@/search/client/mixedbread';
9-
import type { SortedResult } from '@/search/shared';
9+
import type { SortedResult } from '@/search';
1010

1111
interface UseDocsSearch {
1212
search: string;

packages/core/src/search/client/algolia.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BaseIndex } from '@/search/algolia';
22
import type { Hit, LiteClient, SearchResponse } from 'algoliasearch/lite';
3-
import { createContentHighlighter, type SortedResult } from '@/search/shared';
3+
import { createContentHighlighter, type SortedResult } from '@/search';
44

55
export interface AlgoliaOptions {
66
indexName: string;

packages/core/src/search/client/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SortedResult } from '@/server';
1+
import type { SortedResult } from '@/search';
22

33
export interface FetchOptions {
44
/**

packages/core/src/search/client/mixedbread.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SortedResult } from '@/server';
1+
import type { SortedResult } from '@/search';
22
import Mixedbread from '@mixedbread/sdk';
33
import { VectorStoreSearchResponse } from '@mixedbread/sdk/resources/vector-stores';
44
import removeMd from 'remove-markdown';

packages/core/src/search/client/orama-cloud.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import type { SortedResult } from '@/server';
21
import type { ClientSearchParams, OramaClient } from '@oramacloud/client';
32
import { removeUndefined } from '@/utils/remove-undefined';
43
import type { OramaIndex } from '@/search/orama-cloud';
5-
import { createContentHighlighter } from '@/search/shared';
4+
import { createContentHighlighter, type SortedResult } from '@/search';
65

76
interface CrawlerIndex {
87
path: string;
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
export interface SortedResult {
1+
import type { ReactNode } from 'react';
2+
3+
export interface SortedResult<Content = string> {
24
id: string;
35
url: string;
46
type: 'page' | 'heading' | 'text';
5-
content: string;
6-
contentWithHighlights?: HighlightedText[];
7+
content: Content;
8+
9+
/**
10+
* breadcrumbs to be displayed on UI
11+
*/
12+
breadcrumbs?: Content[];
13+
contentWithHighlights?: HighlightedText<Content>[];
714
}
815

9-
export type HighlightedText = {
16+
export type ReactSortedResult = SortedResult<ReactNode>;
17+
18+
export interface HighlightedText<Content = string> {
1019
type: 'text';
11-
content: string;
20+
content: Content;
1221
styles?: {
1322
highlight?: boolean;
1423
};
15-
};
24+
}
1625

1726
function escapeRegExp(input: string): string {
1827
return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

packages/core/src/search/orama/search/advanced.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import {
44
type advancedSchema,
55
} from '@/search/orama/create-db';
66
import { removeUndefined } from '@/utils/remove-undefined';
7-
import type { SortedResult } from '@/server';
8-
import { createContentHighlighter } from '@/search/shared';
7+
import { createContentHighlighter, type SortedResult } from '@/search';
98

109
export async function searchAdvanced(
1110
db: Orama<typeof advancedSchema>,

0 commit comments

Comments
 (0)