@usereactify/search 5.11.0 → 5.12.0
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 +25 -0
- package/dist/package.json +1 -1
- package/dist/src/components/Sensor/SensorSearchTerm.js +1 -1
- package/dist/src/components/Sensor/SensorSearchTerm.js.map +1 -1
- package/dist/src/components/Sensor/SensorSort.js +71 -65
- package/dist/src/components/Sensor/SensorSort.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [5.12.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.11.0...release-v5.12.0) (2022-11-20)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* exclude all keyword fields from span_first query ([a479ba7](https://bitbucket.org/usereactify/reactify-search-ui/commit/a479ba7b6be8cedaf96618fe04e6e0d50dce01df))
|
|
11
|
+
* improve logic and codeflow for sorting ([80dcb8f](https://bitbucket.org/usereactify/reactify-search-ui/commit/80dcb8f0190d1c88c43efe41bb6c06c48f2e36ef))
|
|
12
|
+
|
|
13
|
+
## [5.12.0-beta.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/beta-v5.10.0-beta.1...beta-v5.12.0-beta.0) (2022-11-20)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* exclude all keyword fields from span_first query ([a479ba7](https://bitbucket.org/usereactify/reactify-search-ui/commit/a479ba7b6be8cedaf96618fe04e6e0d50dce01df))
|
|
19
|
+
* improve example slider styling ([02763a6](https://bitbucket.org/usereactify/reactify-search-ui/commit/02763a6f6f9f2ce6103bf76a343f1d29d0aa484c))
|
|
20
|
+
* improve logic and codeflow for sorting ([80dcb8f](https://bitbucket.org/usereactify/reactify-search-ui/commit/80dcb8f0190d1c88c43efe41bb6c06c48f2e36ef))
|
|
21
|
+
* sort based on _score when mode is search or instant search ([9f82218](https://bitbucket.org/usereactify/reactify-search-ui/commit/9f82218a02c010d9b1ecb286f1b20b765c27929b))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* simplify Filters component ([49467dd](https://bitbucket.org/usereactify/reactify-search-ui/commit/49467ddb5f05ca685cc862426f924d9e78ed22a2))
|
|
27
|
+
* update ExampleFilters ([f324434](https://bitbucket.org/usereactify/reactify-search-ui/commit/f324434c000f5bcf2e26ebc19e163bd46565f0d0))
|
|
28
|
+
* update pnpm-lock.yaml ([86a53a2](https://bitbucket.org/usereactify/reactify-search-ui/commit/86a53a28f4d6a9806b35bc71c92254d9164205e6))
|
|
29
|
+
|
|
5
30
|
## [5.11.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.10.3...release-v5.11.0) (2022-11-15)
|
|
6
31
|
|
|
7
32
|
|
package/dist/package.json
CHANGED
|
@@ -53,7 +53,7 @@ const SensorSearchTerm = () => {
|
|
|
53
53
|
.filter((field) => !field.includes("."));
|
|
54
54
|
const fieldsSpanFirst = dataField
|
|
55
55
|
.filter((field) => {
|
|
56
|
-
if (field.
|
|
56
|
+
if (field.endsWith(".keyword")) {
|
|
57
57
|
return false;
|
|
58
58
|
}
|
|
59
59
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SensorSearchTerm.js","sourceRoot":"","sources":["../../../../src/components/Sensor/SensorSearchTerm.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,mCAAuC;AACvC,4GAAoF;AAEpF,uCAAgF;AAEzE,MAAM,gBAAgB,GAAa,GAAG,EAAE;IAC7C,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,EAAE,KAAK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,EAAE,CAAC;4BACP,GAAG,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC;gCACzB,CAAC,CAAC;oCACE;wCACE,WAAW,EAAE;4CACX,KAAK,EAAE,KAAK;4CACZ,MAAM,EAAE,YAAY;4CACpB,IAAI,EAAE,QAAQ;4CACd,QAAQ,EAAE,KAAK;yCAChB;qCACF;iCACF;gCACH,CAAC,CAAC,EAAE,CAAC;4BACP,GAAG,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC;gCAC/B,CAAC,CAAC;oCACE;wCACE,WAAW,EAAE;4CACX,KAAK,EAAE,KAAK;4CACZ,MAAM,EAAE,kBAAkB;4CAC1B,IAAI,EAAE,eAAe;4CACrB,QAAQ,EAAE,KAAK;yCAChB;qCACF;iCACF;gCACH,CAAC,CAAC,EAAE,CAAC;4BACP,GAAG,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC;gCAC9B,CAAC,CAAC;oCACE;wCACE,WAAW,EAAE;4CACX,KAAK,EAAE,KAAK;4CACZ,MAAM,EAAE,iBAAiB;4CACzB,IAAI,EAAE,cAAc;4CACpB,QAAQ,EAAE,KAAK;yCAChB;qCACF;iCACF;gCACH,CAAC,CAAC,EAAE,CAAC;4BACP,GAAG,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;yBAC5D;wBACD,oBAAoB,EAAE,GAAG;qBAC1B;iBACF,CAAC;gBACF,OAAO,EAAE,KAAK,EAAE,CAAC;YACnB,CAAC,GACD,CACD,CACJ,CAAC;AACJ,CAAC,CAAC;AApKW,QAAA,gBAAgB,oBAoK3B","sourcesContent":["import React from \"react\";\nimport { useDebounceFn } from \"ahooks\";\nimport DataSearch from \"@appbaseio/reactivesearch/lib/components/search/DataSearch\";\n\nimport { useAnalytics, useReactifySearchContext, useSearch } from \"../../hooks\";\n\nexport const SensorSearchTerm: React.FC = () => {\n const { options, config } = useReactifySearchContext();\n const { track } = useAnalytics();\n const { searchTerm } = useSearch();\n\n const [searchTermDebounced, setSearchTermDebounced] =\n React.useState<string>(searchTerm);\n\n // ignore search fields only set for instant search\n const searchFields = React.useMemo(() => {\n if (options.mode === \"search\") {\n return config.fields.filter((field) =>\n [\"always_search\", \"search_page\"].includes(field.searchType)\n );\n }\n\n if (options.mode === \"instant-search\") {\n return config.fields.filter((field) =>\n [\"always_search\", \"instant_search\"].includes(field.searchType)\n );\n }\n\n return [];\n }, [config.fields]);\n\n const { run: runDebouncedTriggerQuery, cancel: cancelDebouncedTriggerQuery } =\n useDebounceFn(\n (value: string) => {\n setSearchTermDebounced(value);\n\n if (!value || (value && value.length < 3)) {\n return;\n }\n\n track({\n eventName: \"search\",\n payload: {\n searchTerm: value,\n },\n });\n },\n {\n wait: 300,\n }\n );\n\n React.useEffect(() => {\n runDebouncedTriggerQuery(searchTerm);\n }, [searchTerm]);\n\n if (searchFields.length === 0) {\n return null;\n }\n\n return (\n <>\n <DataSearch\n fuzziness={1}\n queryFormat=\"and\"\n autosuggest={false}\n value={searchTermDebounced}\n componentId=\"SensorSearchTerm\"\n style={{ display: \"none\" }}\n dataField={searchFields.map((field) => field.field)}\n fieldWeights={searchFields.map((field) => field.importance)}\n customQuery={(value, props) => {\n const { dataField, fieldWeights } = props;\n\n const fieldsCrossFields = dataField.map(\n (field: string, index: number) => `${field}^${fieldWeights[index]}`\n );\n\n const fieldsPhrase = dataField.map(\n (field: string, index: number) => `${field}^${fieldWeights[index]}`\n );\n\n const fieldsPhrasePrefix = dataField\n .map(\n (field: string, index: number) =>\n `${field}^${fieldWeights[index]}`\n )\n .filter((field: string) => !field.includes(\".\"));\n\n const fieldsSpanFirst: any = dataField\n .filter((field: string) => {\n if (field.endsWith(\".keyword\")) {\n return false;\n }\n\n return true;\n })\n .map((field: string) => ({\n span_first: {\n match: {\n span_term: { [`${field}`]: value },\n },\n end: 1,\n },\n }));\n\n const query = {\n bool: {\n should: [\n ...(value\n ? [\n {\n nested: {\n path: \"curations\",\n query: {\n term: {\n \"curations.searchTerm.keyword\":\n value.toLowerCase(),\n },\n },\n },\n },\n ]\n : []),\n ...(fieldsPhrase.length > 0\n ? [\n {\n multi_match: {\n query: value,\n fields: fieldsPhrase,\n type: \"phrase\",\n operator: \"and\",\n },\n },\n ]\n : []),\n ...(fieldsPhrasePrefix.length > 0\n ? [\n {\n multi_match: {\n query: value,\n fields: fieldsPhrasePrefix,\n type: \"phrase_prefix\",\n operator: \"and\",\n },\n },\n ]\n : []),\n ...(fieldsCrossFields.length > 0\n ? [\n {\n multi_match: {\n query: value,\n fields: fieldsCrossFields,\n type: \"cross_fields\",\n operator: \"and\",\n },\n },\n ]\n : []),\n ...(fieldsSpanFirst.length > 0 ? [...fieldsSpanFirst] : []),\n ],\n minimum_should_match: \"1\",\n },\n };\n return { query };\n }}\n />\n </>\n );\n};\n"]}
|
|
@@ -10,13 +10,11 @@ const hooks_1 = require("../../hooks");
|
|
|
10
10
|
const SensorSort = () => {
|
|
11
11
|
const { options, config } = (0, hooks_1.useReactifySearchContext)();
|
|
12
12
|
const { curation } = (0, hooks_1.useCuration)();
|
|
13
|
-
const globalCuration = (curation === null || curation === void 0 ? void 0 : curation.id) === "global";
|
|
14
13
|
const { sortOption } = (0, hooks_1.useSortBy)();
|
|
15
14
|
const { sort, query } = react_1.default.useMemo(() => {
|
|
16
15
|
return {
|
|
17
16
|
sort: buildSort({
|
|
18
17
|
mode: options.mode,
|
|
19
|
-
globalCuration,
|
|
20
18
|
curation,
|
|
21
19
|
sortOption,
|
|
22
20
|
collectionHandle: options.mode === "collection" ? options.collectionHandle : undefined,
|
|
@@ -24,10 +22,9 @@ const SensorSort = () => {
|
|
|
24
22
|
query: buildQuery({
|
|
25
23
|
sortOption,
|
|
26
24
|
curation,
|
|
27
|
-
globalCuration,
|
|
28
25
|
}),
|
|
29
26
|
};
|
|
30
|
-
}, [options, config, sortOption, curation
|
|
27
|
+
}, [options, config, sortOption, curation]);
|
|
31
28
|
return (react_1.default.createElement(ReactiveComponent_1.default, { componentId: "SensorSort", customQuery: () => ({
|
|
32
29
|
sort,
|
|
33
30
|
query,
|
|
@@ -36,80 +33,89 @@ const SensorSort = () => {
|
|
|
36
33
|
exports.SensorSort = SensorSort;
|
|
37
34
|
const buildSort = (args) => {
|
|
38
35
|
var _a;
|
|
39
|
-
const { mode, curation, sortOption, collectionHandle
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
: ["_score"];
|
|
46
|
-
}
|
|
47
|
-
// curation positions are only applied for the default `collections.position` or `_score` sort
|
|
48
|
-
// if the sort is something else, apply a normal sort which applies what the user has requested
|
|
49
|
-
if (!["_score", "collections.position"].includes(sortOption.field)) {
|
|
50
|
-
return [{ [sortOption.field]: sortOption.direction }];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// no matching curation, return default sort clause
|
|
54
|
-
if (!curation) {
|
|
55
|
-
return collectionHandle
|
|
56
|
-
? mapCollectionPositionSortClause(collectionHandle)
|
|
57
|
-
: ["_score"];
|
|
36
|
+
const { mode, curation, sortOption, collectionHandle } = args;
|
|
37
|
+
// curation positions are only applied for the default `collections.position` or `_score` sort
|
|
38
|
+
// if the sort is something else, apply a normal sort which applies what the user has requested
|
|
39
|
+
if (sortOption &&
|
|
40
|
+
!["_score", "collections.position"].includes(sortOption.field)) {
|
|
41
|
+
return [{ [sortOption.field]: sortOption.direction }];
|
|
58
42
|
}
|
|
59
43
|
const sorts = [];
|
|
60
|
-
//
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
:
|
|
44
|
+
// collection specific sorting
|
|
45
|
+
if (mode === "collection" && collectionHandle) {
|
|
46
|
+
if (!curation || (curation === null || curation === void 0 ? void 0 : curation.id) === "global") {
|
|
47
|
+
sorts.push(...mapCollectionPositionSortClause(collectionHandle));
|
|
48
|
+
}
|
|
49
|
+
if (curation === null || curation === void 0 ? void 0 : curation.collectionHandle) {
|
|
50
|
+
sorts.push({
|
|
51
|
+
"curations.position": {
|
|
52
|
+
unmapped_type: "long",
|
|
53
|
+
order: "asc",
|
|
54
|
+
nested: {
|
|
55
|
+
path: "curations",
|
|
56
|
+
filter: {
|
|
57
|
+
term: {
|
|
58
|
+
[`curations.collectionHandle.keyword`]: curation.collectionHandle,
|
|
59
|
+
},
|
|
75
60
|
},
|
|
76
61
|
},
|
|
77
62
|
},
|
|
78
|
-
}
|
|
79
|
-
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
80
65
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
66
|
+
// search specific sorting
|
|
67
|
+
if (mode === "search" || mode === "instant-search") {
|
|
68
|
+
if (curation === null || curation === void 0 ? void 0 : curation.searchTerm) {
|
|
69
|
+
sorts.push({
|
|
70
|
+
"curations.position": {
|
|
71
|
+
unmapped_type: "long",
|
|
72
|
+
order: "asc",
|
|
73
|
+
nested: {
|
|
74
|
+
path: "curations",
|
|
75
|
+
filter: {
|
|
76
|
+
term: {
|
|
77
|
+
[`curations.searchTerm.keyword`]: (_a = curation.searchTerm) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
});
|
|
92
83
|
}
|
|
93
84
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
85
|
+
// curation specific sorting
|
|
86
|
+
if (curation) {
|
|
87
|
+
if (0 < curation.boosting.groupings.length) {
|
|
88
|
+
const groupings = curation.boosting.groupings.sort((a, b) => a.position > b.position ? 1 : -1);
|
|
89
|
+
for (const grouping of groupings) {
|
|
90
|
+
try {
|
|
91
|
+
const query = JSON.parse(grouping.query);
|
|
92
|
+
if (query)
|
|
93
|
+
sorts.push(query);
|
|
94
|
+
}
|
|
95
|
+
catch (_b) {
|
|
96
|
+
console.error(`query could not be parsed for boost grouping`, grouping);
|
|
97
|
+
}
|
|
101
98
|
}
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
}
|
|
100
|
+
if (0 < curation.boosting.sortings.length) {
|
|
101
|
+
const sortings = curation.boosting.sortings.sort((a, b) => a.position > b.position ? 1 : -1);
|
|
102
|
+
for (const sorting of sortings) {
|
|
103
|
+
try {
|
|
104
|
+
const query = JSON.parse(sorting.query);
|
|
105
|
+
if (query)
|
|
106
|
+
sorts.push(query);
|
|
107
|
+
}
|
|
108
|
+
catch (_c) {
|
|
109
|
+
console.error(`query could not be parsed for boost sorting`, sorting);
|
|
110
|
+
}
|
|
104
111
|
}
|
|
105
112
|
}
|
|
106
113
|
}
|
|
107
|
-
// finally
|
|
108
|
-
// a consistent order
|
|
114
|
+
// finally for collections if no other sorting is defined, sort by index order to provide a consistent order
|
|
109
115
|
if (mode === "collection" && sorts.length === 0) {
|
|
110
116
|
sorts.push("_doc");
|
|
111
117
|
}
|
|
112
|
-
// finally
|
|
118
|
+
// finally for search sort by score
|
|
113
119
|
if (mode === "search" || mode === "instant-search") {
|
|
114
120
|
sorts.push("_score");
|
|
115
121
|
}
|
|
@@ -137,8 +143,8 @@ function mapCollectionPositionSortClause(collectionHandle) {
|
|
|
137
143
|
}
|
|
138
144
|
const buildQuery = (args) => {
|
|
139
145
|
var _a;
|
|
140
|
-
const { curation, sortOption
|
|
141
|
-
if (!curation ||
|
|
146
|
+
const { curation, sortOption } = args;
|
|
147
|
+
if (!curation || curation.id === "global") {
|
|
142
148
|
return undefined;
|
|
143
149
|
}
|
|
144
150
|
return {
|
|
@@ -1 +1 @@
|
|
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AAC,gBAAgB;gDAC3B,CAAC,CAAC,MAAA,QAAQ,CAAC,UAAU,0CAAE,WAAW,EAAE;yCACzC;qCACF;oCACD;wCACE,IAAI,EAAE;4CACJ,kBAAkB,EAAE,IAAI;yCACzB;qCACF;iCACF;6BACF;yBACF;qBACF;iBACF;gBACD,kEAAkE;gBAClE,GAAG,CAAC,UAAU;oBACd,CAAC,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC;oBAC5D,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","sourcesContent":["import React from \"react\";\nimport ReactiveComponent from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent\";\n\nimport { ConfigCuration, ConfigSort } from \"../../types\";\nimport {\n useReactifySearchContext,\n useSortBy,\n useCuration,\n ReactifySearchMode,\n} from \"../../hooks\";\nimport { optionsToId } from \"react-intersection-observer/observe\";\n\nexport const SensorSort: React.FC = () => {\n const { options, config } = useReactifySearchContext();\n const { curation } = useCuration();\n const globalCuration = curation?.id === \"global\";\n\n const { sortOption } = useSortBy();\n\n const { sort, query } = React.useMemo(() => {\n return {\n sort: buildSort({\n mode: options.mode,\n globalCuration,\n curation,\n sortOption,\n collectionHandle:\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n }),\n query: buildQuery({\n sortOption,\n curation,\n globalCuration,\n }),\n };\n }, [options, config, sortOption, curation, globalCuration]);\n\n return (\n <ReactiveComponent\n componentId=\"SensorSort\"\n customQuery={() => ({\n sort,\n query,\n })}\n />\n );\n};\n\nconst buildSort = (args: {\n mode: ReactifySearchMode;\n globalCuration: boolean;\n curation?: ConfigCuration;\n sortOption?: ConfigSort;\n collectionHandle?: string;\n}): any[] => {\n const { mode, curation, sortOption, collectionHandle, globalCuration } = args;\n\n if (mode !== \"instant-search\") {\n // return default sort option if unset\n if (!sortOption) {\n return collectionHandle\n ? mapCollectionPositionSortClause(collectionHandle)\n : [\"_score\"];\n }\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 (![\"_score\", \"collections.position\"].includes(sortOption.field)) {\n return [{ [sortOption.field]: sortOption.direction }];\n }\n }\n\n // no matching curation, return default sort clause\n if (!curation) {\n return collectionHandle\n ? mapCollectionPositionSortClause(collectionHandle)\n : [\"_score\"];\n }\n\n const sorts = [];\n\n // show pins first\n if (!globalCuration && (curation.collectionHandle || curation.searchTerm)) {\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\n term: {\n [`curations.${\n \"collection\" === curation.type\n ? \"collectionHandle\"\n : \"searchTerm\"\n }.keyword`]:\n \"collection\" === curation.type\n ? curation.collectionHandle\n : curation.searchTerm?.toLowerCase(),\n },\n },\n },\n },\n });\n }\n\n if (0 < curation.boosting.groupings.length) {\n const groupings = 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(`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) =>\n a.position > b.position ? 1 : -1\n );\n\n for (const sorting of sortings) {\n try {\n const query = JSON.parse(sorting.query);\n if (query) sorts.push(query);\n } catch {\n console.error(`query could not be parsed for boost sorting`, sorting);\n }\n }\n }\n\n // finally, for collections, if no other sorting is defined, sort by index order to provide\n // a consistent order\n if (mode === \"collection\" && sorts.length === 0) {\n sorts.push(\"_doc\");\n }\n\n // finally, for search, sort by score\n if (mode === \"search\" || mode === \"instant-search\") {\n sorts.push(\"_score\");\n }\n\n return sorts;\n};\n\n/**\n * Return a sort clause which sorts by position within the given collection.\n */\nfunction mapCollectionPositionSortClause(collectionHandle: string) {\n return [\n {\n \"collections.position\": {\n order: \"asc\",\n nested: {\n path: \"collections\",\n filter: {\n term: {\n \"collections.handle.keyword\": collectionHandle,\n },\n },\n },\n },\n },\n ];\n}\n\nconst buildQuery = (args: {\n sortOption?: ConfigSort;\n curation?: ConfigCuration;\n globalCuration?: boolean;\n}): Record<string, any> | undefined => {\n const { curation, sortOption, globalCuration } = args;\n\n if (!curation || globalCuration) {\n return undefined;\n }\n\n return {\n bool: {\n must_not: [\n {\n nested: {\n path: \"curations\",\n query: {\n bool: {\n must: [\n {\n term: {\n [`curations.${\n \"collection\" === curation.type\n ? \"collectionHandle\"\n : \"searchTerm\"\n }.keyword`]:\n \"collection\" === curation.type\n ? curation.collectionHandle\n : curation.searchTerm?.toLowerCase(),\n },\n },\n {\n term: {\n \"curations.hidden\": true,\n },\n },\n ],\n },\n },\n },\n },\n // hide callout when not sorting by _score or collections.position\n ...(sortOption &&\n ![\"_score\", \"collections.position\"].includes(sortOption.field)\n ? [\n {\n term: {\n type: \"callout\",\n },\n },\n ]\n : []),\n ],\n },\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"SensorSort.js","sourceRoot":"","sources":["../../../../src/components/Sensor/SensorSort.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yHAAiG;AAGjG,uCAKqB;AAEd,MAAM,UAAU,GAAa,GAAG,EAAE;IACvC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,mBAAW,GAAE,CAAC;IAEnC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,iBAAS,GAAE,CAAC;IAEnC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACzC,OAAO;YACL,IAAI,EAAE,SAAS,CAAC;gBACd,IAAI,EAAE,OAAO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ReactiveComponent from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent\";\n\nimport { ConfigCuration, ConfigSort } from \"../../types\";\nimport {\n useReactifySearchContext,\n useSortBy,\n useCuration,\n ReactifySearchMode,\n} from \"../../hooks\";\n\nexport const SensorSort: React.FC = () => {\n const { options, config } = useReactifySearchContext();\n const { curation } = useCuration();\n\n const { sortOption } = useSortBy();\n\n const { sort, query } = React.useMemo(() => {\n return {\n sort: buildSort({\n mode: options.mode,\n curation,\n sortOption,\n collectionHandle:\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n }),\n query: buildQuery({\n sortOption,\n curation,\n }),\n };\n }, [options, config, sortOption, curation]);\n\n return (\n <ReactiveComponent\n componentId=\"SensorSort\"\n customQuery={() => ({\n sort,\n query,\n })}\n />\n );\n};\n\nconst buildSort = (args: {\n mode: ReactifySearchMode;\n curation?: ConfigCuration;\n sortOption?: ConfigSort;\n collectionHandle?: string;\n}): any[] => {\n const { mode, curation, sortOption, collectionHandle } = args;\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 (\n sortOption &&\n ![\"_score\", \"collections.position\"].includes(sortOption.field)\n ) {\n return [{ [sortOption.field]: sortOption.direction }];\n }\n\n const sorts = [];\n\n // collection specific sorting\n if (mode === \"collection\" && collectionHandle) {\n if (!curation || curation?.id === \"global\") {\n sorts.push(...mapCollectionPositionSortClause(collectionHandle));\n }\n\n if (curation?.collectionHandle) {\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\n term: {\n [`curations.collectionHandle.keyword`]:\n curation.collectionHandle,\n },\n },\n },\n },\n });\n }\n }\n\n // search specific sorting\n if (mode === \"search\" || mode === \"instant-search\") {\n if (curation?.searchTerm) {\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\n term: {\n [`curations.searchTerm.keyword`]:\n curation.searchTerm?.toLowerCase(),\n },\n },\n },\n },\n });\n }\n }\n\n // curation specific sorting\n if (curation) {\n if (0 < curation.boosting.groupings.length) {\n const groupings = 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 < curation.boosting.sortings.length) {\n const sortings = curation.boosting.sortings.sort((a, b) =>\n a.position > b.position ? 1 : -1\n );\n\n for (const sorting of sortings) {\n try {\n const query = JSON.parse(sorting.query);\n if (query) sorts.push(query);\n } catch {\n console.error(`query could not be parsed for boost sorting`, sorting);\n }\n }\n }\n }\n\n // finally for collections if no other sorting is defined, sort by index order to provide a consistent order\n if (mode === \"collection\" && sorts.length === 0) {\n sorts.push(\"_doc\");\n }\n\n // finally for search sort by score\n if (mode === \"search\" || mode === \"instant-search\") {\n sorts.push(\"_score\");\n }\n\n return sorts;\n};\n\n/**\n * Return a sort clause which sorts by position within the given collection.\n */\nfunction mapCollectionPositionSortClause(collectionHandle: string) {\n return [\n {\n \"collections.position\": {\n order: \"asc\",\n nested: {\n path: \"collections\",\n filter: {\n term: {\n \"collections.handle.keyword\": collectionHandle,\n },\n },\n },\n },\n },\n ];\n}\n\nconst buildQuery = (args: {\n sortOption?: ConfigSort;\n curation?: ConfigCuration;\n}): Record<string, any> | undefined => {\n const { curation, sortOption } = args;\n\n if (!curation || curation.id === \"global\") {\n return undefined;\n }\n\n return {\n bool: {\n must_not: [\n {\n nested: {\n path: \"curations\",\n query: {\n bool: {\n must: [\n {\n term: {\n [`curations.${\n \"collection\" === curation.type\n ? \"collectionHandle\"\n : \"searchTerm\"\n }.keyword`]:\n \"collection\" === curation.type\n ? curation.collectionHandle\n : curation.searchTerm?.toLowerCase(),\n },\n },\n {\n term: {\n \"curations.hidden\": true,\n },\n },\n ],\n },\n },\n },\n },\n // hide callout when not sorting by _score or collections.position\n ...(sortOption &&\n ![\"_score\", \"collections.position\"].includes(sortOption.field)\n ? [\n {\n term: {\n type: \"callout\",\n },\n },\n ]\n : []),\n ],\n },\n };\n};\n"]}
|