typesense-instantsearch-adapter 2.5.0-6 → 2.5.0-8
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 +34 -14
- 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/index.d.ts +0 -1
- package/lib/Configuration.js +12 -10
- package/lib/Configuration.js.map +1 -1
- package/lib/SearchResponseAdapter.js +22 -4
- package/lib/SearchResponseAdapter.js.map +1 -1
- package/package.json +2 -2
- package/src/Configuration.js +10 -5
- package/src/SearchResponseAdapter.js +21 -4
|
@@ -2204,7 +2204,6 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2204
2204
|
var Configuration = /*#__PURE__*/function () {
|
|
2205
2205
|
function Configuration() {
|
|
2206
2206
|
var _this$server$cacheSea,
|
|
2207
|
-
_options$useHighlight,
|
|
2208
2207
|
_options$additionalSe,
|
|
2209
2208
|
_ref,
|
|
2210
2209
|
_this$additionalSearc,
|
|
@@ -2212,6 +2211,8 @@ var Configuration = /*#__PURE__*/function () {
|
|
|
2212
2211
|
_this$additionalSearc2,
|
|
2213
2212
|
_ref3,
|
|
2214
2213
|
_this$additionalSearc3,
|
|
2214
|
+
_ref4,
|
|
2215
|
+
_this$additionalSearc4,
|
|
2215
2216
|
_options$geoLocationF,
|
|
2216
2217
|
_options$collectionSp,
|
|
2217
2218
|
_this = this;
|
|
@@ -2229,20 +2230,21 @@ var Configuration = /*#__PURE__*/function () {
|
|
|
2229
2230
|
}]
|
|
2230
2231
|
};
|
|
2231
2232
|
this.server.cacheSearchResultsForSeconds = (_this$server$cacheSea = this.server.cacheSearchResultsForSeconds) !== null && _this$server$cacheSea !== void 0 ? _this$server$cacheSea : 2 * 60;
|
|
2232
|
-
this.useHighlightV2Structure = (_options$useHighlight = options.useHighlightV2Structure) !== null && _options$useHighlight !== void 0 ? _options$useHighlight : true;
|
|
2233
2233
|
this.additionalSearchParameters = (_options$additionalSe = options.additionalSearchParameters) !== null && _options$additionalSe !== void 0 ? _options$additionalSe : {};
|
|
2234
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 : "";
|
|
2235
|
-
this.additionalSearchParameters.
|
|
2236
|
-
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;
|
|
2237
2238
|
this.geoLocationField = (_options$geoLocationF = options.geoLocationField) !== null && _options$geoLocationF !== void 0 ? _options$geoLocationF : "_geoloc";
|
|
2238
2239
|
this.collectionSpecificSearchParameters = (_options$collectionSp = options.collectionSpecificSearchParameters) !== null && _options$collectionSp !== void 0 ? _options$collectionSp : {};
|
|
2239
2240
|
Object.keys(this.collectionSpecificSearchParameters).forEach(function (collection) {
|
|
2240
|
-
var _params$queryBy, _params$
|
|
2241
|
+
var _params$queryBy, _params$preset, _params$sortBy, _ref5, _ref6, _params$highlightFull;
|
|
2241
2242
|
|
|
2242
2243
|
var params = _this.collectionSpecificSearchParameters[collection];
|
|
2243
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;
|
|
2244
2246
|
params.sort_by = (_params$sortBy = params.sortBy) !== null && _params$sortBy !== void 0 ? _params$sortBy : params.sort_by;
|
|
2245
|
-
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
|
|
2246
2248
|
|
|
2247
2249
|
Object.keys(params).forEach(function (key) {
|
|
2248
2250
|
return params[key] === undefined ? delete params[key] : {};
|
|
@@ -2260,14 +2262,14 @@ var Configuration = /*#__PURE__*/function () {
|
|
|
2260
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.");
|
|
2261
2263
|
}
|
|
2262
2264
|
/*
|
|
2263
|
-
* Either additionalSearchParameters.query_by needs to be set, or
|
|
2264
|
-
* 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
|
|
2265
2267
|
*
|
|
2266
2268
|
* */
|
|
2267
2269
|
|
|
2268
2270
|
|
|
2269
|
-
if (this.additionalSearchParameters.query_by.length === 0 && (Object.keys(this.collectionSpecificSearchParameters).length === 0 || Object.values(this.collectionSpecificSearchParameters).some(function (c) {
|
|
2270
|
-
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;
|
|
2271
2273
|
}))) {
|
|
2272
2274
|
throw new Error("[typesense-instantsearch-adapter] Missing parameter: Either additionalSearchParameters.query_by needs to be set, or all collectionSpecificSearchParameters need to have .query_by set");
|
|
2273
2275
|
}
|
|
@@ -2856,9 +2858,10 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2856
2858
|
key: "_adaptHighlightResult",
|
|
2857
2859
|
value: function _adaptHighlightResult(typesenseHit, snippetOrValue) {
|
|
2858
2860
|
var result = {}; // If there is a highlight object available (as of v0.24.0),
|
|
2861
|
+
// And the highlight object uses the highlight format available in v0.24.0.rcn32 and above
|
|
2859
2862
|
// use that instead of the highlights array, since it supports highlights of nested fields
|
|
2860
2863
|
|
|
2861
|
-
if (
|
|
2864
|
+
if (typesenseHit.highlight != null && this.isHighlightPost0240RCN32Format(typesenseHit.highlight)) {
|
|
2862
2865
|
this.adaptHighlightObject(typesenseHit, result, snippetOrValue);
|
|
2863
2866
|
} else {
|
|
2864
2867
|
this.adaptHighlightsArray(typesenseHit, result, snippetOrValue);
|
|
@@ -2866,6 +2869,11 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2866
2869
|
|
|
2867
2870
|
return result;
|
|
2868
2871
|
}
|
|
2872
|
+
}, {
|
|
2873
|
+
key: "isHighlightPost0240RCN32Format",
|
|
2874
|
+
value: function isHighlightPost0240RCN32Format(highlight) {
|
|
2875
|
+
return highlight.full == null && highlight.snippet == null;
|
|
2876
|
+
}
|
|
2869
2877
|
}, {
|
|
2870
2878
|
key: "adaptHighlightsArray",
|
|
2871
2879
|
value: function adaptHighlightsArray(typesenseHit, result, snippetOrValue) {
|
|
@@ -2908,7 +2916,9 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2908
2916
|
matchedWords = v.matchedWords,
|
|
2909
2917
|
matchedIndices = v.matchedIndices;
|
|
2910
2918
|
|
|
2911
|
-
if (
|
|
2919
|
+
if (value == null) {
|
|
2920
|
+
result[attribute] = _this3._adaptHighlightNullValue();
|
|
2921
|
+
} else if (Array.isArray(value)) {
|
|
2912
2922
|
// Algolia lists all values of the key in highlights, even those that don't have any highlights
|
|
2913
2923
|
// So add all values of the array field, including highlights
|
|
2914
2924
|
result[attribute] = [];
|
|
@@ -2919,6 +2929,11 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2919
2929
|
matchLevel: matchLevel,
|
|
2920
2930
|
matchedWords: matchedWords[index]
|
|
2921
2931
|
});
|
|
2932
|
+
} else if ((0,_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__["default"])(unhighlightedValueFromArray) === "object") {
|
|
2933
|
+
// Handle arrays of objects
|
|
2934
|
+
// Side note: Typesense does not support highlights for nested objects in this `highlights` array,
|
|
2935
|
+
// so we pass in an empty object below
|
|
2936
|
+
result[attribute].push(_this3._adaptHighlightInObjectValue(unhighlightedValueFromArray, {}, snippetOrValue));
|
|
2922
2937
|
} else {
|
|
2923
2938
|
result[attribute].push({
|
|
2924
2939
|
value: "".concat(unhighlightedValueFromArray),
|
|
@@ -2927,6 +2942,11 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2927
2942
|
});
|
|
2928
2943
|
}
|
|
2929
2944
|
});
|
|
2945
|
+
} else if ((0,_babel_runtime_helpers_typeof__WEBPACK_IMPORTED_MODULE_0__["default"])(value) === "object") {
|
|
2946
|
+
// Handle nested objects
|
|
2947
|
+
// Side note: Typesense does not support highlights for nested objects in this `highlights` array,
|
|
2948
|
+
// so we pass in an empty object below
|
|
2949
|
+
result[attribute] = _this3._adaptHighlightInObjectValue(value, {}, snippetOrValue);
|
|
2930
2950
|
} else {
|
|
2931
2951
|
// Convert all values to strings
|
|
2932
2952
|
result[attribute].value = _this3._adaptHighlightTag("".concat(value), _this3.instantsearchRequest.params.highlightPreTag, _this3.instantsearchRequest.params.highlightPostTag);
|
|
@@ -2998,8 +3018,8 @@ var SearchResponseAdapter = /*#__PURE__*/function () {
|
|
|
2998
3018
|
if (highlightPrimitiveValue != null) {
|
|
2999
3019
|
return {
|
|
3000
3020
|
value: this._adaptHighlightTag("".concat(highlightPrimitiveValue[snippetOrValue]), this.instantsearchRequest.params.highlightPreTag, this.instantsearchRequest.params.highlightPostTag),
|
|
3001
|
-
matchLevel: "full",
|
|
3002
|
-
matchedWords: highlightPrimitiveValue.matched_tokens
|
|
3021
|
+
matchLevel: (highlightPrimitiveValue.matched_tokens || []).length > 0 ? "full" : "none",
|
|
3022
|
+
matchedWords: highlightPrimitiveValue.matched_tokens || []
|
|
3003
3023
|
};
|
|
3004
3024
|
} else {
|
|
3005
3025
|
return {
|