@usereactify/search 5.59.0-beta.2 → 5.59.0-beta.4
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/CHANGELOG.md +14 -0
- package/dist/package.json +5 -4
- package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.d.ts +2 -2
- package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js +32 -66
- package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js.map +1 -1
- package/dist/src/components/Result/Results.js +5 -8
- package/dist/src/components/Result/Results.js.map +1 -1
- package/dist/src/components/Sensor/SensorCollection.js +0 -1
- package/dist/src/components/Sensor/SensorCollection.js.map +1 -1
- package/dist/src/components/Sensor/SensorCuratedPageCollection.js +0 -1
- package/dist/src/components/Sensor/SensorCuratedPageCollection.js.map +1 -1
- package/dist/src/components/Sensor/index.d.ts +1 -1
- package/dist/src/components/Sensor/index.js +5 -2
- package/dist/src/components/Sensor/index.js.map +1 -1
- package/dist/src/components/Suggestions/Suggestions.js +2 -1
- package/dist/src/components/Suggestions/Suggestions.js.map +1 -1
- package/dist/src/utility/curation.js +36 -33
- package/dist/src/utility/curation.js.map +1 -1
- package/dist/src/utility/filters.js +6 -3
- package/dist/src/utility/filters.js.map +1 -1
- package/dist/src/utility/props.d.ts +2 -2
- package/dist/src/utility/props.js +16 -19
- package/dist/src/utility/props.js.map +1 -1
- package/dist/src/utility/sortOption.js +64 -129
- package/dist/src/utility/sortOption.js.map +1 -1
- package/package.json +6 -5
|
@@ -2,61 +2,49 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateSortQuery = exports.generateSortSort = exports.getSortOption = exports.getSortOptions = void 0;
|
|
4
4
|
const getSortOptions = (options) => {
|
|
5
|
+
const { provider } = options;
|
|
6
|
+
const visibilityMode = provider.mode === "curated-page" ? provider.variation : provider.mode;
|
|
5
7
|
return options.config.sort
|
|
6
8
|
.sort((a, b) => {
|
|
7
|
-
const aInt = typeof a.position === "string"
|
|
8
|
-
|
|
9
|
-
: a.position;
|
|
10
|
-
const bInt = typeof b.position === "string"
|
|
11
|
-
? parseInt(b.position, 10)
|
|
12
|
-
: b.position;
|
|
9
|
+
const aInt = typeof a.position === "string" ? parseInt(a.position, 10) : a.position;
|
|
10
|
+
const bInt = typeof b.position === "string" ? parseInt(b.position, 10) : b.position;
|
|
13
11
|
return aInt - bInt;
|
|
14
12
|
})
|
|
15
|
-
.filter(({ visibility }) => ["all",
|
|
13
|
+
.filter(({ visibility }) => ["all", visibilityMode].includes(visibility));
|
|
16
14
|
};
|
|
17
15
|
exports.getSortOptions = getSortOptions;
|
|
18
16
|
const getSortOption = (options) => {
|
|
19
17
|
var _a;
|
|
20
18
|
const sortOptions = (0, exports.getSortOptions)(options);
|
|
21
|
-
return (_a = sortOptions.find(({ handle }) => { var _a; return handle === options.sortOption || handle === ((_a = options.query) === null || _a === void 0 ? void 0 : _a.sort); })) !== null && _a !== void 0 ? _a : sortOptions[0];
|
|
19
|
+
return ((_a = sortOptions.find(({ handle }) => { var _a; return handle === options.sortOption || handle === ((_a = options.query) === null || _a === void 0 ? void 0 : _a.sort); })) !== null && _a !== void 0 ? _a : sortOptions[0]);
|
|
22
20
|
};
|
|
23
21
|
exports.getSortOption = getSortOption;
|
|
24
22
|
const generateSortSort = (options) => {
|
|
25
|
-
|
|
23
|
+
const { provider, curation, sortOption } = options;
|
|
26
24
|
// curation positions are only applied for the default `collections.position` or `_score` sort
|
|
27
25
|
// if the sort is something else, apply a normal sort which applies what the user has requested
|
|
28
|
-
if (
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return [{ [`${options.sortOption.field}_market_${options.provider.market}`]: options.sortOption.direction }];
|
|
26
|
+
if (provider.mode !== "instant-search") {
|
|
27
|
+
if (sortOption && !["_score", "collections.position"].includes(sortOption.field)) {
|
|
28
|
+
if (["price_min", "price_max"].includes(sortOption.field) && provider.market) {
|
|
29
|
+
return [{ [`${sortOption.field}_market_${provider.market}`]: sortOption.direction }];
|
|
33
30
|
}
|
|
34
|
-
return [{ [
|
|
31
|
+
return [{ [sortOption.field]: sortOption.direction }];
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
34
|
const sorts = [];
|
|
38
35
|
// collection curation pin sorting
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}];
|
|
36
|
+
if ((provider.mode === "collection" && provider.collectionHandle) ||
|
|
37
|
+
(provider.mode === "curated-page" && provider.variation === "collection")) {
|
|
38
|
+
if (curation === null || curation === void 0 ? void 0 : curation.collectionHandle) {
|
|
39
|
+
const queriesMust = [
|
|
40
|
+
{ term: { "curations.collectionHandle.keyword": curation.collectionHandle } },
|
|
41
|
+
];
|
|
46
42
|
const queriesMustNot = [];
|
|
47
|
-
if (
|
|
48
|
-
queriesMust.push({
|
|
49
|
-
term: {
|
|
50
|
-
"curations.markets.keyword": options.provider.market,
|
|
51
|
-
},
|
|
52
|
-
});
|
|
43
|
+
if (provider.market) {
|
|
44
|
+
queriesMust.push({ term: { "curations.markets.keyword": provider.market } });
|
|
53
45
|
}
|
|
54
46
|
else {
|
|
55
|
-
queriesMustNot.push({
|
|
56
|
-
exists: {
|
|
57
|
-
field: "curations.markets.keyword"
|
|
58
|
-
},
|
|
59
|
-
});
|
|
47
|
+
queriesMustNot.push({ exists: { field: "curations.markets.keyword" } });
|
|
60
48
|
}
|
|
61
49
|
sorts.push({
|
|
62
50
|
"curations.position": {
|
|
@@ -65,35 +53,27 @@ const generateSortSort = (options) => {
|
|
|
65
53
|
nested: {
|
|
66
54
|
path: "curations",
|
|
67
55
|
filter: {
|
|
68
|
-
bool: Object.assign({ must: queriesMust }, queriesMustNot.length > 0 ? { must_not: queriesMustNot } : {})
|
|
69
|
-
}
|
|
56
|
+
bool: Object.assign({ must: queriesMust }, (queriesMustNot.length > 0 ? { must_not: queriesMustNot } : {})),
|
|
57
|
+
},
|
|
70
58
|
},
|
|
71
59
|
},
|
|
72
60
|
});
|
|
73
61
|
}
|
|
74
62
|
}
|
|
75
|
-
// search
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
63
|
+
// search curation pin sorting
|
|
64
|
+
if (provider.mode === "search" ||
|
|
65
|
+
provider.mode === "instant-search" ||
|
|
66
|
+
(provider.mode === "curated-page" && provider.variation === "search")) {
|
|
67
|
+
if (curation === null || curation === void 0 ? void 0 : curation.searchTerm) {
|
|
68
|
+
const queriesMust = [
|
|
69
|
+
{ term: { "curations.searchTerm.keyword": curation.searchTerm.toLowerCase() } },
|
|
70
|
+
];
|
|
83
71
|
const queriesMustNot = [];
|
|
84
|
-
if (
|
|
85
|
-
queriesMust.push({
|
|
86
|
-
term: {
|
|
87
|
-
"curations.markets.keyword": options.provider.market,
|
|
88
|
-
},
|
|
89
|
-
});
|
|
72
|
+
if (provider.market) {
|
|
73
|
+
queriesMust.push({ term: { "curations.markets.keyword": provider.market } });
|
|
90
74
|
}
|
|
91
75
|
else {
|
|
92
|
-
queriesMustNot.push({
|
|
93
|
-
exists: {
|
|
94
|
-
field: "curations.markets.keyword"
|
|
95
|
-
},
|
|
96
|
-
});
|
|
76
|
+
queriesMustNot.push({ exists: { field: "curations.markets.keyword" } });
|
|
97
77
|
}
|
|
98
78
|
sorts.push({
|
|
99
79
|
"curations.position": {
|
|
@@ -102,109 +82,71 @@ const generateSortSort = (options) => {
|
|
|
102
82
|
nested: {
|
|
103
83
|
path: "curations",
|
|
104
84
|
filter: {
|
|
105
|
-
bool: Object.assign({ must: queriesMust }, queriesMustNot.length > 0 ? { must_not: queriesMustNot } : {})
|
|
106
|
-
}
|
|
85
|
+
bool: Object.assign({ must: queriesMust }, (queriesMustNot.length > 0 ? { must_not: queriesMustNot } : {})),
|
|
86
|
+
},
|
|
107
87
|
},
|
|
108
88
|
},
|
|
109
89
|
});
|
|
110
90
|
}
|
|
111
91
|
}
|
|
112
|
-
//
|
|
113
|
-
if (
|
|
114
|
-
if (0 <
|
|
115
|
-
const groupings =
|
|
92
|
+
// curation boost sorting
|
|
93
|
+
if (curation) {
|
|
94
|
+
if (0 < curation.boosting.groupings.length) {
|
|
95
|
+
const groupings = curation.boosting.groupings.sort((a, b) => (a.position > b.position ? 1 : -1));
|
|
116
96
|
for (const grouping of groupings) {
|
|
117
97
|
try {
|
|
118
98
|
const query = JSON.parse(grouping.query);
|
|
119
99
|
if (query)
|
|
120
100
|
sorts.push(query);
|
|
121
101
|
}
|
|
122
|
-
catch (
|
|
102
|
+
catch (_a) {
|
|
123
103
|
console.error(`query could not be parsed for boost grouping`, grouping);
|
|
124
104
|
}
|
|
125
105
|
}
|
|
126
106
|
}
|
|
127
|
-
if (0 <
|
|
128
|
-
const sortings =
|
|
107
|
+
if (0 < curation.boosting.sortings.length) {
|
|
108
|
+
const sortings = curation.boosting.sortings.sort((a, b) => (a.position > b.position ? 1 : -1));
|
|
129
109
|
for (const sorting of sortings) {
|
|
130
110
|
try {
|
|
131
111
|
let query = JSON.parse(sorting.query);
|
|
132
|
-
if (
|
|
133
|
-
query = {
|
|
134
|
-
[`inventory_quantity_market_${options.provider.market}`]: query.inventory_total,
|
|
135
|
-
};
|
|
112
|
+
if (provider.market && sorting.field === "inventory_total") {
|
|
113
|
+
query = { [`inventory_quantity_market_${provider.market}`]: query.inventory_total };
|
|
136
114
|
}
|
|
137
|
-
if (
|
|
138
|
-
query = {
|
|
139
|
-
[`price_min_market_${options.provider.market}`]: query.price_min,
|
|
140
|
-
};
|
|
115
|
+
if (provider.market && sorting.field === "price") {
|
|
116
|
+
query = { [`price_min_market_${provider.market}`]: query.price_min };
|
|
141
117
|
}
|
|
142
118
|
if (query) {
|
|
143
119
|
sorts.push(query);
|
|
144
120
|
}
|
|
145
121
|
}
|
|
146
|
-
catch (
|
|
122
|
+
catch (_b) {
|
|
147
123
|
console.error(`query could not be parsed for boost sorting`, sorting);
|
|
148
124
|
}
|
|
149
125
|
}
|
|
150
126
|
}
|
|
151
127
|
}
|
|
152
|
-
// default
|
|
153
|
-
|
|
154
|
-
sorts.push({
|
|
155
|
-
"collections.position": {
|
|
156
|
-
order: "asc",
|
|
157
|
-
nested: {
|
|
158
|
-
path: "collections",
|
|
159
|
-
filter: {
|
|
160
|
-
term: {
|
|
161
|
-
"collections.handle.keyword": options.provider.collectionHandle,
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
// default search sorting
|
|
169
|
-
if (options.provider.mode === "search" || options.provider.mode === "instant-search") {
|
|
170
|
-
sorts.push("_score");
|
|
171
|
-
}
|
|
128
|
+
// default sorting - use _score for all modes
|
|
129
|
+
sorts.push("_score");
|
|
172
130
|
return sorts;
|
|
173
131
|
};
|
|
174
132
|
exports.generateSortSort = generateSortSort;
|
|
175
133
|
const generateSortQuery = (options) => {
|
|
176
134
|
var _a;
|
|
177
|
-
|
|
135
|
+
const { provider, curation, sortOption } = options;
|
|
136
|
+
if (!curation || curation.id.includes("global"))
|
|
178
137
|
return { match_all: {} };
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
? options.curation.collectionHandle
|
|
186
|
-
: (_a = options.curation.searchTerm) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
term: {
|
|
191
|
-
"curations.hidden": true,
|
|
192
|
-
},
|
|
193
|
-
}];
|
|
138
|
+
const curationField = curation.type === "collection" ? "collectionHandle" : "searchTerm";
|
|
139
|
+
const curationValue = curation.type === "collection" ? curation.collectionHandle : (_a = curation.searchTerm) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
140
|
+
const queriesMust = [
|
|
141
|
+
{ term: { [`curations.${curationField}.keyword`]: curationValue } },
|
|
142
|
+
{ term: { "curations.hidden": true } },
|
|
143
|
+
];
|
|
194
144
|
const queriesMustNot = [];
|
|
195
|
-
if (
|
|
196
|
-
queriesMust.push({
|
|
197
|
-
term: {
|
|
198
|
-
"curations.markets.keyword": options.provider.market,
|
|
199
|
-
},
|
|
200
|
-
});
|
|
145
|
+
if (provider.market) {
|
|
146
|
+
queriesMust.push({ term: { "curations.markets.keyword": provider.market } });
|
|
201
147
|
}
|
|
202
148
|
else {
|
|
203
|
-
queriesMustNot.push({
|
|
204
|
-
exists: {
|
|
205
|
-
field: "curations.markets.keyword",
|
|
206
|
-
},
|
|
207
|
-
});
|
|
149
|
+
queriesMustNot.push({ exists: { field: "curations.markets.keyword" } });
|
|
208
150
|
}
|
|
209
151
|
return {
|
|
210
152
|
bool: {
|
|
@@ -213,20 +155,13 @@ const generateSortQuery = (options) => {
|
|
|
213
155
|
nested: {
|
|
214
156
|
path: "curations",
|
|
215
157
|
query: {
|
|
216
|
-
bool: Object.assign({ must: queriesMust }, queriesMustNot.length > 0 ? { must_not: queriesMustNot } : {}),
|
|
158
|
+
bool: Object.assign({ must: queriesMust }, (queriesMustNot.length > 0 ? { must_not: queriesMustNot } : {})),
|
|
217
159
|
},
|
|
218
160
|
},
|
|
219
161
|
},
|
|
220
162
|
// hide callout when not sorting by _score or collections.position
|
|
221
|
-
...(
|
|
222
|
-
|
|
223
|
-
? [
|
|
224
|
-
{
|
|
225
|
-
term: {
|
|
226
|
-
type: "callout",
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
]
|
|
163
|
+
...(sortOption && !["_score", "collections.position"].includes(sortOption.field)
|
|
164
|
+
? [{ term: { type: "callout" } }]
|
|
230
165
|
: []),
|
|
231
166
|
],
|
|
232
167
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sortOption.js","sourceRoot":"","sources":["../../../src/utility/sortOption.ts"],"names":[],"mappings":";;;AAGO,MAAM,cAAc,GAAG,CAAC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AI,EAAE;gBACJ,2BAA2B,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM;aACrD;SACF,CAAC,CAAA;IACJ,CAAC;SAAM,CAAC;QACN,cAAc,CAAC,IAAI,CAAC;YAClB,MAAM,EAAE;gBACN,KAAK,EAAE,2BAA2B;aACnC;SACF,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,IAAI,EAAE;YACJ,QAAQ,EAAE;gBACR;oBACE,MAAM,EAAE;wBACN,IAAI,EAAE,WAAW;wBACjB,KAAK,EAAE;4BACL,IAAI,kBACF,IAAI,EAAE,WAAW,IACd,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CACjE;yBACF;qBACF;iBACF;gBACD,kEAAkE;gBAClE,GAAG,CAAC,OAAO,CAAC,UAAU;oBACtB,CAAC,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC;oBACpE,CAAC,CAAC;wBACE;4BACE,IAAI,EAAE;gCACJ,IAAI,EAAE,SAAS;6BAChB;yBACF;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAtEW,QAAA,iBAAiB,qBAsE5B","sourcesContent":["import { ReactifySearchProviderProps } from \"../components\";\nimport { Config, ConfigCuration, ConfigSort } from \"../types\";\n\nexport const getSortOptions = (options: {\n provider: ReactifySearchProviderProps;\n config: Config;\n sortOption?: string;\n}) => {\n return options.config.sort\n .sort((a, b) => {\n const aInt =\n typeof a.position === \"string\"\n ? parseInt(a.position, 10)\n : a.position;\n const bInt =\n typeof b.position === \"string\"\n ? parseInt(b.position, 10)\n : b.position;\n return aInt - bInt;\n })\n .filter(({ visibility }) => [\"all\", options.provider.mode].includes(visibility));\n\n}\n\nexport const getSortOption = (options: {\n provider: ReactifySearchProviderProps;\n config: Config;\n sortOption?: string;\n query?: Record<string, string>;\n}) => {\n const sortOptions = getSortOptions(options);\n\n return sortOptions.find(({ handle }) => handle === options.sortOption || handle === options.query?.sort) ?? sortOptions[0];\n}\n\nexport const generateSortSort = (options: {\n provider: ReactifySearchProviderProps;\n config: Config;\n curation?: ConfigCuration;\n sortOption?: ConfigSort;\n}) => {\n // curation positions are only applied for the default `collections.position` or `_score` sort\n // if the sort is something else, apply a normal sort which applies what the user has requested\n if (options.provider.mode !== \"instant-search\") {\n if (\n options.sortOption &&\n ![\"_score\", \"collections.position\"].includes(options.sortOption.field)\n ) {\n if ([\"price_min\", \"price_max\"].includes(options.sortOption.field) && options.provider.market) {\n return [{ [`${options.sortOption.field}_market_${options.provider.market}`]: options.sortOption.direction }];\n }\n return [{ [options.sortOption.field]: options.sortOption.direction }];\n }\n }\n\n const sorts = [];\n\n // collection curation pin sorting\n if (options.provider.mode === \"collection\" && options.provider.collectionHandle) {\n if (options.curation?.collectionHandle) {\n const queriesMust: Array<unknown> = [{\n term: {\n \"curations.collectionHandle.keyword\": options.curation.collectionHandle,\n },\n }];\n const queriesMustNot: Array<unknown> = [];\n if (options.provider.market) {\n queriesMust.push({\n term: {\n \"curations.markets.keyword\": options.provider.market,\n },\n });\n } else {\n queriesMustNot.push({\n exists: {\n field: \"curations.markets.keyword\"\n },\n })\n }\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\n bool: {\n must: queriesMust,\n ...queriesMustNot.length > 0 ? { must_not: queriesMustNot } : {},\n }\n }\n },\n },\n });\n }\n }\n\n // search options.curation pin sorting\n if (options.provider.mode === \"search\" || options.provider.mode === \"instant-search\") {\n if (options.curation?.searchTerm) {\n const queriesMust: Array<unknown> = [{\n term: {\n \"curations.searchTerm.keyword\": options.curation.searchTerm.toLowerCase(),\n },\n }];\n const queriesMustNot: Array<unknown> = [];\n if (options.provider.market) {\n queriesMust.push({\n term: {\n \"curations.markets.keyword\": options.provider.market,\n },\n });\n } else {\n queriesMustNot.push({\n exists: {\n field: \"curations.markets.keyword\"\n },\n })\n }\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\n bool: {\n must: queriesMust,\n ...queriesMustNot.length > 0 ? { must_not: queriesMustNot } : {},\n }\n }\n },\n },\n });\n }\n }\n\n // options.curation boost sorting\n if (options.curation) {\n if (0 < options.curation.boosting.groupings.length) {\n const groupings = options.curation.boosting.groupings.sort((a, b) =>\n a.position > b.position ? 1 : -1\n );\n\n for (const grouping of groupings) {\n try {\n const query = JSON.parse(grouping.query);\n if (query) sorts.push(query);\n } catch {\n console.error(\n `query could not be parsed for boost grouping`,\n grouping\n );\n }\n }\n }\n\n if (0 < options.curation.boosting.sortings.length) {\n const sortings = options.curation.boosting.sortings.sort((a, b) =>\n a.position > b.position ? 1 : -1\n );\n\n for (const sorting of sortings) {\n try {\n let query = JSON.parse(sorting.query);\n\n if (options.provider.market && sorting.field === \"inventory_total\") {\n query = {\n [`inventory_quantity_market_${options.provider.market}`]: query.inventory_total,\n };\n }\n if (options.provider.market && sorting.field === \"price\") {\n query = {\n [`price_min_market_${options.provider.market}`]: query.price_min,\n };\n }\n if (query) {\n sorts.push(query);\n }\n } catch {\n console.error(`query could not be parsed for boost sorting`, sorting);\n }\n }\n }\n }\n\n // default collection sorting\n if (options.provider.mode === \"collection\" && options.provider.collectionHandle) {\n sorts.push({\n \"collections.position\": {\n order: \"asc\",\n nested: {\n path: \"collections\",\n filter: {\n term: {\n \"collections.handle.keyword\": options.provider.collectionHandle,\n },\n },\n },\n },\n });\n }\n\n // default search sorting\n if (options.provider.mode === \"search\" || options.provider.mode === \"instant-search\") {\n sorts.push(\"_score\");\n }\n\n return sorts;\n}\n\nexport const generateSortQuery = (options: {\n provider: ReactifySearchProviderProps;\n curation?: ConfigCuration;\n sortOption?: ConfigSort;\n}): Record<string, any> | undefined => {\n if (!options.curation || options.curation.id.includes(\"global\")) {\n return { match_all: {} };\n }\n\n const queriesMust: Array<unknown> = [{\n term: {\n [`curations.${\n \"collection\" === options.curation.type\n ? \"collectionHandle\"\n : \"searchTerm\"\n }.keyword`]:\n \"collection\" === options.curation.type\n ? options.curation.collectionHandle\n : options.curation.searchTerm?.toLowerCase(),\n },\n },\n {\n term: {\n \"curations.hidden\": true,\n },\n }];\n const queriesMustNot: Array<unknown> = [];\n\n if (options.provider.market) {\n queriesMust.push({\n term: {\n \"curations.markets.keyword\": options.provider.market,\n },\n })\n } else {\n queriesMustNot.push({\n exists: {\n field: \"curations.markets.keyword\",\n },\n });\n }\n\n return {\n bool: {\n must_not: [\n {\n nested: {\n path: \"curations\",\n query: {\n bool: {\n must: queriesMust,\n ...queriesMustNot.length > 0 ? { must_not: queriesMustNot } : {},\n },\n },\n },\n },\n // hide callout when not sorting by _score or collections.position\n ...(options.sortOption &&\n ![\"_score\", \"collections.position\"].includes(options.sortOption.field)\n ? [\n {\n term: {\n type: \"callout\",\n },\n },\n ]\n : []),\n ],\n },\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"sortOption.js","sourceRoot":"","sources":["../../../src/utility/sortOption.ts"],"names":[],"mappings":";;;AAGO,MAAM,cAAc,GAAG,CAAC,OAI9B,EAAE,EAAE;IACH,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,cAAc,GAAG,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC7F,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI;SACvB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CA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A5CW,QAAA,iBAAiB,qBA4C5B","sourcesContent":["import { ReactifySearchProviderProps } from \"../components\";\nimport { Config, ConfigCuration, ConfigSort } from \"../types\";\n\nexport const getSortOptions = (options: {\n provider: ReactifySearchProviderProps;\n config: Config;\n sortOption?: string;\n}) => {\n const { provider } = options;\n const visibilityMode = provider.mode === \"curated-page\" ? provider.variation : provider.mode;\n return options.config.sort\n .sort((a, b) => {\n const aInt = typeof a.position === \"string\" ? parseInt(a.position, 10) : a.position;\n const bInt = typeof b.position === \"string\" ? parseInt(b.position, 10) : b.position;\n return aInt - bInt;\n })\n .filter(({ visibility }) => [\"all\", visibilityMode].includes(visibility));\n};\n\nexport const getSortOption = (options: {\n provider: ReactifySearchProviderProps;\n config: Config;\n sortOption?: string;\n query?: Record<string, string>;\n}) => {\n const sortOptions = getSortOptions(options);\n\n return (\n sortOptions.find(({ handle }) => handle === options.sortOption || handle === options.query?.sort) ?? sortOptions[0]\n );\n};\n\nexport const generateSortSort = (options: {\n provider: ReactifySearchProviderProps;\n config: Config;\n curation?: ConfigCuration;\n sortOption?: ConfigSort;\n}) => {\n const { provider, curation, sortOption } = options;\n // curation positions are only applied for the default `collections.position` or `_score` sort\n // if the sort is something else, apply a normal sort which applies what the user has requested\n if (provider.mode !== \"instant-search\") {\n if (sortOption && ![\"_score\", \"collections.position\"].includes(sortOption.field)) {\n if ([\"price_min\", \"price_max\"].includes(sortOption.field) && provider.market) {\n return [{ [`${sortOption.field}_market_${provider.market}`]: sortOption.direction }];\n }\n return [{ [sortOption.field]: sortOption.direction }];\n }\n }\n\n const sorts = [];\n\n // collection curation pin sorting\n if (\n (provider.mode === \"collection\" && provider.collectionHandle) ||\n (provider.mode === \"curated-page\" && provider.variation === \"collection\")\n ) {\n if (curation?.collectionHandle) {\n const queriesMust: Array<unknown> = [\n { term: { \"curations.collectionHandle.keyword\": curation.collectionHandle } },\n ];\n const queriesMustNot: Array<unknown> = [];\n if (provider.market) {\n queriesMust.push({ term: { \"curations.markets.keyword\": provider.market } });\n } else {\n queriesMustNot.push({ exists: { field: \"curations.markets.keyword\" } });\n }\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\n bool: {\n must: queriesMust,\n ...(queriesMustNot.length > 0 ? { must_not: queriesMustNot } : {}),\n },\n },\n },\n },\n });\n }\n }\n\n // search curation pin sorting\n if (\n provider.mode === \"search\" ||\n provider.mode === \"instant-search\" ||\n (provider.mode === \"curated-page\" && provider.variation === \"search\")\n ) {\n if (curation?.searchTerm) {\n const queriesMust: Array<unknown> = [\n { term: { \"curations.searchTerm.keyword\": curation.searchTerm.toLowerCase() } },\n ];\n const queriesMustNot: Array<unknown> = [];\n if (provider.market) {\n queriesMust.push({ term: { \"curations.markets.keyword\": provider.market } });\n } else {\n queriesMustNot.push({ exists: { field: \"curations.markets.keyword\" } });\n }\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\n bool: {\n must: queriesMust,\n ...(queriesMustNot.length > 0 ? { must_not: queriesMustNot } : {}),\n },\n },\n },\n },\n });\n }\n }\n\n // curation boost sorting\n if (curation) {\n if (0 < curation.boosting.groupings.length) {\n const groupings = curation.boosting.groupings.sort((a, b) => (a.position > b.position ? 1 : -1));\n\n for (const grouping of groupings) {\n try {\n const query = JSON.parse(grouping.query);\n if (query) sorts.push(query);\n } catch {\n console.error(`query could not be parsed for boost grouping`, grouping);\n }\n }\n }\n\n if (0 < curation.boosting.sortings.length) {\n const sortings = curation.boosting.sortings.sort((a, b) => (a.position > b.position ? 1 : -1));\n\n for (const sorting of sortings) {\n try {\n let query = JSON.parse(sorting.query);\n\n if (provider.market && sorting.field === \"inventory_total\") {\n query = { [`inventory_quantity_market_${provider.market}`]: query.inventory_total };\n }\n if (provider.market && sorting.field === \"price\") {\n query = { [`price_min_market_${provider.market}`]: query.price_min };\n }\n if (query) {\n sorts.push(query);\n }\n } catch {\n console.error(`query could not be parsed for boost sorting`, sorting);\n }\n }\n }\n }\n\n // default sorting - use _score for all modes\n sorts.push(\"_score\");\n\n return sorts;\n};\n\nexport const generateSortQuery = (options: {\n provider: ReactifySearchProviderProps;\n curation?: ConfigCuration;\n sortOption?: ConfigSort;\n}): Record<string, any> | undefined => {\n const { provider, curation, sortOption } = options;\n if (!curation || curation.id.includes(\"global\")) return { match_all: {} };\n\n const curationField = curation.type === \"collection\" ? \"collectionHandle\" : \"searchTerm\";\n const curationValue = curation.type === \"collection\" ? curation.collectionHandle : curation.searchTerm?.toLowerCase();\n\n const queriesMust: Array<unknown> = [\n { term: { [`curations.${curationField}.keyword`]: curationValue } },\n { term: { \"curations.hidden\": true } },\n ];\n const queriesMustNot: Array<unknown> = [];\n\n if (provider.market) {\n queriesMust.push({ term: { \"curations.markets.keyword\": provider.market } });\n } else {\n queriesMustNot.push({ exists: { field: \"curations.markets.keyword\" } });\n }\n\n return {\n bool: {\n must_not: [\n {\n nested: {\n path: \"curations\",\n query: {\n bool: {\n must: queriesMust,\n ...(queriesMustNot.length > 0 ? { must_not: queriesMustNot } : {}),\n },\n },\n },\n },\n // hide callout when not sorting by _score or collections.position\n ...(sortOption && ![\"_score\", \"collections.position\"].includes(sortOption.field)\n ? [{ term: { type: \"callout\" } }]\n : []),\n ],\n },\n };\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usereactify/search",
|
|
3
3
|
"description": "React UI library for Reactify Search",
|
|
4
|
-
"version": "5.59.0-beta.
|
|
4
|
+
"version": "5.59.0-beta.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
7
7
|
"types": "dist/src/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"README.md",
|
|
11
11
|
"CHANGELOG.md"
|
|
12
12
|
],
|
|
13
|
-
"packageManager": "pnpm@
|
|
13
|
+
"packageManager": "pnpm@10.13.1",
|
|
14
14
|
"scripts": {
|
|
15
15
|
"watch": "tsc --watch",
|
|
16
16
|
"release": "standard-version --tag-prefix release-v",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
]
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@appbaseio/reactivecore": "9.8.0",
|
|
33
32
|
"@usereactify/search-internals": "1.0.0",
|
|
33
|
+
"@appbaseio/reactivecore": "9.15.2",
|
|
34
34
|
"ahooks": "2.10.11",
|
|
35
|
-
"axios": "
|
|
35
|
+
"axios": "1.10.0",
|
|
36
36
|
"currency.js": "2.0.4",
|
|
37
37
|
"debug": "4.3.2",
|
|
38
38
|
"ga-gtag": "1.1.5",
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"react-slider": "2.0.4"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"react": "
|
|
43
|
+
"react": "^18.2.0",
|
|
44
|
+
"react-dom": "^18.2.0"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@babel/plugin-transform-typescript": "7.18.12",
|