@usereactify/search 5.6.0-beta.2 → 5.6.1-beta.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
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
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.6.1-beta.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/beta-v5.6.0-beta.2...beta-v5.6.1-beta.0) (2022-10-11)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* add all dependencies to sort and query memo ([b60c9bc](https://bitbucket.org/usereactify/reactify-search-ui/commit/b60c9bc1e22b6f277a0cf2716fa4d0adcdafdbc0))
|
|
11
|
+
* remove collection position sorting when curation exists ([913fac8](https://bitbucket.org/usereactify/reactify-search-ui/commit/913fac865be62d24aa5e625c0fe0887bada5197b))
|
|
12
|
+
|
|
13
|
+
## [5.6.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.5.0...release-v5.6.0) (2022-10-11)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* align queries and sensors for both search and instant search modes ([481c9c6](https://bitbucket.org/usereactify/reactify-search-ui/commit/481c9c62a0c6f3088dd2b0bc2f0fcbb94cbebf9a))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* allow global curation to apply to all search modes ([2de5ab1](https://bitbucket.org/usereactify/reactify-search-ui/commit/2de5ab15d322ac8f98ddb4fdf2fa84c6ca4bc089))
|
|
24
|
+
* skip sort option logic for instant search ([4ef922f](https://bitbucket.org/usereactify/reactify-search-ui/commit/4ef922ffe553c51ee90cd5ae6de2f5292bbf6734))
|
|
25
|
+
|
|
5
26
|
## [5.6.0-beta.2](https://bitbucket.org/usereactify/reactify-search-ui/compare/beta-v5.6.0-beta.1...beta-v5.6.0-beta.2) (2022-10-11)
|
|
6
27
|
|
|
7
28
|
|
package/dist/package.json
CHANGED
|
@@ -27,7 +27,7 @@ const SensorSort = () => {
|
|
|
27
27
|
globalCuration,
|
|
28
28
|
}),
|
|
29
29
|
};
|
|
30
|
-
}, [config, sortOption, curation]);
|
|
30
|
+
}, [options, config, sortOption, curation, globalCuration]);
|
|
31
31
|
return (react_1.default.createElement(ReactiveComponent_1.default, { componentId: "SensorSort", customQuery: () => ({
|
|
32
32
|
sort,
|
|
33
33
|
query,
|
|
@@ -58,10 +58,7 @@ const buildSort = (args) => {
|
|
|
58
58
|
}
|
|
59
59
|
const sorts = [];
|
|
60
60
|
// show pins first
|
|
61
|
-
if (globalCuration && collectionHandle) {
|
|
62
|
-
sorts.push(...mapCollectionPositionSortClause(collectionHandle));
|
|
63
|
-
}
|
|
64
|
-
if ((!globalCuration && curation.collectionHandle) || curation.searchTerm) {
|
|
61
|
+
if (!globalCuration && (curation.collectionHandle || curation.searchTerm)) {
|
|
65
62
|
sorts.push({
|
|
66
63
|
"curations.position": {
|
|
67
64
|
unmapped_type: "long",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SensorSort.js","sourceRoot":"","sources":["../../../../src/components/Sensor/SensorSort.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yHAAiG;AAGjG,uCAKqB;AAGd,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;IACnC,MAAM,cAAc,GAAG,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,MAAK,QAAQ,CAAC;IAEjD,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,iBAAS,GAAE,C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,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 }, [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 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 && collectionHandle) {\n sorts.push(...mapCollectionPositionSortClause(collectionHandle));\n }\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 (\"collection\" === curation.type && sorts.length === 0) {\n sorts.push(\"_doc\");\n }\n\n // finally, for search, sort by score\n if (\"search\" === curation.type) {\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;AAGd,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;IACnC,MAAM,cAAc,GAAG,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,MAAK,QAAQ,CAAC;IAEjD,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,cAAc;gBACd,QAAQ;gBACR,UAAU;gBACV,gBAAgB,EACd,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS;aACvE,CAAC;YACF,KAAK,EAAE,UAAU,CAAC;gBAChB,UAAU;gBACV,QAAQ;g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AO,SAAS,CAAC;KAClB;IAED,OAAO;QACL,IAAI,EAAE;YACJ,QAAQ,EAAE;gBACR;oBACE,MAAM,EAAE;wBACN,IAAI,EAAE,WAAW;wBACjB,KAAK,EAAE;4BACL,IAAI,EAAE;gCACJ,IAAI,EAAE;oCACJ;wCACE,IAAI,EAAE;4CACJ,CAAC,aACC,YAAY,KAAK,QAAQ,CAAC,IAAI;gDAC5B,CAAC,CAAC,kBAAkB;gDACpB,CAAC,CAAC,YACN,UAAU,CAAC,EACT,YAAY,KAAK,QAAQ,CAAC,IAAI;gDAC5B,CAAC,CAAC,QAAQ,CAAC,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 (\"collection\" === curation.type && sorts.length === 0) {\n sorts.push(\"_doc\");\n }\n\n // finally, for search, sort by score\n if (\"search\" === curation.type) {\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"]}
|