@searchcraft/javascript-sdk 0.12.0 → 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/dist/components/index.d.ts +13 -0
- package/dist/components/index.js +136 -17
- package/dist/components/index.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 +2 -2
- 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 +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/hydrate/index.js +192 -100
- package/dist/hydrate/index.mjs +192 -100
- package/dist/types/classes/SearchcraftCore.d.ts +1 -1
- 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-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.d.ts +8 -0
- package/dist/types/store/SearchcraftStore.types.d.ts +6 -1
- package/package.json +4 -3
- package/dist/components/p-0c495408.js.map +0 -1
- package/dist/components/p-b7e99386.js.map +0 -1
|
@@ -683,6 +683,11 @@ export interface SearchcraftStateValues {
|
|
|
683
683
|
searchClientRequestProperties: SearchClientRequestProperties | string | undefined | null;
|
|
684
684
|
searchClientResponseItems: SearchClientResponseItem[];
|
|
685
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;
|
|
686
691
|
searchResponseTimeTaken: number | undefined;
|
|
687
692
|
searchResponseFacetPrime: FacetPrime | undefined | null;
|
|
688
693
|
supplementalFacetPrime: FacetPrime | undefined | null;
|
|
@@ -921,6 +926,10 @@ export namespace Components {
|
|
|
921
926
|
* The id of the Searchcraft instance that this component should use.
|
|
922
927
|
*/
|
|
923
928
|
"searchcraftId"?: string;
|
|
929
|
+
/**
|
|
930
|
+
* The value to display in the input field.
|
|
931
|
+
*/
|
|
932
|
+
"value"?: string;
|
|
924
933
|
}
|
|
925
934
|
/**
|
|
926
935
|
* This web component serves as the input label for the searchcraft-input-form component.
|
|
@@ -2184,6 +2193,10 @@ declare namespace LocalJSX {
|
|
|
2184
2193
|
* The id of the Searchcraft instance that this component should use.
|
|
2185
2194
|
*/
|
|
2186
2195
|
"searchcraftId"?: string;
|
|
2196
|
+
/**
|
|
2197
|
+
* The value to display in the input field.
|
|
2198
|
+
*/
|
|
2199
|
+
"value"?: string;
|
|
2187
2200
|
}
|
|
2188
2201
|
/**
|
|
2189
2202
|
* This web component serves as the input label for the searchcraft-input-form component.
|
package/dist/components/index.js
CHANGED
|
@@ -1303,6 +1303,11 @@ const initialSearchcraftStateValues = {
|
|
|
1303
1303
|
searchClientRequestProperties: undefined,
|
|
1304
1304
|
searchClientResponseItems: [],
|
|
1305
1305
|
cachedSearchClientResponseItems: [],
|
|
1306
|
+
cachedSearchResponseFacetPrime: undefined,
|
|
1307
|
+
cachedSupplementalFacetPrime: undefined,
|
|
1308
|
+
cachedSearchResponseTimeTaken: undefined,
|
|
1309
|
+
cachedSearchResultsCount: undefined,
|
|
1310
|
+
cachedSearchClientRequestProperties: undefined,
|
|
1306
1311
|
searchResponseTimeTaken: undefined,
|
|
1307
1312
|
searchResponseFacetPrime: undefined,
|
|
1308
1313
|
supplementalFacetPrime: undefined,
|
|
@@ -1335,27 +1340,38 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
1335
1340
|
}
|
|
1336
1341
|
const newStore = zustand.createStore((set, get) => {
|
|
1337
1342
|
const functions = {
|
|
1338
|
-
addFacetPathsForIndexField: (facetPaths) =>
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
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
|
+
},
|
|
1344
1352
|
addRangeValueForIndexField: (rangeValue) => set((state) => ({
|
|
1345
1353
|
rangeValueForIndexFields: {
|
|
1346
1354
|
...state.rangeValueForIndexFields,
|
|
1347
1355
|
[rangeValue.fieldName]: rangeValue,
|
|
1348
1356
|
},
|
|
1349
1357
|
})),
|
|
1350
|
-
removeFacetPathsForIndexField: (fieldName) =>
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
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
|
+
},
|
|
1359
1375
|
removeRangeValueForIndexField: (fieldName) => set((state) => {
|
|
1360
1376
|
const currentValues = state.rangeValueForIndexFields;
|
|
1361
1377
|
delete currentValues[fieldName];
|
|
@@ -1383,14 +1399,83 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
1383
1399
|
if (state.core.config.cortexURL && !options?.skipSummary) {
|
|
1384
1400
|
state.summaryClient?.streamSummaryData();
|
|
1385
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';
|
|
1386
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
|
|
1387
1468
|
state.core?.searchClient?.abortRequests();
|
|
1388
1469
|
set({
|
|
1389
1470
|
searchClientResponseItems: [
|
|
1390
1471
|
...state.cachedSearchClientResponseItems,
|
|
1391
1472
|
],
|
|
1392
1473
|
adClientResponseItems: [...state.cachedAdClientResponseItems],
|
|
1393
|
-
|
|
1474
|
+
searchResponseFacetPrime: state.cachedSearchResponseFacetPrime,
|
|
1475
|
+
supplementalFacetPrime: state.cachedSupplementalFacetPrime,
|
|
1476
|
+
searchResponseTimeTaken: state.cachedSearchResponseTimeTaken,
|
|
1477
|
+
searchResultsCount: state.cachedSearchResultsCount || 0,
|
|
1478
|
+
searchClientRequestProperties: state.cachedSearchClientRequestProperties,
|
|
1394
1479
|
searchResultsPage: 1,
|
|
1395
1480
|
searchTerm: '',
|
|
1396
1481
|
});
|
|
@@ -1438,6 +1523,11 @@ const createSearchcraftStore = (searchcraftId, initialState = {}) => {
|
|
|
1438
1523
|
...state.cachedSearchClientResponseItems,
|
|
1439
1524
|
],
|
|
1440
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,
|
|
1441
1531
|
}),
|
|
1442
1532
|
});
|
|
1443
1533
|
},
|
|
@@ -1652,6 +1742,30 @@ class SearchcraftCore {
|
|
|
1652
1742
|
}
|
|
1653
1743
|
}
|
|
1654
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
|
+
}
|
|
1655
1769
|
this.store.setState({
|
|
1656
1770
|
isSearchInProgress: false,
|
|
1657
1771
|
searchClientResponseItems: items,
|
|
@@ -1662,6 +1776,11 @@ class SearchcraftCore {
|
|
|
1662
1776
|
searchClientRequestProperties: props.requestProperties,
|
|
1663
1777
|
...(props.shouldCacheResultsForEmptyState && {
|
|
1664
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,
|
|
1665
1784
|
}),
|
|
1666
1785
|
});
|
|
1667
1786
|
})();
|
|
@@ -1691,7 +1810,7 @@ class SearchcraftCore {
|
|
|
1691
1810
|
}
|
|
1692
1811
|
|
|
1693
1812
|
const name = "@searchcraft/javascript-sdk";
|
|
1694
|
-
const version = "0.12.
|
|
1813
|
+
const version = "0.12.1";
|
|
1695
1814
|
|
|
1696
1815
|
/**
|
|
1697
1816
|
* @fileoverview entry point for your component library
|