Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/site-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const client = buildClient({ apiToken: 'YOUR_API_TOKEN' });

const { state, error, data } = useSiteSearch({
client,
buildTriggerId: '7497',
searchIndexId: '7497',
// optional: by default fuzzy-search is not active
fuzzySearch: true,
// optional: you can omit it you only have one locale, or you want to find results in every locale
Expand All @@ -60,7 +60,7 @@ For a complete walk-through, please refer to the [DatoCMS Site Search documentat
| prop | type | required | description | default |
| ------------------- | ------------------------------------------------------------------ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------- |
| client | CMA Client instance | :white_check_mark: | [DatoCMS CMA Client](https://www.datocms.com/docs/content-management-api/using-the-nodejs-clients) instance | |
| 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 | |
| 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 | |
| fuzzySearch | boolean | :x: | Whether fuzzy-search is active or not. When active, it will also find strings that approximately match the query provided. | false |
| resultsPerPage | number | :x: | The number of search results to show per page | 8 |
| 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>) |
Expand Down Expand Up @@ -127,7 +127,7 @@ function App() {
) : (
<mark key={key}>{text}</mark>
),
buildTriggerId: '7497',
searchIndexId: '7497',
resultsPerPage: 10,
});

Expand Down
186 changes: 114 additions & 72 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/src/SiteSearchExamples/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function SiteSearchExamples() {
const [query, setQuery] = useState('');
const { state, error, data } = useSiteSearch({
client,
buildTriggerId: '7497',
searchIndexId: '34759',
// optional: you can omit it you only have one locale, or you want to find results in every locale
initialState: { locale: 'en' },
// optional: by default fuzzy-search is not active
Expand Down
6 changes: 5 additions & 1 deletion src/useSiteSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type SearchResultInstancesHrefSchema = {
fuzzy?: boolean;
query: string;
build_trigger_id?: string;
search_index_id?: string;
locale?: string;
[k: string]: unknown;
};
Expand Down Expand Up @@ -62,7 +63,8 @@ type Highlighter = (

export type UseSiteSearchConfig<Client extends GenericClient> = {
client: Client;
buildTriggerId: string;
buildTriggerId?: string;
searchIndexId?: string;
fuzzySearch?: boolean;
resultsPerPage?: number;
highlightMatch?: Highlighter;
Expand Down Expand Up @@ -161,6 +163,7 @@ export function useSiteSearch<Client extends GenericClient>(
query: state.query,
locale: state.locale,
build_trigger_id: config.buildTriggerId,
search_index_id: config.searchIndexId,
...(config.fuzzySearch === true ? { fuzzy: true } : {}),
},
page: {
Expand Down Expand Up @@ -196,6 +199,7 @@ export function useSiteSearch<Client extends GenericClient>(
resultsPerPage,
state,
config.buildTriggerId,
config.searchIndexId,
config.fuzzySearch,
config.client.config.apiToken,
]);
Expand Down