@searchcraft/javascript-sdk 0.11.1 → 0.12.1
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.
- package/README.md +11 -2
- package/dist/components/index.d.ts +44 -2
- package/dist/components/index.js +162 -95
- package/dist/components/index.js.map +1 -1
- package/dist/components/{p-3e41546c.js → p-02ad136b.js} +3 -3
- package/dist/components/{p-3e41546c.js.map → p-02ad136b.js.map} +1 -1
- package/dist/components/{p-b7e99386.js → p-870f81fd.js} +38 -6
- package/dist/components/p-870f81fd.js.map +1 -0
- package/dist/components/{p-0c495408.js → p-c8566920.js} +74 -33
- package/dist/components/p-c8566920.js.map +1 -0
- package/dist/components/searchcraft-facet-list.js +1 -1
- package/dist/components/searchcraft-filter-panel.js +3 -3
- package/dist/components/searchcraft-filter-panel.js.map +1 -1
- package/dist/components/searchcraft-input-form.js +1 -1
- package/dist/components/searchcraft-pagination.js +8 -2
- package/dist/components/searchcraft-pagination.js.map +1 -1
- package/dist/components/searchcraft-popover-form.js +22 -4
- package/dist/components/searchcraft-popover-form.js.map +1 -1
- package/dist/components/searchcraft-results-info.js +9 -1
- package/dist/components/searchcraft-results-info.js.map +1 -1
- package/dist/components/searchcraft-search-results-per-page.js +8 -2
- package/dist/components/searchcraft-search-results-per-page.js.map +1 -1
- package/dist/components/searchcraft-summary-box.js +42 -10
- package/dist/components/searchcraft-summary-box.js.map +1 -1
- package/dist/components/searchcraft-theme.js +1 -1
- package/dist/components/searchcraft-toggle-button.js +1 -1
- package/dist/hydrate/index.js +258 -116
- package/dist/hydrate/index.mjs +258 -116
- package/dist/types/classes/SearchcraftCore.d.ts +1 -1
- package/dist/types/clients/SearchClient.d.ts +1 -0
- package/dist/types/components/searchcraft-facet-list/searchcraft-facet-list.d.ts +1 -1
- package/dist/types/components/searchcraft-filter-panel/searchcraft-filter-panel.d.ts +1 -1
- package/dist/types/components/searchcraft-input-form/searchcraft-input-form.d.ts +5 -0
- package/dist/types/components/searchcraft-pagination/searchcraft-pagination.d.ts +1 -0
- package/dist/types/components/searchcraft-popover-form/searchcraft-popover-form.d.ts +10 -0
- package/dist/types/components/searchcraft-results-info/searchcraft-results-info.d.ts +1 -0
- package/dist/types/components/searchcraft-search-results-per-page/searchcraft-search-results-per-page.d.ts +1 -0
- package/dist/types/components/searchcraft-summary-box/searchcraft-summary-box.d.ts +17 -0
- package/dist/types/components.d.ts +24 -0
- package/dist/types/store/SearchcraftStore.types.d.ts +10 -2
- package/dist/types/types/core-types/Measure.types.d.ts +1 -0
- package/dist/types/types/core-types/SearchcraftConfig.types.d.ts +9 -1
- package/package.json +5 -4
- package/dist/components/p-0c495408.js.map +0 -1
- package/dist/components/p-b7e99386.js.map +0 -1
package/README.md
CHANGED
|
@@ -49,8 +49,17 @@ As early as possible in your app's lifecycle, initialize searchcraft, passing in
|
|
|
49
49
|
```js
|
|
50
50
|
import { Searchcraft } from '@searchcraft/javascript-sdk';
|
|
51
51
|
|
|
52
|
+
// Index Search Configuration
|
|
52
53
|
const searchcraft = new Searchcraft({
|
|
53
|
-
|
|
54
|
+
indexName: 'your_index_from_vektron',
|
|
55
|
+
readKey: 'your_read_key_from_vektron',
|
|
56
|
+
endpointURL: 'your_searchcraft_endpoint_url',
|
|
57
|
+
searchDebounceDelay: 50, // The amount of debounce, in millis, to add to search requests (optional)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// Federation Search Configuration (searches across multiple indices)
|
|
61
|
+
const federationSearchcraft = new Searchcraft({
|
|
62
|
+
federationName: 'your_federation_name',
|
|
54
63
|
readKey: 'your_read_key_from_vektron',
|
|
55
64
|
endpointURL: 'your_searchcraft_endpoint_url',
|
|
56
65
|
searchDebounceDelay: 50, // The amount of debounce, in millis, to add to search requests (optional)
|
|
@@ -170,7 +179,7 @@ You can subscribe to various events within Searchcraft:
|
|
|
170
179
|
```jsx
|
|
171
180
|
|
|
172
181
|
const searchcraft = new Searchcraft({
|
|
173
|
-
|
|
182
|
+
indexName: 'your_index_from_vektron',
|
|
174
183
|
readKey: 'your_read_key_from_vektron',
|
|
175
184
|
endpointURL: 'your_searchcraft_endpoint_url',
|
|
176
185
|
});
|
|
@@ -90,6 +90,7 @@ export interface MeasureRequestProperties {
|
|
|
90
90
|
searchcraft_organization_id?: string;
|
|
91
91
|
searchcraft_application_id?: string;
|
|
92
92
|
searchcraft_index_names: string[];
|
|
93
|
+
searchcraft_federation_name?: string;
|
|
93
94
|
search_term?: string;
|
|
94
95
|
number_of_documents?: number;
|
|
95
96
|
external_document_id?: string;
|
|
@@ -333,8 +334,16 @@ export interface SearchcraftConfig {
|
|
|
333
334
|
endpointURL: string;
|
|
334
335
|
/**
|
|
335
336
|
* Name of the Searchcraft search index to search for results within. If you are using Searchcraft Cloud, this value can be found within the Vektron dashboard in the Code Snippets section when configuring a search index.
|
|
337
|
+
*
|
|
338
|
+
* Note: Either `indexName` or `federationName` must be provided, but not both.
|
|
339
|
+
*/
|
|
340
|
+
indexName?: string;
|
|
341
|
+
/**
|
|
342
|
+
* Name of the Searchcraft federation to search across multiple indices. Federation search allows you to search across all indices defined in a federation with a single query.
|
|
343
|
+
*
|
|
344
|
+
* Note: Either `indexName` or `federationName` must be provided, but not both.
|
|
336
345
|
*/
|
|
337
|
-
|
|
346
|
+
federationName?: string;
|
|
338
347
|
/**
|
|
339
348
|
* The initial search query to call when Searchcraft is first initialized in your front-end application. This parameter can be used when you want to populate a page with an initial set of search results based on a query.
|
|
340
349
|
*
|
|
@@ -601,6 +610,7 @@ declare class SearchClient {
|
|
|
601
610
|
constructor(parent: SearchcraftCore, config: SearchcraftConfig, userId: string);
|
|
602
611
|
/**
|
|
603
612
|
* Getter for the base url used by the /search endpoint.
|
|
613
|
+
* Supports both index and federation search endpoints.
|
|
604
614
|
*/
|
|
605
615
|
private get baseSearchUrl();
|
|
606
616
|
/**
|
|
@@ -640,7 +650,9 @@ export interface SearchcraftStateFunctions {
|
|
|
640
650
|
removeFacetPathsForIndexField: (fieldName: string) => void;
|
|
641
651
|
removeRangeValueForIndexField: (fieldName: string) => void;
|
|
642
652
|
resetSearchValues: () => void;
|
|
643
|
-
search: (
|
|
653
|
+
search: (options?: {
|
|
654
|
+
skipSummary?: boolean;
|
|
655
|
+
}) => Promise<void>;
|
|
644
656
|
setPopoverVisibility: (isVisible: boolean) => void;
|
|
645
657
|
setSearchResultsCount: (count: number) => void;
|
|
646
658
|
setSearchResultsPage: (page: number) => void;
|
|
@@ -671,6 +683,11 @@ export interface SearchcraftStateValues {
|
|
|
671
683
|
searchClientRequestProperties: SearchClientRequestProperties | string | undefined | null;
|
|
672
684
|
searchClientResponseItems: SearchClientResponseItem[];
|
|
673
685
|
cachedSearchClientResponseItems: SearchClientResponseItem[];
|
|
686
|
+
cachedSearchResponseFacetPrime: FacetPrime | undefined | null;
|
|
687
|
+
cachedSupplementalFacetPrime: FacetPrime | undefined | null;
|
|
688
|
+
cachedSearchResponseTimeTaken: number | undefined;
|
|
689
|
+
cachedSearchResultsCount: number | undefined;
|
|
690
|
+
cachedSearchClientRequestProperties: SearchClientRequestProperties | string | undefined | null;
|
|
674
691
|
searchResponseTimeTaken: number | undefined;
|
|
675
692
|
searchResponseFacetPrime: FacetPrime | undefined | null;
|
|
676
693
|
supplementalFacetPrime: FacetPrime | undefined | null;
|
|
@@ -684,6 +701,7 @@ export interface SearchcraftStateValues {
|
|
|
684
701
|
hasSummaryBox: boolean;
|
|
685
702
|
isSummaryLoading: boolean;
|
|
686
703
|
summaryClient?: SummaryClient;
|
|
704
|
+
isSummaryNotEnabled: boolean;
|
|
687
705
|
}
|
|
688
706
|
export interface SearchcraftState extends SearchcraftStateFunctions, SearchcraftStateValues {
|
|
689
707
|
}
|
|
@@ -908,6 +926,10 @@ export namespace Components {
|
|
|
908
926
|
* The id of the Searchcraft instance that this component should use.
|
|
909
927
|
*/
|
|
910
928
|
"searchcraftId"?: string;
|
|
929
|
+
/**
|
|
930
|
+
* The value to display in the input field.
|
|
931
|
+
*/
|
|
932
|
+
"value"?: string;
|
|
911
933
|
}
|
|
912
934
|
/**
|
|
913
935
|
* This web component serves as the input label for the searchcraft-input-form component.
|
|
@@ -1048,6 +1070,14 @@ export namespace Components {
|
|
|
1048
1070
|
* The hotkey modifier that activates the popover. Used together with the `hotkey` prop.
|
|
1049
1071
|
*/
|
|
1050
1072
|
"hotkeyModifier"?: "ctrl" | "meta" | "alt" | "option";
|
|
1073
|
+
/**
|
|
1074
|
+
* The placeholder's render behavior. 'hide-on-focus' - Hide the placeholder text immediately when the input form gains focus. 'hide-on-text-entered' - Only hide the placeholder when the input form has text entered into it.
|
|
1075
|
+
*/
|
|
1076
|
+
"placeholderBehavior"?: "hide-on-focus" | "hide-on-text-entered";
|
|
1077
|
+
/**
|
|
1078
|
+
* The input element's placeholder value.
|
|
1079
|
+
*/
|
|
1080
|
+
"placeholderValue"?: string;
|
|
1051
1081
|
/**
|
|
1052
1082
|
* Formats the content rendered for each result.
|
|
1053
1083
|
*/
|
|
@@ -2163,6 +2193,10 @@ declare namespace LocalJSX {
|
|
|
2163
2193
|
* The id of the Searchcraft instance that this component should use.
|
|
2164
2194
|
*/
|
|
2165
2195
|
"searchcraftId"?: string;
|
|
2196
|
+
/**
|
|
2197
|
+
* The value to display in the input field.
|
|
2198
|
+
*/
|
|
2199
|
+
"value"?: string;
|
|
2166
2200
|
}
|
|
2167
2201
|
/**
|
|
2168
2202
|
* This web component serves as the input label for the searchcraft-input-form component.
|
|
@@ -2303,6 +2337,14 @@ declare namespace LocalJSX {
|
|
|
2303
2337
|
* The hotkey modifier that activates the popover. Used together with the `hotkey` prop.
|
|
2304
2338
|
*/
|
|
2305
2339
|
"hotkeyModifier"?: "ctrl" | "meta" | "alt" | "option";
|
|
2340
|
+
/**
|
|
2341
|
+
* The placeholder's render behavior. 'hide-on-focus' - Hide the placeholder text immediately when the input form gains focus. 'hide-on-text-entered' - Only hide the placeholder when the input form has text entered into it.
|
|
2342
|
+
*/
|
|
2343
|
+
"placeholderBehavior"?: "hide-on-focus" | "hide-on-text-entered";
|
|
2344
|
+
/**
|
|
2345
|
+
* The input element's placeholder value.
|
|
2346
|
+
*/
|
|
2347
|
+
"placeholderValue"?: string;
|
|
2306
2348
|
/**
|
|
2307
2349
|
* Formats the content rendered for each result.
|
|
2308
2350
|
*/
|
package/dist/components/index.js
CHANGED
|
@@ -264,7 +264,8 @@ class MeasureClient {
|
|
|
264
264
|
const request = {
|
|
265
265
|
event_name: eventName,
|
|
266
266
|
properties: {
|
|
267
|
-
searchcraft_index_names: [this.config.indexName],
|
|
267
|
+
searchcraft_index_names: this.config.indexName ? [this.config.indexName] : [],
|
|
268
|
+
searchcraft_federation_name: this.config.federationName,
|
|
268
269
|
session_id: this.sessionId,
|
|
269
270
|
...properties,
|
|
270
271
|
},
|
|
@@ -372,9 +373,12 @@ class SearchClient {
|
|
|
372
373
|
}
|
|
373
374
|
/**
|
|
374
375
|
* Getter for the base url used by the /search endpoint.
|
|
376
|
+
* Supports both index and federation search endpoints.
|
|
375
377
|
*/
|
|
376
378
|
get baseSearchUrl() {
|
|
377
|
-
return
|
|
379
|
+
return this.config.federationName
|
|
380
|
+
? `${this.config.endpointURL}/federation/${this.config.federationName}/search`
|
|
381
|
+
: `${this.config.endpointURL}/index/${this.config.indexName}/search`;
|
|
378
382
|
}
|
|
379
383
|
/**
|
|
380
384
|
* Immediately cancels all pending search requests.
|
|
@@ -1245,6 +1249,14 @@ class SummaryClient {
|
|
|
1245
1249
|
throw new Error('Invalid fetch response');
|
|
1246
1250
|
}
|
|
1247
1251
|
if (!fetchResponse.ok) {
|
|
1252
|
+
if (fetchResponse.status === 403) {
|
|
1253
|
+
console.warn('Please contact Searchcraft to enable AI summaries with your account');
|
|
1254
|
+
this.set({
|
|
1255
|
+
isSummaryLoading: false,
|
|
1256
|
+
isSummaryNotEnabled: true,
|
|
1257
|
+
});
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1248
1260
|
throw new Error(`HTTP ${fetchResponse.status}`);
|
|
1249
1261
|
}
|
|
1250
1262
|
const reader = fetchResponse.body.getReader();
|
|
@@ -1291,6 +1303,11 @@ const initialSearchcraftStateValues = {
|
|
|
1291
1303
|
searchClientRequestProperties: undefined,
|
|
1292
1304
|
searchClientResponseItems: [],
|
|
1293
1305
|
cachedSearchClientResponseItems: [],
|
|
1306
|
+
cachedSearchResponseFacetPrime: undefined,
|
|
1307
|
+
cachedSupplementalFacetPrime: undefined,
|
|
1308
|
+
cachedSearchResponseTimeTaken: undefined,
|
|
1309
|
+
cachedSearchResultsCount: undefined,
|
|
1310
|
+
cachedSearchClientRequestProperties: undefined,
|
|
1294
1311
|
searchResponseTimeTaken: undefined,
|
|
1295
1312
|
searchResponseFacetPrime: undefined,
|
|
1296
1313
|
supplementalFacetPrime: undefined,
|
|
@@ -1303,6 +1320,7 @@ const initialSearchcraftStateValues = {
|
|
|
1303
1320
|
hasSummaryBox: false,
|
|
1304
1321
|
summaryClient: undefined,
|
|
1305
1322
|
isSummaryLoading: false,
|
|
1323
|
+
isSummaryNotEnabled: false,
|
|
1306
1324
|
};
|
|
1307
1325
|
// const logger = new Logger({ logLevel: LogLevel.NONE });
|
|
1308
1326
|
const existingStores = {};
|
|
@@ -1322,27 +1340,38 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
1322
1340
|
}
|
|
1323
1341
|
const newStore = zustand.createStore((set, get) => {
|
|
1324
1342
|
const functions = {
|
|
1325
|
-
addFacetPathsForIndexField: (facetPaths) =>
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1343
|
+
addFacetPathsForIndexField: (facetPaths) => {
|
|
1344
|
+
set((state) => ({
|
|
1345
|
+
facetPathsForIndexFields: {
|
|
1346
|
+
...state.facetPathsForIndexFields,
|
|
1347
|
+
[facetPaths.fieldName]: facetPaths,
|
|
1348
|
+
},
|
|
1349
|
+
searchResultsPage: 1, // Reset to page 1 when filters change
|
|
1350
|
+
}));
|
|
1351
|
+
},
|
|
1331
1352
|
addRangeValueForIndexField: (rangeValue) => set((state) => ({
|
|
1332
1353
|
rangeValueForIndexFields: {
|
|
1333
1354
|
...state.rangeValueForIndexFields,
|
|
1334
1355
|
[rangeValue.fieldName]: rangeValue,
|
|
1335
1356
|
},
|
|
1336
1357
|
})),
|
|
1337
|
-
removeFacetPathsForIndexField: (fieldName) =>
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1358
|
+
removeFacetPathsForIndexField: (fieldName) => {
|
|
1359
|
+
console.log('[FACET] removeFacetPathsForIndexField', {
|
|
1360
|
+
fieldName,
|
|
1361
|
+
currentPage: get().searchResultsPage,
|
|
1362
|
+
stackTrace: new Error().stack,
|
|
1363
|
+
});
|
|
1364
|
+
set((state) => {
|
|
1365
|
+
const currentPaths = state.facetPathsForIndexFields;
|
|
1366
|
+
delete currentPaths[fieldName];
|
|
1367
|
+
return {
|
|
1368
|
+
facetPathsForIndexFields: {
|
|
1369
|
+
...currentPaths,
|
|
1370
|
+
},
|
|
1371
|
+
searchResultsPage: 1, // Reset to page 1 when filters change
|
|
1372
|
+
};
|
|
1373
|
+
});
|
|
1374
|
+
},
|
|
1346
1375
|
removeRangeValueForIndexField: (fieldName) => set((state) => {
|
|
1347
1376
|
const currentValues = state.rangeValueForIndexFields;
|
|
1348
1377
|
delete currentValues[fieldName];
|
|
@@ -1362,22 +1391,91 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
1362
1391
|
adClientResponseItems: [...state.cachedAdClientResponseItems],
|
|
1363
1392
|
});
|
|
1364
1393
|
},
|
|
1365
|
-
search: async () => {
|
|
1394
|
+
search: async (options) => {
|
|
1366
1395
|
const state = get();
|
|
1367
1396
|
if (!state.core) {
|
|
1368
1397
|
throw new Error('Searchcraft instance is not initialized.');
|
|
1369
1398
|
}
|
|
1370
|
-
if (state.core.config.cortexURL) {
|
|
1399
|
+
if (state.core.config.cortexURL && !options?.skipSummary) {
|
|
1371
1400
|
state.summaryClient?.streamSummaryData();
|
|
1372
1401
|
}
|
|
1402
|
+
// Check if this is an initialQuery case (string requestProperties with empty searchTerm)
|
|
1403
|
+
const isInitialQuery = typeof state.cachedSearchClientRequestProperties === 'string' &&
|
|
1404
|
+
state.searchTerm.trim() === '';
|
|
1405
|
+
// Check if there are any active filters or pagination changes
|
|
1406
|
+
const hasActiveFilters = Object.keys(state.facetPathsForIndexFields).length > 0 ||
|
|
1407
|
+
Object.keys(state.rangeValueForIndexFields).length > 0;
|
|
1408
|
+
const hasNonDefaultPagination = state.searchResultsPage !== 1;
|
|
1409
|
+
const hasNonDefaultSearchMode = state.searchMode !== 'fuzzy';
|
|
1373
1410
|
if (!state.searchTerm.trim()) {
|
|
1411
|
+
// If it's initialQuery and there are filters, pagination, or mode changes, perform a search
|
|
1412
|
+
if (isInitialQuery &&
|
|
1413
|
+
(hasActiveFilters ||
|
|
1414
|
+
hasNonDefaultPagination ||
|
|
1415
|
+
hasNonDefaultSearchMode)) {
|
|
1416
|
+
// Parse the initialQuery
|
|
1417
|
+
const initialQueryObj = JSON.parse(state.cachedSearchClientRequestProperties);
|
|
1418
|
+
set({ isSearchInProgress: true });
|
|
1419
|
+
// Build the modified query array starting with the base query
|
|
1420
|
+
const baseQuery = Array.isArray(initialQueryObj.query)
|
|
1421
|
+
? initialQueryObj.query.filter((q) => !q.occur)
|
|
1422
|
+
: [initialQueryObj.query];
|
|
1423
|
+
const queries = [...baseQuery];
|
|
1424
|
+
// Add facet filters
|
|
1425
|
+
if (state.facetPathsForIndexFields) {
|
|
1426
|
+
Object.keys(state.facetPathsForIndexFields).forEach((fieldName) => {
|
|
1427
|
+
const item = state.facetPathsForIndexFields?.[fieldName];
|
|
1428
|
+
if (item) {
|
|
1429
|
+
queries.push({
|
|
1430
|
+
occur: 'must',
|
|
1431
|
+
exact: {
|
|
1432
|
+
ctx: item.value,
|
|
1433
|
+
},
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
// Add range filters
|
|
1439
|
+
if (state.rangeValueForIndexFields) {
|
|
1440
|
+
Object.keys(state.rangeValueForIndexFields).forEach((fieldName) => {
|
|
1441
|
+
const item = state.rangeValueForIndexFields?.[fieldName];
|
|
1442
|
+
if (item) {
|
|
1443
|
+
queries.push({
|
|
1444
|
+
occur: 'must',
|
|
1445
|
+
exact: {
|
|
1446
|
+
ctx: item.value,
|
|
1447
|
+
},
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
// Build the modified request with filters and pagination
|
|
1453
|
+
const modifiedRequest = {
|
|
1454
|
+
...initialQueryObj,
|
|
1455
|
+
query: queries,
|
|
1456
|
+
offset: state.searchResultsPerPage
|
|
1457
|
+
? state.searchResultsPerPage * (state.searchResultsPage - 1)
|
|
1458
|
+
: 0,
|
|
1459
|
+
limit: state.searchResultsPerPage,
|
|
1460
|
+
};
|
|
1461
|
+
state.core.getResponseItems({
|
|
1462
|
+
requestProperties: JSON.stringify(modifiedRequest),
|
|
1463
|
+
shouldCacheResultsForEmptyState: false,
|
|
1464
|
+
});
|
|
1465
|
+
return;
|
|
1466
|
+
}
|
|
1467
|
+
// Otherwise, restore cached results
|
|
1374
1468
|
state.core?.searchClient?.abortRequests();
|
|
1375
1469
|
set({
|
|
1376
1470
|
searchClientResponseItems: [
|
|
1377
1471
|
...state.cachedSearchClientResponseItems,
|
|
1378
1472
|
],
|
|
1379
1473
|
adClientResponseItems: [...state.cachedAdClientResponseItems],
|
|
1380
|
-
|
|
1474
|
+
searchResponseFacetPrime: state.cachedSearchResponseFacetPrime,
|
|
1475
|
+
supplementalFacetPrime: state.cachedSupplementalFacetPrime,
|
|
1476
|
+
searchResponseTimeTaken: state.cachedSearchResponseTimeTaken,
|
|
1477
|
+
searchResultsCount: state.cachedSearchResultsCount || 0,
|
|
1478
|
+
searchClientRequestProperties: state.cachedSearchClientRequestProperties,
|
|
1381
1479
|
searchResultsPage: 1,
|
|
1382
1480
|
searchTerm: '',
|
|
1383
1481
|
});
|
|
@@ -1425,17 +1523,22 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
1425
1523
|
...state.cachedSearchClientResponseItems,
|
|
1426
1524
|
],
|
|
1427
1525
|
adClientResponseItems: [...state.cachedAdClientResponseItems],
|
|
1526
|
+
searchResponseFacetPrime: state.cachedSearchResponseFacetPrime,
|
|
1527
|
+
supplementalFacetPrime: state.cachedSupplementalFacetPrime,
|
|
1528
|
+
searchResponseTimeTaken: state.cachedSearchResponseTimeTaken,
|
|
1529
|
+
searchResultsCount: state.cachedSearchResultsCount || 0,
|
|
1530
|
+
searchClientRequestProperties: state.cachedSearchClientRequestProperties,
|
|
1428
1531
|
}),
|
|
1429
1532
|
});
|
|
1430
1533
|
},
|
|
1431
1534
|
setSearchResultsCount: (count) => set({ searchResultsCount: count }),
|
|
1432
1535
|
setSearchResultsPage: async (page) => {
|
|
1433
1536
|
set({ searchResultsPage: page });
|
|
1434
|
-
await functions.search();
|
|
1537
|
+
await functions.search({ skipSummary: true });
|
|
1435
1538
|
},
|
|
1436
1539
|
setSearchResultsPerPage: async (perPage) => {
|
|
1437
1540
|
set({ searchResultsPerPage: perPage });
|
|
1438
|
-
await functions.search();
|
|
1541
|
+
await functions.search({ skipSummary: true });
|
|
1439
1542
|
},
|
|
1440
1543
|
setHotKeyAndHotKeyModifier: (hotkey, hotkeyModifier) => {
|
|
1441
1544
|
const { hotkey: initialHotkey, hotkeyModifier: initialHotkeyModifier } = initialSearchcraftStateValues;
|
|
@@ -1483,8 +1586,11 @@ class SearchcraftCore {
|
|
|
1483
1586
|
if (!config.readKey) {
|
|
1484
1587
|
throw new Error('SDK Configuration Error: readKey not specified.');
|
|
1485
1588
|
}
|
|
1486
|
-
if (!config.indexName) {
|
|
1487
|
-
throw new Error('SDK Configuration Error: indexName
|
|
1589
|
+
if (!config.indexName && !config.federationName) {
|
|
1590
|
+
throw new Error('SDK Configuration Error: Either indexName or federationName must be specified.');
|
|
1591
|
+
}
|
|
1592
|
+
if (config.indexName && config.federationName) {
|
|
1593
|
+
throw new Error('SDK Configuration Error: Cannot specify both indexName and federationName. Please specify only one.');
|
|
1488
1594
|
}
|
|
1489
1595
|
this.config = {
|
|
1490
1596
|
...config,
|
|
@@ -1636,6 +1742,30 @@ class SearchcraftCore {
|
|
|
1636
1742
|
}
|
|
1637
1743
|
}
|
|
1638
1744
|
}
|
|
1745
|
+
else if (typeof props.requestProperties === 'string') {
|
|
1746
|
+
// Handle supplemental search for initialQuery with filters
|
|
1747
|
+
const requestObj = JSON.parse(props.requestProperties);
|
|
1748
|
+
// Check if there are any filter queries (queries beyond the base query)
|
|
1749
|
+
const queryArray = Array.isArray(requestObj.query)
|
|
1750
|
+
? requestObj.query
|
|
1751
|
+
: [requestObj.query];
|
|
1752
|
+
if (queryArray.length > 1) {
|
|
1753
|
+
// Remove filter queries to get base query for supplemental search
|
|
1754
|
+
const baseQuery = queryArray.filter((q) => q.occur !== 'must');
|
|
1755
|
+
const supplementalRequest = {
|
|
1756
|
+
...requestObj,
|
|
1757
|
+
query: baseQuery.length > 0 ? baseQuery : queryArray.slice(0, 1),
|
|
1758
|
+
};
|
|
1759
|
+
try {
|
|
1760
|
+
supplementalResponse =
|
|
1761
|
+
await this?.searchClient?.getSearchResponseItems(JSON.stringify(supplementalRequest), true);
|
|
1762
|
+
}
|
|
1763
|
+
catch (error) {
|
|
1764
|
+
Logger.info(`Search request error: ${error}`);
|
|
1765
|
+
return;
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1639
1769
|
this.store.setState({
|
|
1640
1770
|
isSearchInProgress: false,
|
|
1641
1771
|
searchClientResponseItems: items,
|
|
@@ -1646,6 +1776,11 @@ class SearchcraftCore {
|
|
|
1646
1776
|
searchClientRequestProperties: props.requestProperties,
|
|
1647
1777
|
...(props.shouldCacheResultsForEmptyState && {
|
|
1648
1778
|
cachedSearchClientResponseItems: items,
|
|
1779
|
+
cachedSearchResponseFacetPrime: response.data.facets,
|
|
1780
|
+
cachedSupplementalFacetPrime: supplementalResponse?.data.facets,
|
|
1781
|
+
cachedSearchResponseTimeTaken: response.data.time_taken,
|
|
1782
|
+
cachedSearchResultsCount: response.data.count,
|
|
1783
|
+
cachedSearchClientRequestProperties: props.requestProperties,
|
|
1649
1784
|
}),
|
|
1650
1785
|
});
|
|
1651
1786
|
})();
|
|
@@ -1675,75 +1810,7 @@ class SearchcraftCore {
|
|
|
1675
1810
|
}
|
|
1676
1811
|
|
|
1677
1812
|
const name = "@searchcraft/javascript-sdk";
|
|
1678
|
-
const version = "0.
|
|
1679
|
-
const description = "Searchcraft Javascript SDK";
|
|
1680
|
-
const author = "Searchcraft Inc.";
|
|
1681
|
-
const license = "Apache-2.0";
|
|
1682
|
-
const module = "dist/components/index.js";
|
|
1683
|
-
const types = "dist/components/index.d.ts";
|
|
1684
|
-
const exports = {
|
|
1685
|
-
".": {
|
|
1686
|
-
"import": "./dist/components/index.js",
|
|
1687
|
-
types: "./dist/components/index.d.ts"
|
|
1688
|
-
},
|
|
1689
|
-
"./dist/components/*": {
|
|
1690
|
-
"import": "./dist/components/*",
|
|
1691
|
-
types: "./dist/components/*"
|
|
1692
|
-
},
|
|
1693
|
-
"./hydrate": {
|
|
1694
|
-
require: "./dist/hydrate/index.js",
|
|
1695
|
-
"import": "./dist/hydrate/index.mjs",
|
|
1696
|
-
types: "./dist/hydrate/index.d.ts"
|
|
1697
|
-
},
|
|
1698
|
-
"./themes/*.css": "./dist/themes/*.css"
|
|
1699
|
-
};
|
|
1700
|
-
const repository = {
|
|
1701
|
-
type: "git",
|
|
1702
|
-
url: "https://bitbucket.org/madebychalk/searchcraft-javascript-sdks/"
|
|
1703
|
-
};
|
|
1704
|
-
const files = [
|
|
1705
|
-
"dist/"
|
|
1706
|
-
];
|
|
1707
|
-
const scripts = {
|
|
1708
|
-
build: "stencil build",
|
|
1709
|
-
docs: "typedoc --options typedoc.json",
|
|
1710
|
-
dev: "stencil build --dev --watch",
|
|
1711
|
-
test: "stencil test --spec --e2e",
|
|
1712
|
-
"test.watch": "stencil test --spec --e2e --watchAll",
|
|
1713
|
-
generate: "stencil generate"
|
|
1714
|
-
};
|
|
1715
|
-
const dependencies = {
|
|
1716
|
-
classnames: "^2.3.2",
|
|
1717
|
-
dompurify: "^3.2.4",
|
|
1718
|
-
marked: "^15.0.12",
|
|
1719
|
-
nanoid: "^5.0.9"
|
|
1720
|
-
};
|
|
1721
|
-
const devDependencies = {
|
|
1722
|
-
"@stencil/core": "^4.7.0",
|
|
1723
|
-
"@stencil/react-output-target": "^0.8.2",
|
|
1724
|
-
"@stencil/sass": "^3.0.12",
|
|
1725
|
-
"@stencil/vue-output-target": "^0.9.2",
|
|
1726
|
-
"@thumbmarkjs/thumbmarkjs": "^0.16.1",
|
|
1727
|
-
"@types/node": "^16.18.11",
|
|
1728
|
-
nanoid: "^5.0.9",
|
|
1729
|
-
zustand: "^5.0.1"
|
|
1730
|
-
};
|
|
1731
|
-
const packageJson = {
|
|
1732
|
-
name: name,
|
|
1733
|
-
"private": false,
|
|
1734
|
-
version: version,
|
|
1735
|
-
description: description,
|
|
1736
|
-
author: author,
|
|
1737
|
-
license: license,
|
|
1738
|
-
module: module,
|
|
1739
|
-
types: types,
|
|
1740
|
-
exports: exports,
|
|
1741
|
-
repository: repository,
|
|
1742
|
-
files: files,
|
|
1743
|
-
scripts: scripts,
|
|
1744
|
-
dependencies: dependencies,
|
|
1745
|
-
devDependencies: devDependencies
|
|
1746
|
-
};
|
|
1813
|
+
const version = "0.12.1";
|
|
1747
1814
|
|
|
1748
1815
|
/**
|
|
1749
1816
|
* @fileoverview entry point for your component library
|
|
@@ -1760,8 +1827,8 @@ const packageJson = {
|
|
|
1760
1827
|
class Searchcraft extends SearchcraftCore {
|
|
1761
1828
|
constructor(config, searchcraftId = undefined) {
|
|
1762
1829
|
super(config, {
|
|
1763
|
-
sdkName:
|
|
1764
|
-
sdkVersion:
|
|
1830
|
+
sdkName: name,
|
|
1831
|
+
sdkVersion: version,
|
|
1765
1832
|
}, searchcraftId);
|
|
1766
1833
|
}
|
|
1767
1834
|
}
|