@sitecore-content-sdk/react 2.4.0-canary.20260824045921 → 2.4.0-canary.20260826121528

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.debug = exports.useInfiniteSearch = exports.useSearch = void 0;
3
+ exports.debug = exports.useSuggest = exports.useInfiniteSearch = exports.useSearch = void 0;
4
4
  var useSearch_1 = require("./useSearch");
5
5
  Object.defineProperty(exports, "useSearch", { enumerable: true, get: function () { return useSearch_1.useSearch; } });
6
6
  var useInfiniteSearch_1 = require("./useInfiniteSearch");
7
7
  Object.defineProperty(exports, "useInfiniteSearch", { enumerable: true, get: function () { return useInfiniteSearch_1.useInfiniteSearch; } });
8
+ var useSuggest_1 = require("./useSuggest");
9
+ Object.defineProperty(exports, "useSuggest", { enumerable: true, get: function () { return useSuggest_1.useSuggest; } });
8
10
  var search_1 = require("@sitecore-content-sdk/search");
9
11
  Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return search_1.debug; } });
@@ -6,13 +6,15 @@ const react_1 = require("react");
6
6
  const utils_1 = require("./utils");
7
7
  /**
8
8
  * React hook for performing infinite search queries.
9
+ * Supports keyword search via `query` and More Like This (MLT) via `seedItemId` or `seedItemUrl`.
10
+ * Those query fields are mutually exclusive.
9
11
  * @param {UseInfiniteSearchOptions} options - Configuration options for the infinite search hook.
10
12
  * @returns {UseInfiniteSearchState} The infinite search state.
11
13
  * @throws {Error} if the search index ID is not provided.
12
14
  * @public
13
15
  */
14
16
  const useInfiniteSearch = (options) => {
15
- const { query, searchIndexId, pageSize = utils_1.DEFAULT_PAGE_SIZE, sort, enabled = true, locale, facet } = options;
17
+ const { query, searchIndexId, pageSize = utils_1.DEFAULT_PAGE_SIZE, sort, enabled = true, locale, facet, seedItemId, seedItemUrl, } = options;
16
18
  const [state, setState] = (0, react_1.useState)(() => {
17
19
  const error = !searchIndexId
18
20
  ? new Error('useInfiniteSearch: searchIndexId is required when initializing the hook')
@@ -54,8 +56,8 @@ const useInfiniteSearch = (options) => {
54
56
  });
55
57
  }
56
58
  try {
57
- const searchParams = Object.assign(Object.assign({ searchIndexId, keyphrase: query, limit: pageSize, offset,
58
- sort }, (locale !== undefined && { locale })), (facet !== undefined && { facet }));
59
+ const searchParams = Object.assign(Object.assign(Object.assign(Object.assign({ searchIndexId, keyphrase: query, limit: pageSize, offset,
60
+ sort }, (locale !== undefined && { locale })), (facet !== undefined && { facet })), (seedItemId !== undefined && { seedItemId })), (seedItemUrl !== undefined && { seedItemUrl }));
59
61
  const { results: searchResults, total: totalResults, facets } = await searchService.search(searchParams, { signal });
60
62
  if (signal.aborted) {
61
63
  return;
@@ -98,7 +100,7 @@ const useInfiniteSearch = (options) => {
98
100
  });
99
101
  }
100
102
  }
101
- }, [searchService, pageSize, sort, query, searchIndexId, locale, facet]);
103
+ }, [searchService, pageSize, sort, query, searchIndexId, locale, facet, seedItemId, seedItemUrl]);
102
104
  (0, react_1.useEffect)(() => {
103
105
  if (enabled) {
104
106
  search(0, false);
@@ -5,13 +5,15 @@ const react_1 = require("react");
5
5
  const utils_1 = require("./utils");
6
6
  /**
7
7
  * React hook for performing search queries with pagination.
8
+ * Supports keyword search via `query` and More Like This (MLT) via `seedItemId` or `seedItemUrl`.
9
+ * Those query fields are mutually exclusive.
8
10
  * @param {UseSearchOptions} options - Configuration options for the search hook.
9
11
  * @returns {UseSearchState} The search state.
10
12
  * @throws {Error} if the search index ID is not provided.
11
13
  * @public
12
14
  */
13
15
  const useSearch = (options) => {
14
- const { query, page = 1, searchIndexId, pageSize = utils_1.DEFAULT_PAGE_SIZE, sort, enabled = true, keepPreviousData = false, locale, facet, } = options;
16
+ const { query, page = 1, searchIndexId, pageSize = utils_1.DEFAULT_PAGE_SIZE, sort, enabled = true, keepPreviousData = false, locale, facet, seedItemId, seedItemUrl, } = options;
15
17
  const [state, setState] = (0, react_1.useState)(() => {
16
18
  const error = !searchIndexId
17
19
  ? new Error('useSearch: searchIndexId is required when initializing the hook')
@@ -46,8 +48,8 @@ const useSearch = (options) => {
46
48
  }));
47
49
  try {
48
50
  const offset = (0, utils_1.getOffset)(page, pageSize);
49
- const searchParams = Object.assign(Object.assign({ searchIndexId, keyphrase: query, limit: pageSize, offset,
50
- sort }, (locale !== undefined && { locale })), (facet !== undefined && { facet }));
51
+ const searchParams = Object.assign(Object.assign(Object.assign(Object.assign({ searchIndexId, keyphrase: query, limit: pageSize, offset,
52
+ sort }, (locale !== undefined && { locale })), (facet !== undefined && { facet })), (seedItemId !== undefined && { seedItemId })), (seedItemUrl !== undefined && { seedItemUrl }));
51
53
  const { results: searchResults, total, facets } = await searchService.search(searchParams, {
52
54
  signal,
53
55
  });
@@ -81,7 +83,7 @@ const useSearch = (options) => {
81
83
  previousStatus: 'error',
82
84
  });
83
85
  }
84
- }, [searchService, searchIndexId, page, pageSize, sort, query, keepPreviousData, locale, facet]);
86
+ }, [searchService, searchIndexId, page, pageSize, sort, query, keepPreviousData, locale, facet, seedItemId, seedItemUrl]);
85
87
  (0, react_1.useEffect)(() => {
86
88
  if (enabled) {
87
89
  search();
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSuggest = void 0;
4
+ const react_1 = require("react");
5
+ const utils_1 = require("./utils");
6
+ /**
7
+ * React hook for typeahead suggestions via `/v1/search/suggest`.
8
+ * @param {UseSuggestOptions} options - Configuration options for the suggest hook.
9
+ * @returns {UseSuggestState} The suggest state.
10
+ * @throws {Error} if the search index ID is not provided.
11
+ * @public
12
+ */
13
+ const useSuggest = (options) => {
14
+ const { query, searchIndexId, enabled = true, keepPreviousData = false, locale } = options;
15
+ const trimmedQuery = typeof query === 'string' ? query.trim() : '';
16
+ const [state, setState] = (0, react_1.useState)(() => {
17
+ const error = !searchIndexId
18
+ ? new Error('useSuggest: searchIndexId is required when initializing the hook')
19
+ : null;
20
+ const status = !searchIndexId ? 'error' : 'idle';
21
+ return {
22
+ querySuggestions: [],
23
+ previewResults: [],
24
+ error,
25
+ status,
26
+ previousStatus: 'idle',
27
+ };
28
+ });
29
+ const searchService = (0, utils_1.useSearchService)();
30
+ const abortControllerRef = (0, react_1.useRef)(null);
31
+ const suggest = (0, react_1.useCallback)(async () => {
32
+ if (!searchService || !searchIndexId) {
33
+ return;
34
+ }
35
+ if (!trimmedQuery) {
36
+ setState((prev) => ({
37
+ querySuggestions: keepPreviousData ? prev.querySuggestions : [],
38
+ previewResults: keepPreviousData ? prev.previewResults : [],
39
+ status: 'idle',
40
+ error: null,
41
+ previousStatus: prev.status,
42
+ }));
43
+ return;
44
+ }
45
+ abortControllerRef.current = new AbortController();
46
+ const signal = abortControllerRef.current.signal;
47
+ setState((prev) => ({
48
+ querySuggestions: keepPreviousData ? prev.querySuggestions : [],
49
+ previewResults: keepPreviousData ? prev.previewResults : [],
50
+ status: 'loading',
51
+ error: null,
52
+ previousStatus: prev.status,
53
+ }));
54
+ try {
55
+ const suggestParams = Object.assign({ searchIndexId, keyphrase: trimmedQuery }, (locale !== undefined && { locale }));
56
+ const { querySuggestions, previewResults } = await searchService.suggest(suggestParams, {
57
+ signal,
58
+ });
59
+ if (signal.aborted) {
60
+ return;
61
+ }
62
+ setState({
63
+ querySuggestions,
64
+ previewResults,
65
+ status: 'success',
66
+ error: null,
67
+ previousStatus: 'success',
68
+ });
69
+ }
70
+ catch (err) {
71
+ if (signal.aborted) {
72
+ return;
73
+ }
74
+ const errorMessage = err instanceof Error ? err : new Error(JSON.stringify(err));
75
+ setState({
76
+ querySuggestions: [],
77
+ previewResults: [],
78
+ status: 'error',
79
+ error: errorMessage,
80
+ previousStatus: 'error',
81
+ });
82
+ }
83
+ }, [searchService, searchIndexId, trimmedQuery, keepPreviousData, locale]);
84
+ (0, react_1.useEffect)(() => {
85
+ if (enabled) {
86
+ suggest();
87
+ }
88
+ return () => {
89
+ var _a;
90
+ (_a = abortControllerRef.current) === null || _a === void 0 ? void 0 : _a.abort();
91
+ };
92
+ }, [suggest, enabled]);
93
+ return (0, react_1.useMemo)(() => ({
94
+ error: state.error,
95
+ querySuggestions: state.querySuggestions,
96
+ previewResults: state.previewResults,
97
+ status: state.status,
98
+ isLoading: state.status === 'loading',
99
+ isSuccess: state.status === 'success',
100
+ isError: state.status === 'error',
101
+ isPreviousData: keepPreviousData && state.previousStatus === 'success' && state.status === 'loading',
102
+ }), [state, keepPreviousData]);
103
+ };
104
+ exports.useSuggest = useSuggest;
@@ -1,3 +1,4 @@
1
1
  export { useSearch } from './useSearch';
2
2
  export { useInfiniteSearch, } from './useInfiniteSearch';
3
+ export { useSuggest } from './useSuggest';
3
4
  export { debug } from '@sitecore-content-sdk/search';
@@ -3,13 +3,15 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { DEFAULT_PAGE_SIZE, useSearchService } from './utils';
4
4
  /**
5
5
  * React hook for performing infinite search queries.
6
+ * Supports keyword search via `query` and More Like This (MLT) via `seedItemId` or `seedItemUrl`.
7
+ * Those query fields are mutually exclusive.
6
8
  * @param {UseInfiniteSearchOptions} options - Configuration options for the infinite search hook.
7
9
  * @returns {UseInfiniteSearchState} The infinite search state.
8
10
  * @throws {Error} if the search index ID is not provided.
9
11
  * @public
10
12
  */
11
13
  export const useInfiniteSearch = (options) => {
12
- const { query, searchIndexId, pageSize = DEFAULT_PAGE_SIZE, sort, enabled = true, locale, facet } = options;
14
+ const { query, searchIndexId, pageSize = DEFAULT_PAGE_SIZE, sort, enabled = true, locale, facet, seedItemId, seedItemUrl, } = options;
13
15
  const [state, setState] = useState(() => {
14
16
  const error = !searchIndexId
15
17
  ? new Error('useInfiniteSearch: searchIndexId is required when initializing the hook')
@@ -51,8 +53,8 @@ export const useInfiniteSearch = (options) => {
51
53
  });
52
54
  }
53
55
  try {
54
- const searchParams = Object.assign(Object.assign({ searchIndexId, keyphrase: query, limit: pageSize, offset,
55
- sort }, (locale !== undefined && { locale })), (facet !== undefined && { facet }));
56
+ const searchParams = Object.assign(Object.assign(Object.assign(Object.assign({ searchIndexId, keyphrase: query, limit: pageSize, offset,
57
+ sort }, (locale !== undefined && { locale })), (facet !== undefined && { facet })), (seedItemId !== undefined && { seedItemId })), (seedItemUrl !== undefined && { seedItemUrl }));
56
58
  const { results: searchResults, total: totalResults, facets } = await searchService.search(searchParams, { signal });
57
59
  if (signal.aborted) {
58
60
  return;
@@ -95,7 +97,7 @@ export const useInfiniteSearch = (options) => {
95
97
  });
96
98
  }
97
99
  }
98
- }, [searchService, pageSize, sort, query, searchIndexId, locale, facet]);
100
+ }, [searchService, pageSize, sort, query, searchIndexId, locale, facet, seedItemId, seedItemUrl]);
99
101
  useEffect(() => {
100
102
  if (enabled) {
101
103
  search(0, false);
@@ -2,13 +2,15 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
2
  import { DEFAULT_PAGE_SIZE, getOffset, useSearchService } from './utils';
3
3
  /**
4
4
  * React hook for performing search queries with pagination.
5
+ * Supports keyword search via `query` and More Like This (MLT) via `seedItemId` or `seedItemUrl`.
6
+ * Those query fields are mutually exclusive.
5
7
  * @param {UseSearchOptions} options - Configuration options for the search hook.
6
8
  * @returns {UseSearchState} The search state.
7
9
  * @throws {Error} if the search index ID is not provided.
8
10
  * @public
9
11
  */
10
12
  export const useSearch = (options) => {
11
- const { query, page = 1, searchIndexId, pageSize = DEFAULT_PAGE_SIZE, sort, enabled = true, keepPreviousData = false, locale, facet, } = options;
13
+ const { query, page = 1, searchIndexId, pageSize = DEFAULT_PAGE_SIZE, sort, enabled = true, keepPreviousData = false, locale, facet, seedItemId, seedItemUrl, } = options;
12
14
  const [state, setState] = useState(() => {
13
15
  const error = !searchIndexId
14
16
  ? new Error('useSearch: searchIndexId is required when initializing the hook')
@@ -43,8 +45,8 @@ export const useSearch = (options) => {
43
45
  }));
44
46
  try {
45
47
  const offset = getOffset(page, pageSize);
46
- const searchParams = Object.assign(Object.assign({ searchIndexId, keyphrase: query, limit: pageSize, offset,
47
- sort }, (locale !== undefined && { locale })), (facet !== undefined && { facet }));
48
+ const searchParams = Object.assign(Object.assign(Object.assign(Object.assign({ searchIndexId, keyphrase: query, limit: pageSize, offset,
49
+ sort }, (locale !== undefined && { locale })), (facet !== undefined && { facet })), (seedItemId !== undefined && { seedItemId })), (seedItemUrl !== undefined && { seedItemUrl }));
48
50
  const { results: searchResults, total, facets } = await searchService.search(searchParams, {
49
51
  signal,
50
52
  });
@@ -78,7 +80,7 @@ export const useSearch = (options) => {
78
80
  previousStatus: 'error',
79
81
  });
80
82
  }
81
- }, [searchService, searchIndexId, page, pageSize, sort, query, keepPreviousData, locale, facet]);
83
+ }, [searchService, searchIndexId, page, pageSize, sort, query, keepPreviousData, locale, facet, seedItemId, seedItemUrl]);
82
84
  useEffect(() => {
83
85
  if (enabled) {
84
86
  search();
@@ -0,0 +1,100 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { useSearchService } from './utils';
3
+ /**
4
+ * React hook for typeahead suggestions via `/v1/search/suggest`.
5
+ * @param {UseSuggestOptions} options - Configuration options for the suggest hook.
6
+ * @returns {UseSuggestState} The suggest state.
7
+ * @throws {Error} if the search index ID is not provided.
8
+ * @public
9
+ */
10
+ export const useSuggest = (options) => {
11
+ const { query, searchIndexId, enabled = true, keepPreviousData = false, locale } = options;
12
+ const trimmedQuery = typeof query === 'string' ? query.trim() : '';
13
+ const [state, setState] = useState(() => {
14
+ const error = !searchIndexId
15
+ ? new Error('useSuggest: searchIndexId is required when initializing the hook')
16
+ : null;
17
+ const status = !searchIndexId ? 'error' : 'idle';
18
+ return {
19
+ querySuggestions: [],
20
+ previewResults: [],
21
+ error,
22
+ status,
23
+ previousStatus: 'idle',
24
+ };
25
+ });
26
+ const searchService = useSearchService();
27
+ const abortControllerRef = useRef(null);
28
+ const suggest = useCallback(async () => {
29
+ if (!searchService || !searchIndexId) {
30
+ return;
31
+ }
32
+ if (!trimmedQuery) {
33
+ setState((prev) => ({
34
+ querySuggestions: keepPreviousData ? prev.querySuggestions : [],
35
+ previewResults: keepPreviousData ? prev.previewResults : [],
36
+ status: 'idle',
37
+ error: null,
38
+ previousStatus: prev.status,
39
+ }));
40
+ return;
41
+ }
42
+ abortControllerRef.current = new AbortController();
43
+ const signal = abortControllerRef.current.signal;
44
+ setState((prev) => ({
45
+ querySuggestions: keepPreviousData ? prev.querySuggestions : [],
46
+ previewResults: keepPreviousData ? prev.previewResults : [],
47
+ status: 'loading',
48
+ error: null,
49
+ previousStatus: prev.status,
50
+ }));
51
+ try {
52
+ const suggestParams = Object.assign({ searchIndexId, keyphrase: trimmedQuery }, (locale !== undefined && { locale }));
53
+ const { querySuggestions, previewResults } = await searchService.suggest(suggestParams, {
54
+ signal,
55
+ });
56
+ if (signal.aborted) {
57
+ return;
58
+ }
59
+ setState({
60
+ querySuggestions,
61
+ previewResults,
62
+ status: 'success',
63
+ error: null,
64
+ previousStatus: 'success',
65
+ });
66
+ }
67
+ catch (err) {
68
+ if (signal.aborted) {
69
+ return;
70
+ }
71
+ const errorMessage = err instanceof Error ? err : new Error(JSON.stringify(err));
72
+ setState({
73
+ querySuggestions: [],
74
+ previewResults: [],
75
+ status: 'error',
76
+ error: errorMessage,
77
+ previousStatus: 'error',
78
+ });
79
+ }
80
+ }, [searchService, searchIndexId, trimmedQuery, keepPreviousData, locale]);
81
+ useEffect(() => {
82
+ if (enabled) {
83
+ suggest();
84
+ }
85
+ return () => {
86
+ var _a;
87
+ (_a = abortControllerRef.current) === null || _a === void 0 ? void 0 : _a.abort();
88
+ };
89
+ }, [suggest, enabled]);
90
+ return useMemo(() => ({
91
+ error: state.error,
92
+ querySuggestions: state.querySuggestions,
93
+ previewResults: state.previewResults,
94
+ status: state.status,
95
+ isLoading: state.status === 'loading',
96
+ isSuccess: state.status === 'success',
97
+ isError: state.status === 'error',
98
+ isPreviousData: keepPreviousData && state.previousStatus === 'success' && state.status === 'loading',
99
+ }), [state, keepPreviousData]);
100
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/react",
3
- "version": "2.4.0-canary.20260824045921",
3
+ "version": "2.4.0-canary.20260826121528",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -32,7 +32,7 @@
32
32
  "url": "https://github.com/sitecore/content-sdk/issues"
33
33
  },
34
34
  "devDependencies": {
35
- "@sitecore-content-sdk/analytics-core": "2.1.3-canary.20260824045921",
35
+ "@sitecore-content-sdk/analytics-core": "2.1.3-canary.20260826121528",
36
36
  "@sitecore-feaas/clientside": "^0.6.0",
37
37
  "@stylistic/eslint-plugin": "^5.2.2",
38
38
  "@testing-library/dom": "^10.4.0",
@@ -71,16 +71,16 @@
71
71
  "typescript": "~5.8.3"
72
72
  },
73
73
  "peerDependencies": {
74
- "@sitecore-content-sdk/analytics-core": "2.1.3-canary.20260824045921",
75
- "@sitecore-content-sdk/events": "2.1.3-canary.20260824045921",
74
+ "@sitecore-content-sdk/analytics-core": "2.1.3-canary.20260826121528",
75
+ "@sitecore-content-sdk/events": "2.1.3-canary.20260826121528",
76
76
  "@sitecore-feaas/clientside": "^0.6.0",
77
77
  "react": "^19.2.1",
78
78
  "react-dom": "^19.2.1"
79
79
  },
80
80
  "dependencies": {
81
- "@sitecore-content-sdk/content": "2.3.0-canary.20260824045921",
82
- "@sitecore-content-sdk/core": "2.1.4-canary.20260824045921",
83
- "@sitecore-content-sdk/search": "0.4.1-canary.20260824045921",
81
+ "@sitecore-content-sdk/content": "2.3.0-canary.20260826121528",
82
+ "@sitecore-content-sdk/core": "2.1.4-canary.20260826121528",
83
+ "@sitecore-content-sdk/search": "0.5.0-canary.20260826121528",
84
84
  "fast-deep-equal": "^3.1.3"
85
85
  },
86
86
  "description": "",
@@ -1,5 +1,6 @@
1
1
  export { useSearch, UseSearchState, UseSearchOptions } from './useSearch';
2
2
  export { useInfiniteSearch, UseInfiniteSearchState, UseInfiniteSearchOptions, } from './useInfiniteSearch';
3
+ export { useSuggest, UseSuggestState, UseSuggestOptions } from './useSuggest';
3
4
  export { SearchStatus } from './utils';
4
5
  export { debug } from '@sitecore-content-sdk/search';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC"}
@@ -2,12 +2,15 @@ import { SearchStatus } from './utils';
2
2
  import { SearchDocument, SearchParameters, FacetRequest, FacetResult } from '@sitecore-content-sdk/search';
3
3
  /**
4
4
  * Options for the useInfiniteSearch hook.
5
+ * `query`, `seedItemId`, and `seedItemUrl` are mutually exclusive.
6
+ * Use `seedItemId` or `seedItemUrl` for More Like This (MLT) widget queries.
5
7
  * @public
6
8
  */
7
9
  export interface UseInfiniteSearchOptions<T extends SearchDocument = SearchDocument> {
8
10
  /**
9
11
  * The query string to search for.
10
12
  * By default empty string is used.
13
+ * Mutually exclusive with `seedItemId` and `seedItemUrl`.
11
14
  */
12
15
  query?: string;
13
16
  /**
@@ -39,6 +42,16 @@ export interface UseInfiniteSearchOptions<T extends SearchDocument = SearchDocum
39
42
  * Use 'fields' to filter results by specific facet values. Both can be combined.
40
43
  */
41
44
  facet?: FacetRequest;
45
+ /**
46
+ * Item ID used as the seed for More Like This (MLT) results.
47
+ * Mutually exclusive with `query` and `seedItemUrl`.
48
+ */
49
+ seedItemId?: string;
50
+ /**
51
+ * Item URL used as the seed for More Like This (MLT) results.
52
+ * Mutually exclusive with `query` and `seedItemId`.
53
+ */
54
+ seedItemUrl?: string;
42
55
  }
43
56
  /**
44
57
  * The state of the useInfiniteSearch hook.
@@ -121,6 +134,8 @@ type InternalInfiniteSearchState<T extends SearchDocument = SearchDocument> = {
121
134
  };
122
135
  /**
123
136
  * React hook for performing infinite search queries.
137
+ * Supports keyword search via `query` and More Like This (MLT) via `seedItemId` or `seedItemUrl`.
138
+ * Those query fields are mutually exclusive.
124
139
  * @param {UseInfiniteSearchOptions} options - Configuration options for the infinite search hook.
125
140
  * @returns {UseInfiniteSearchState} The infinite search state.
126
141
  * @throws {Error} if the search index ID is not provided.
@@ -1 +1 @@
1
- {"version":3,"file":"useInfiniteSearch.d.ts","sourceRoot":"","sources":["../../src/search/useInfiniteSearch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,YAAY,EAAoB,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3G;;;GAGG;AACH,MAAM,WAAW,wBAAwB,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc;IACjF;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IAC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,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IACvB;;OAEG;IACH,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,KAAK,2BAA2B,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,IAAI;IAC5E;;OAEG;IACH,OAAO,EAAE,CAAC,EAAE,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IACvB;;OAEG;IACH,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;;;OAQG;IACH,MAAM,EAAE,YAAY,CAAC;IACrB;;;;;;;OAOG;IACH,cAAc,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;CAC/C,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,cAAc,GAAG,cAAc,EACzE,SAAS,wBAAwB,CAAC,CAAC,CAAC,KACnC,sBAAsB,CAAC,CAAC,CAgL1B,CAAC"}
@@ -2,12 +2,15 @@ import { SearchDocument, SearchParameters, FacetRequest, FacetResult } from '@si
2
2
  import { SearchStatus } from './utils';
3
3
  /**
4
4
  * Options for the useSearch hook.
5
+ * `query`, `seedItemId`, and `seedItemUrl` are mutually exclusive.
6
+ * Use `seedItemId` or `seedItemUrl` for More Like This (MLT) widget queries.
5
7
  * @public
6
8
  */
7
9
  export interface UseSearchOptions<T extends SearchDocument = SearchDocument> {
8
10
  /**
9
11
  * The query string to search for.
10
12
  * By default empty string is used.
13
+ * Mutually exclusive with `seedItemId` and `seedItemUrl`.
11
14
  */
12
15
  query?: string;
13
16
  /**
@@ -49,6 +52,16 @@ export interface UseSearchOptions<T extends SearchDocument = SearchDocument> {
49
52
  * Use 'fields' to filter results by specific facet values. Both can be combined.
50
53
  */
51
54
  facet?: FacetRequest;
55
+ /**
56
+ * Item ID used as the seed for More Like This (MLT) results.
57
+ * Mutually exclusive with `query` and `seedItemUrl`.
58
+ */
59
+ seedItemId?: string;
60
+ /**
61
+ * Item URL used as the seed for More Like This (MLT) results.
62
+ * Mutually exclusive with `query` and `seedItemId`.
63
+ */
64
+ seedItemUrl?: string;
52
65
  }
53
66
  type InternalState<T extends SearchDocument = SearchDocument> = {
54
67
  /**
@@ -112,6 +125,8 @@ export type UseSearchState<T extends SearchDocument = SearchDocument> = Omit<Int
112
125
  };
113
126
  /**
114
127
  * React hook for performing search queries with pagination.
128
+ * Supports keyword search via `query` and More Like This (MLT) via `seedItemId` or `seedItemUrl`.
129
+ * Those query fields are mutually exclusive.
115
130
  * @param {UseSearchOptions} options - Configuration options for the search hook.
116
131
  * @returns {UseSearchState} The search state.
117
132
  * @throws {Error} if the search index ID is not provided.
@@ -1 +1 @@
1
- {"version":3,"file":"useSearch.d.ts","sourceRoot":"","sources":["../../src/search/useSearch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3G,OAAO,EAAgC,YAAY,EAAoB,MAAM,SAAS,CAAC;AAEvF;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc;IACzE;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,IAAI,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACnC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,gBAA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AAS,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,SAAS,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,cAAc,GAAG,cAAc,EACjE,SAAS,gBAAgB,CAAC,CAAC,CAAC,KAC3B,cAAc,CAAC,CAAC,CAqIlB,CAAC"}
@@ -0,0 +1,97 @@
1
+ import { SearchDocument, QuerySuggestionItem } from '@sitecore-content-sdk/search';
2
+ import { SearchStatus } from './utils';
3
+ /**
4
+ * Options for the useSuggest hook.
5
+ * `/v1/search/suggest` accepts only `keyphrase`; `seedItemId` and `seedItemUrl` are not supported.
6
+ * @public
7
+ */
8
+ export interface UseSuggestOptions {
9
+ /**
10
+ * Partial text used for typeahead suggestions.
11
+ * Mapped to `keyphrase` on `SearchService.suggest()`.
12
+ * When omitted or whitespace only, no request is sent.
13
+ */
14
+ query?: string;
15
+ /**
16
+ * The ID of the search index to use.
17
+ */
18
+ searchIndexId: string;
19
+ /**
20
+ * Specifies whether the suggest request should automatically run.
21
+ * @default true
22
+ */
23
+ enabled?: boolean;
24
+ /**
25
+ * Specifies whether the previous suggestions should be kept when fetching new results.
26
+ * @default false
27
+ */
28
+ keepPreviousData?: boolean;
29
+ /**
30
+ * The locale to use for the suggest request. Required for multi-locale index configurations.
31
+ * Format: letters and hyphens only (e.g. 'en', 'fr-FR', 'el-GR').
32
+ * Omit for single-locale indexes.
33
+ */
34
+ locale?: string;
35
+ }
36
+ type InternalSuggestState<T extends SearchDocument = SearchDocument> = {
37
+ /**
38
+ * Autocomplete completions from query suggestion mode.
39
+ */
40
+ querySuggestions: QuerySuggestionItem[];
41
+ /**
42
+ * Document previews from preview results mode.
43
+ */
44
+ previewResults: T[];
45
+ /**
46
+ * The error object if the last suggest request failed, or null if no error occurred.
47
+ */
48
+ error: Error | null;
49
+ /**
50
+ * The status of the suggest request.
51
+ * It will be set to:
52
+ * - 'idle' if no suggest request has been made yet.
53
+ * - 'loading' if a suggest request is currently in progress.
54
+ * - 'success' if a suggest request was successful.
55
+ * - 'error' if a suggest request failed.
56
+ * @default 'idle'
57
+ */
58
+ status: SearchStatus;
59
+ /**
60
+ * The status of the previous suggest request.
61
+ * @default 'idle'
62
+ */
63
+ previousStatus: SearchStatus;
64
+ };
65
+ /**
66
+ * The state of the useSuggest hook.
67
+ * @public
68
+ */
69
+ export type UseSuggestState<T extends SearchDocument = SearchDocument> = Omit<InternalSuggestState<T>, 'previousStatus'> & {
70
+ /**
71
+ * Whether a suggest request is currently in progress.
72
+ */
73
+ isLoading: boolean;
74
+ /**
75
+ * Whether the suggest request was successful.
76
+ */
77
+ isSuccess: boolean;
78
+ /**
79
+ * Whether the suggest request failed.
80
+ */
81
+ isError: boolean;
82
+ /**
83
+ * Whether the suggestions from the previous query are returned.
84
+ * Will be `true` if `keepPreviousData` is set.
85
+ */
86
+ isPreviousData: boolean;
87
+ };
88
+ /**
89
+ * React hook for typeahead suggestions via `/v1/search/suggest`.
90
+ * @param {UseSuggestOptions} options - Configuration options for the suggest hook.
91
+ * @returns {UseSuggestState} The suggest state.
92
+ * @throws {Error} if the search index ID is not provided.
93
+ * @public
94
+ */
95
+ export declare const useSuggest: <T extends SearchDocument = SearchDocument>(options: UseSuggestOptions) => UseSuggestState<T>;
96
+ export {};
97
+ //# sourceMappingURL=useSuggest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSuggest.d.ts","sourceRoot":"","sources":["../../src/search/useSuggest.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EAEd,mBAAmB,EACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,YAAY,EAAoB,MAAM,SAAS,CAAC;AAEzD;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CA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