@usereactify/search 5.12.0 → 5.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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
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.2](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.12.1...release-v5.12.2) (2022-11-21)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* exclude selectable sort option from instant search logic ([988427d](https://bitbucket.org/usereactify/reactify-search-ui/commit/988427d72ee6525cf20c4a3f8a900d3bf9db398a))
|
|
11
|
+
|
|
12
|
+
### [5.12.1](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.12.0...release-v5.12.1) (2022-11-21)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* only apply global boosting rules in collection mode ([731009c](https://bitbucket.org/usereactify/reactify-search-ui/commit/731009c9d6df2dee80d30bbef678b7c7a68bdd55))
|
|
18
|
+
|
|
5
19
|
## [5.12.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.11.0...release-v5.12.0) (2022-11-20)
|
|
6
20
|
|
|
7
21
|
|
package/dist/package.json
CHANGED
|
@@ -36,9 +36,11 @@ const buildSort = (args) => {
|
|
|
36
36
|
const { mode, curation, sortOption, collectionHandle } = args;
|
|
37
37
|
// curation positions are only applied for the default `collections.position` or `_score` sort
|
|
38
38
|
// if the sort is something else, apply a normal sort which applies what the user has requested
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
if (mode !== "instant-search") {
|
|
40
|
+
if (sortOption &&
|
|
41
|
+
!["_score", "collections.position"].includes(sortOption.field)) {
|
|
42
|
+
return [{ [sortOption.field]: sortOption.direction }];
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
45
|
const sorts = [];
|
|
44
46
|
// collection specific sorting
|
|
@@ -84,29 +86,31 @@ const buildSort = (args) => {
|
|
|
84
86
|
}
|
|
85
87
|
// curation specific sorting
|
|
86
88
|
if (curation) {
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
if (curation.id !== "global" || mode === "collection") {
|
|
90
|
+
if (0 < curation.boosting.groupings.length) {
|
|
91
|
+
const groupings = curation.boosting.groupings.sort((a, b) => a.position > b.position ? 1 : -1);
|
|
92
|
+
for (const grouping of groupings) {
|
|
93
|
+
try {
|
|
94
|
+
const query = JSON.parse(grouping.query);
|
|
95
|
+
if (query)
|
|
96
|
+
sorts.push(query);
|
|
97
|
+
}
|
|
98
|
+
catch (_b) {
|
|
99
|
+
console.error(`query could not be parsed for boost grouping`, grouping);
|
|
100
|
+
}
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
if (0 < curation.boosting.sortings.length) {
|
|
104
|
+
const sortings = curation.boosting.sortings.sort((a, b) => a.position > b.position ? 1 : -1);
|
|
105
|
+
for (const sorting of sortings) {
|
|
106
|
+
try {
|
|
107
|
+
const query = JSON.parse(sorting.query);
|
|
108
|
+
if (query)
|
|
109
|
+
sorts.push(query);
|
|
110
|
+
}
|
|
111
|
+
catch (_c) {
|
|
112
|
+
console.error(`query could not be parsed for boost sorting`, sorting);
|
|
113
|
+
}
|
|
110
114
|
}
|
|
111
115
|
}
|
|
112
116
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SensorSort.js","sourceRoot":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B;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\";\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"]}
|
|
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,CAAC,IAAI;gBAClB,QAAQ;gBACR,UAAU;gBACV,gBAAgB,EACd,OAAO,CAAC,IAAI,KAAK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AAC;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\";\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 (mode !== \"instant-search\") {\n if (\n sortOption &&\n ![\"_score\", \"collections.position\"].includes(sortOption.field)\n ) {\n return [{ [sortOption.field]: sortOption.direction }];\n }\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 (curation.id !== \"global\" || mode === \"collection\") {\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(\n `query could not be parsed for boost sorting`,\n sorting\n );\n }\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"]}
|