@searchcraft/javascript-sdk 0.12.0 → 0.12.2
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 +1 -1
- package/dist/components/index.d.ts +22 -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-e8d97093.js} +110 -37
- package/dist/components/p-e8d97093.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 +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 +229 -105
- package/dist/hydrate/index.mjs +229 -105
- package/dist/types/classes/SearchcraftCore.d.ts +1 -1
- package/dist/types/components/searchcraft-facet-list/searchcraft-facet-list.d.ts +5 -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 +16 -0
- package/dist/types/store/SearchcraftStore.types.d.ts +6 -1
- package/dist/types/types/sdk-types/searchcraft-filter-panel.types.d.ts +1 -0
- package/dist/types/utils/facets.d.ts +5 -1
- package/package.json +4 -3
- package/dist/components/p-0c495408.js.map +0 -1
- package/dist/components/p-b7e99386.js.map +0 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ Add the web components to your html. They should be placed with the rest of your
|
|
|
27
27
|
...
|
|
28
28
|
<searchcraft-filter-panel></searchcraft-filter-panel>
|
|
29
29
|
...
|
|
30
|
-
<searchcraft-results-info
|
|
30
|
+
<searchcraft-results-info></searchcraft-results-info>
|
|
31
31
|
...
|
|
32
32
|
<searchcraft-search-results></searchcraft-search-results>
|
|
33
33
|
...
|
|
@@ -183,6 +183,7 @@ export interface FacetsFilterItem extends FilterItem {
|
|
|
183
183
|
type: "facets";
|
|
184
184
|
options: {
|
|
185
185
|
showSublevel: boolean;
|
|
186
|
+
exclude?: string[];
|
|
186
187
|
};
|
|
187
188
|
}
|
|
188
189
|
export interface NumericFilterItem extends FilterItem {
|
|
@@ -683,6 +684,11 @@ export interface SearchcraftStateValues {
|
|
|
683
684
|
searchClientRequestProperties: SearchClientRequestProperties | string | undefined | null;
|
|
684
685
|
searchClientResponseItems: SearchClientResponseItem[];
|
|
685
686
|
cachedSearchClientResponseItems: SearchClientResponseItem[];
|
|
687
|
+
cachedSearchResponseFacetPrime: FacetPrime | undefined | null;
|
|
688
|
+
cachedSupplementalFacetPrime: FacetPrime | undefined | null;
|
|
689
|
+
cachedSearchResponseTimeTaken: number | undefined;
|
|
690
|
+
cachedSearchResultsCount: number | undefined;
|
|
691
|
+
cachedSearchClientRequestProperties: SearchClientRequestProperties | string | undefined | null;
|
|
686
692
|
searchResponseTimeTaken: number | undefined;
|
|
687
693
|
searchResponseFacetPrime: FacetPrime | undefined | null;
|
|
688
694
|
supplementalFacetPrime: FacetPrime | undefined | null;
|
|
@@ -828,6 +834,10 @@ export namespace Components {
|
|
|
828
834
|
* ```
|
|
829
835
|
*/
|
|
830
836
|
interface SearchcraftFacetList {
|
|
837
|
+
/**
|
|
838
|
+
* Array of facet values to exclude from rendering.
|
|
839
|
+
*/
|
|
840
|
+
"exclude"?: string[];
|
|
831
841
|
/**
|
|
832
842
|
* The name of the field where facets are applied.
|
|
833
843
|
*/
|
|
@@ -921,6 +931,10 @@ export namespace Components {
|
|
|
921
931
|
* The id of the Searchcraft instance that this component should use.
|
|
922
932
|
*/
|
|
923
933
|
"searchcraftId"?: string;
|
|
934
|
+
/**
|
|
935
|
+
* The value to display in the input field.
|
|
936
|
+
*/
|
|
937
|
+
"value"?: string;
|
|
924
938
|
}
|
|
925
939
|
/**
|
|
926
940
|
* This web component serves as the input label for the searchcraft-input-form component.
|
|
@@ -2073,6 +2087,10 @@ declare namespace LocalJSX {
|
|
|
2073
2087
|
* ```
|
|
2074
2088
|
*/
|
|
2075
2089
|
interface SearchcraftFacetList {
|
|
2090
|
+
/**
|
|
2091
|
+
* Array of facet values to exclude from rendering.
|
|
2092
|
+
*/
|
|
2093
|
+
"exclude"?: string[];
|
|
2076
2094
|
/**
|
|
2077
2095
|
* The name of the field where facets are applied.
|
|
2078
2096
|
*/
|
|
@@ -2184,6 +2202,10 @@ declare namespace LocalJSX {
|
|
|
2184
2202
|
* The id of the Searchcraft instance that this component should use.
|
|
2185
2203
|
*/
|
|
2186
2204
|
"searchcraftId"?: string;
|
|
2205
|
+
/**
|
|
2206
|
+
* The value to display in the input field.
|
|
2207
|
+
*/
|
|
2208
|
+
"value"?: string;
|
|
2187
2209
|
}
|
|
2188
2210
|
/**
|
|
2189
2211
|
* 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.2";
|
|
1695
1814
|
|
|
1696
1815
|
/**
|
|
1697
1816
|
* @fileoverview entry point for your component library
|