Skip to content

Commit 0a39726

Browse files
committed
Add support for search indexes
1 parent f913d32 commit 0a39726

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

docs/site-search.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const client = buildClient({ apiToken: 'YOUR_API_TOKEN' });
3636

3737
const { state, error, data } = useSiteSearch({
3838
client,
39-
buildTriggerId: '7497',
39+
searchIndexId: '7497',
4040
// optional: by default fuzzy-search is not active
4141
fuzzySearch: true,
4242
// optional: you can omit it you only have one locale, or you want to find results in every locale
@@ -60,7 +60,7 @@ For a complete walk-through, please refer to the [DatoCMS Site Search documentat
6060
| prop | type | required | description | default |
6161
| ------------------- | ------------------------------------------------------------------ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------- |
6262
| client | CMA Client instance | :white_check_mark: | [DatoCMS CMA Client](https://www.datocms.com/docs/content-management-api/using-the-nodejs-clients) instance | |
63-
| buildTriggerId | string | :white_check_mark: | The [ID of the build trigger](https://www.datocms.com/docs/site-search/base-integration#performing-searches) to use to find search results | |
63+
| searchIndexId | string | :white_check_mark: | The [ID of the the search index](https://www.datocms.com/docs/site-search/base-integration#performing-searches) to use to find search results | |
6464
| fuzzySearch | boolean | :x: | Whether fuzzy-search is active or not. When active, it will also find strings that approximately match the query provided. | false |
6565
| resultsPerPage | number | :x: | The number of search results to show per page | 8 |
6666
| highlightMatch | (match, key, context: 'title' \| 'bodyExcerpt') => React.ReactNode | :x: | A function specifying how to highlight the part of page title/content that matches the query | (text, key) => (<mark key={key}>{text}</mark>) |
@@ -127,7 +127,7 @@ function App() {
127127
) : (
128128
<mark key={key}>{text}</mark>
129129
),
130-
buildTriggerId: '7497',
130+
searchIndexId: '7497',
131131
resultsPerPage: 10,
132132
});
133133

examples/src/SiteSearchExamples/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function SiteSearchExamples() {
1212
const [query, setQuery] = useState('');
1313
const { state, error, data } = useSiteSearch({
1414
client,
15-
buildTriggerId: '7497',
15+
searchIndexId: '7497',
1616
// optional: you can omit it you only have one locale, or you want to find results in every locale
1717
initialState: { locale: 'en' },
1818
// optional: by default fuzzy-search is not active

src/useSiteSearch/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type SearchResultInstancesHrefSchema = {
1515
fuzzy?: boolean;
1616
query: string;
1717
build_trigger_id?: string;
18+
search_index_id?: string;
1819
locale?: string;
1920
[k: string]: unknown;
2021
};
@@ -63,6 +64,7 @@ type Highlighter = (
6364
export type UseSiteSearchConfig<Client extends GenericClient> = {
6465
client: Client;
6566
buildTriggerId: string;
67+
searchIndexId: string;
6668
fuzzySearch?: boolean;
6769
resultsPerPage?: number;
6870
highlightMatch?: Highlighter;
@@ -161,6 +163,7 @@ export function useSiteSearch<Client extends GenericClient>(
161163
query: state.query,
162164
locale: state.locale,
163165
build_trigger_id: config.buildTriggerId,
166+
search_index_id: config.searchIndexId,
164167
...(config.fuzzySearch === true ? { fuzzy: true } : {}),
165168
},
166169
page: {
@@ -196,6 +199,7 @@ export function useSiteSearch<Client extends GenericClient>(
196199
resultsPerPage,
197200
state,
198201
config.buildTriggerId,
202+
config.searchIndexId,
199203
config.fuzzySearch,
200204
config.client.config.apiToken,
201205
]);

0 commit comments

Comments
 (0)