typesense-instantsearch-adapter 2.5.0-1 → 2.5.0-10
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/typesense-instantsearch-adapter.js +59 -16
- package/dist/typesense-instantsearch-adapter.js.map +1 -1
- package/dist/typesense-instantsearch-adapter.min.js +1 -1
- package/dist/typesense-instantsearch-adapter.min.js.map +1 -1
- package/lib/Configuration.js +13 -9
- package/lib/Configuration.js.map +1 -1
- package/lib/SearchRequestAdapter.js +9 -1
- package/lib/SearchRequestAdapter.js.map +1 -1
- package/lib/SearchResponseAdapter.js +37 -6
- package/lib/SearchResponseAdapter.js.map +1 -1
- package/package.json +2 -2
- package/src/Configuration.js +11 -4
- package/src/SearchRequestAdapter.js +3 -1
- package/src/SearchResponseAdapter.js +35 -6
|
@@ -2211,6 +2211,8 @@ var Configuration = /*#__PURE__*/function () {
|
|
|
2211
2211
|
_this$additionalSearc2,
|
|
2212
2212
|
_ref3,
|
|
2213
2213
|
_this$additionalSearc3,
|
|
2214
|
+
_ref4,
|
|
2215
|
+
_this$additionalSearc4,
|
|
2214
2216
|
_options$geoLocationF,
|
|
2215
2217
|
_options$collectionSp,
|
|
2216
2218
|
_this = this;
|
|
@@ -2230,17 +2232,19 @@ var Configuration = /*#__PURE__*/function () {
|
|
|
2230
2232
|
this.server.cacheSearchResultsForSeconds = (_this$server$cacheSea = this.server.cacheSearchResultsForSeconds) !== null && _this$server$cacheSea !== void 0 ? _this$server$cacheSea : 2 * 60;
|
|
2231
2233
|
this.additionalSearchParameters = (_options$additionalSe = options.additionalSearchParameters) !== null && _options$additionalSe !== void 0 ? _options$additionalSe : {};
|
|
2232
2234
|
this.additionalSearchParameters.query_by = (_ref = (_this$additionalSearc = this.additionalSearchParameters.queryBy) !== null && _this$additionalSearc !== void 0 ? _this$additionalSearc : this.additionalSearchParameters.query_by) !== null && _ref !== void 0 ? _ref : "";
|
|
2233
|
-
this.additionalSearchParameters.
|
|
2234
|
-
this.additionalSearchParameters.
|
|
2235
|
+
this.additionalSearchParameters.preset = (_ref2 = (_this$additionalSearc2 = this.additionalSearchParameters.preset) !== null && _this$additionalSearc2 !== void 0 ? _this$additionalSearc2 : this.additionalSearchParameters.preset) !== null && _ref2 !== void 0 ? _ref2 : "";
|
|
2236
|
+
this.additionalSearchParameters.sort_by = (_ref3 = (_this$additionalSearc3 = this.additionalSearchParameters.sortBy) !== null && _this$additionalSearc3 !== void 0 ? _this$additionalSearc3 : this.additionalSearchParameters.sort_by) !== null && _ref3 !== void 0 ? _ref3 : "";
|
|
2237
|
+
this.additionalSearchParameters.highlight_full_fields = (_ref4 = (_this$additionalSearc4 = this.additionalSearchParameters.highlightFullFields) !== null && _this$additionalSearc4 !== void 0 ? _this$additionalSearc4 : this.additionalSearchParameters.highlight_full_fields) !== null && _ref4 !== void 0 ? _ref4 : this.additionalSearchParameters.query_by;
|
|
2235
2238
|
this.geoLocationField = (_options$geoLocationF = options.geoLocationField) !== null && _options$geoLocationF !== void 0 ? _options$geoLocationF : "_geoloc";
|
|
2236
2239
|
this.collectionSpecificSearchParameters = (_options$collectionSp = options.collectionSpecificSearchParameters) !== null && _options$collectionSp !== void 0 ? _options$collectionSp : {};
|
|
2237
2240
|
Object.keys(this.collectionSpecificSearchParameters).forEach(function (collection) {
|
|
2238
|
-
var _params$queryBy, _params$
|
|
2241
|
+
var _params$queryBy, _params$preset, _params$sortBy, _ref5, _ref6, _params$highlightFull;
|
|
2239
2242
|
|
|
2240
2243
|
var params = _this.collectionSpecificSearchParameters[collection];
|
|
2241
2244
|
params.query_by = (_params$queryBy = params.queryBy) !== null && _params$queryBy !== void 0 ? _params$queryBy : params.query_by;
|
|
2245
|
+
params.preset = (_params$preset = params.preset) !== null && _params$preset !== void 0 ? _params$preset : params.preset;
|
|
2242
2246
|
params.sort_by = (_params$sortBy = params.sortBy) !== null && _params$sortBy !== void 0 ? _params$sortBy : params.sort_by;
|
|
2243
|
-
params.highlight_full_fields = (
|
|
2247
|
+
params.highlight_full_fields = (_ref5 = (_ref6 = (_params$highlightFull = params.highlightFullFields) !== null && _params$highlightFull !== void 0 ? _params$highlightFull : params.highlight_full_fields) !== null && _ref6 !== void 0 ? _ref6 : _this.additionalSearchParameters.highlight_full_fields) !== null && _ref5 !== void 0 ? _ref5 : params.query_by; // Remove undefined values
|
|
2244
2248
|
|
|
2245
2249
|
Object.keys(params).forEach(function (key) {
|
|
2246
2250
|
return params[key] === undefined ? delete params[key] : {};
|
|
@@ -2258,16 +2262,16 @@ var Configuration = /*#__PURE__*/function () {
|
|
|
2258
2262
|
console.warn("[typesense-instantsearch-adapter] Please use snake_cased versions of parameters in additionalSearchParameters instead of camelCased parameters. For example: Use query_by instead of queryBy. camelCased parameters will be deprecated in a future version." + " We're making this change so that parameter names are identical to the ones sent to Typesense (which are all snake_cased), and to also keep the types for these parameters in sync with the types defined in typesense-js.");
|
|
2259
2263
|
}
|
|
2260
2264
|
/*
|
|
2261
|
-
* Either additionalSearchParameters.query_by needs to be set, or
|
|
2262
|
-
* All collectionSpecificSearchParameters need to have query_by
|
|
2265
|
+
* Either additionalSearchParameters.query_by or additionalSearchParameters.preset needs to be set, or
|
|
2266
|
+
* All collectionSpecificSearchParameters need to have query_by or preset
|
|
2263
2267
|
*
|
|
2264
2268
|
* */
|
|
2265
2269
|
|
|
2266
2270
|
|
|
2267
|
-
if (this.additionalSearchParameters.query_by.length === 0 && (Object.keys(this.collectionSpecificSearchParameters).length === 0 || Object.values(this.collectionSpecificSearchParameters).some(function (c) {
|
|
2268
|
-
return (c.query_by || "").length === 0;
|
|
2271
|
+
if (this.additionalSearchParameters.query_by.length === 0 && this.additionalSearchParameters.preset.length === 0 && (Object.keys(this.collectionSpecificSearchParameters).length === 0 || Object.values(this.collectionSpecificSearchParameters).some(function (c) {
|
|
2272
|
+
return (c.query_by || "").length === 0 && (c.preset || "").length === 0;
|
|
2269
2273
|
}))) {
|
|
2270
|
-
throw new Error("[typesense-instantsearch-adapter] Missing parameter:
|
|
2274
|
+
throw new Error("[typesense-instantsearch-adapter] Missing parameter: One of additionalSearchParameters.query_by or additionalSearchParameters.preset needs to be set, or all collectionSpecificSearchParameters need to have either .query_by or .preset set.");
|
|
2271
2275
|
}
|
|
2272
2276
|
}
|
|
2273
2277
|
}]);
|
|
@@ -2700,9 +2704,17 @@ var SearchRequestAdapter = /*#__PURE__*/function () {
|
|
|
2700
2704
|
typesenseSearchParams.per_page = 0;
|
|
2701
2705
|
} // console.log(params);
|
|
2702
2706
|
// console.log(typesenseSearchParams);
|
|
2707
|
+
// Filter out empty or null values, so we don't accidentally override values set in presets
|
|
2708
|
+
// eslint-disable-next-line no-unused-vars
|
|
2703
2709
|
|
|
2704
2710
|
|
|
2705
|
-
return typesenseSearchParams
|
|
2711
|
+
return Object.fromEntries(Object.entries(typesenseSearchParams).filter(function (_ref2) {
|
|
2712
|
+
var _ref3 = (0,_babel_runtime_helpers_slicedToArray__WEBPACK_IMPORTED_MODULE_1__["default"])(_ref2, 2),
|
|
2713
|
+
_ = _ref3[0],
|
|
2714
|
+
v = _ref3[1];
|
|
2715
|
+
|
|
2716
|
+
return v != null && v !== "";
|
|
2717
|
+
}));
|
|
2706
2718
|
}
|
|
2707
2719
|
}, {
|
|
2708
2720
|
key: "_camelToSnakeCase",
|
|
@@ -2854,9 +2866,10 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2854
2866
|
key: "_adaptHighlightResult",
|
|
2855
2867
|
value: function _adaptHighlightResult(typesenseHit, snippetOrValue) {
|
|
2856
2868
|
var result = {}; // If there is a highlight object available (as of v0.24.0),
|
|
2869
|
+
// And the highlight object uses the highlight format available in v0.24.0.rcn32 and above
|
|
2857
2870
|
// use that instead of the highlights array, since it supports highlights of nested fields
|
|
2858
2871
|
|
|
2859
|
-
if (typesenseHit.highlight != null) {
|
|
2872
|
+
if (typesenseHit.highlight != null && this.isHighlightPost0240RCN32Format(typesenseHit.highlight)) {
|
|
2860
2873
|
this.adaptHighlightObject(typesenseHit, result, snippetOrValue);
|
|
2861
2874
|
} else {
|
|
2862
2875
|
this.adaptHighlightsArray(typesenseHit, result, snippetOrValue);
|
|
@@ -2864,6 +2877,11 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2864
2877
|
|
|
2865
2878
|
return result;
|
|
2866
2879
|
}
|
|
2880
|
+
}, {
|
|
2881
|
+
key: "isHighlightPost0240RCN32Format",
|
|
2882
|
+
value: function isHighlightPost0240RCN32Format(highlight) {
|
|
2883
|
+
return highlight.full == null && highlight.snippet == null;
|
|
2884
|
+
}
|
|
2867
2885
|
}, {
|
|
2868
2886
|
key: "adaptHighlightsArray",
|
|
2869
2887
|
value: function adaptHighlightsArray(typesenseHit, result, snippetOrValue) {
|
|
@@ -2906,7 +2924,9 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2906
2924
|
matchedWords = v.matchedWords,
|
|
2907
2925
|
matchedIndices = v.matchedIndices;
|
|
2908
2926
|
|
|
2909
|
-
if (
|
|
2927
|
+
if (value == null) {
|
|
2928
|
+
result[attribute] = _this3._adaptHighlightNullValue();
|
|
2929
|
+
} else if (Array.isArray(value)) {
|
|
2910
2930
|
// Algolia lists all values of the key in highlights, even those that don't have any highlights
|
|
2911
2931
|
// So add all values of the array field, including highlights
|
|
2912
2932
|
result[attribute] = [];
|
|
@@ -2917,6 +2937,11 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2917
2937
|
matchLevel: matchLevel,
|
|
2918
2938
|
matchedWords: matchedWords[index]
|
|
2919
2939
|
});
|
|
2940
|
+
} else if ((0,_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__["default"])(unhighlightedValueFromArray) === "object") {
|
|
2941
|
+
// Handle arrays of objects
|
|
2942
|
+
// Side note: Typesense does not support highlights for nested objects in this `highlights` array,
|
|
2943
|
+
// so we pass in an empty object below
|
|
2944
|
+
result[attribute].push(_this3._adaptHighlightInObjectValue(unhighlightedValueFromArray, {}, snippetOrValue));
|
|
2920
2945
|
} else {
|
|
2921
2946
|
result[attribute].push({
|
|
2922
2947
|
value: "".concat(unhighlightedValueFromArray),
|
|
@@ -2925,6 +2950,11 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2925
2950
|
});
|
|
2926
2951
|
}
|
|
2927
2952
|
});
|
|
2953
|
+
} else if ((0,_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__["default"])(value) === "object") {
|
|
2954
|
+
// Handle nested objects
|
|
2955
|
+
// Side note: Typesense does not support highlights for nested objects in this `highlights` array,
|
|
2956
|
+
// so we pass in an empty object below
|
|
2957
|
+
result[attribute] = _this3._adaptHighlightInObjectValue(value, {}, snippetOrValue);
|
|
2928
2958
|
} else {
|
|
2929
2959
|
// Convert all values to strings
|
|
2930
2960
|
result[attribute].value = _this3._adaptHighlightTag("".concat(value), _this3.instantsearchRequest.params.highlightPreTag, _this3.instantsearchRequest.params.highlightPostTag);
|
|
@@ -2948,7 +2978,9 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2948
2978
|
|
|
2949
2979
|
var adaptedValue;
|
|
2950
2980
|
|
|
2951
|
-
if (
|
|
2981
|
+
if (value == null) {
|
|
2982
|
+
adaptedValue = _this4._adaptHighlightNullValue();
|
|
2983
|
+
} else if (Array.isArray(value)) {
|
|
2952
2984
|
var _highlightObjectValue;
|
|
2953
2985
|
|
|
2954
2986
|
adaptedValue = _this4._adaptHighlightInArrayValue(value, (_highlightObjectValue = highlightObjectValue === null || highlightObjectValue === void 0 ? void 0 : highlightObjectValue[attribute]) !== null && _highlightObjectValue !== void 0 ? _highlightObjectValue : [], snippetOrValue);
|
|
@@ -2971,7 +3003,9 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2971
3003
|
return arrayValue.map(function (value, index) {
|
|
2972
3004
|
var adaptedValue;
|
|
2973
3005
|
|
|
2974
|
-
if (
|
|
3006
|
+
if (value == null) {
|
|
3007
|
+
adaptedValue = _this5._adaptHighlightNullValue();
|
|
3008
|
+
} else if (Array.isArray(value)) {
|
|
2975
3009
|
var _highlightArrayValue$;
|
|
2976
3010
|
|
|
2977
3011
|
adaptedValue = _this5._adaptHighlightInArrayValue(value, (_highlightArrayValue$ = highlightArrayValue === null || highlightArrayValue === void 0 ? void 0 : highlightArrayValue[index]) !== null && _highlightArrayValue$ !== void 0 ? _highlightArrayValue$ : [], snippetOrValue);
|
|
@@ -2992,8 +3026,8 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2992
3026
|
if (highlightPrimitiveValue != null) {
|
|
2993
3027
|
return {
|
|
2994
3028
|
value: this._adaptHighlightTag("".concat(highlightPrimitiveValue[snippetOrValue]), this.instantsearchRequest.params.highlightPreTag, this.instantsearchRequest.params.highlightPostTag),
|
|
2995
|
-
matchLevel: "full",
|
|
2996
|
-
matchedWords: highlightPrimitiveValue.matched_tokens
|
|
3029
|
+
matchLevel: (highlightPrimitiveValue.matched_tokens || []).length > 0 ? "full" : "none",
|
|
3030
|
+
matchedWords: highlightPrimitiveValue.matched_tokens || []
|
|
2997
3031
|
};
|
|
2998
3032
|
} else {
|
|
2999
3033
|
return {
|
|
@@ -3004,6 +3038,15 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
3004
3038
|
};
|
|
3005
3039
|
}
|
|
3006
3040
|
}
|
|
3041
|
+
}, {
|
|
3042
|
+
key: "_adaptHighlightNullValue",
|
|
3043
|
+
value: function _adaptHighlightNullValue() {
|
|
3044
|
+
return {
|
|
3045
|
+
value: "",
|
|
3046
|
+
matchLevel: "none",
|
|
3047
|
+
matchedWords: []
|
|
3048
|
+
};
|
|
3049
|
+
}
|
|
3007
3050
|
}, {
|
|
3008
3051
|
key: "_adaptFacets",
|
|
3009
3052
|
value: function _adaptFacets(typesenseFacetCounts) {
|