@usereactify/search 3.0.0-beta.0 → 3.0.0-beta.1
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/provider.js
CHANGED
|
@@ -14,10 +14,10 @@ const defaultCredentials = {
|
|
|
14
14
|
endpoint: "https://api.search.reactify.app",
|
|
15
15
|
};
|
|
16
16
|
const Provider = (props) => {
|
|
17
|
-
var _a;
|
|
17
|
+
var _a, _b;
|
|
18
18
|
const { index, config, children, collection, instantSearch, filterStackId, noReactiveBase, enableCallouts, additionalComponentIds, } = props;
|
|
19
19
|
const credentials = (_a = props.credentials) !== null && _a !== void 0 ? _a : defaultCredentials;
|
|
20
|
-
const theme = props.theme
|
|
20
|
+
const theme = (_b = props.theme) !== null && _b !== void 0 ? _b : {
|
|
21
21
|
typography: {
|
|
22
22
|
fontFamily: "inherit",
|
|
23
23
|
fontSize: "inherit",
|
|
@@ -2,8 +2,9 @@ import React from "react";
|
|
|
2
2
|
import type { ElasticProduct } from "../types/elastic";
|
|
3
3
|
import { useProductPrice } from "../hooks";
|
|
4
4
|
declare type Props = {
|
|
5
|
-
product: ElasticProduct;
|
|
6
5
|
pagePosition: number;
|
|
6
|
+
product: ElasticProduct;
|
|
7
|
+
document: ElasticProduct;
|
|
7
8
|
render?: (props: Omit<Props, "render"> & ReturnType<typeof useProductPrice>) => JSX.Element;
|
|
8
9
|
};
|
|
9
10
|
export declare const ResultCard: React.FC<Props>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ElasticCallout } from "../types/elastic";
|
|
3
3
|
declare type Props = {
|
|
4
|
-
callout: ElasticCallout;
|
|
5
4
|
pagePosition: number;
|
|
5
|
+
document: ElasticCallout;
|
|
6
|
+
callout: ElasticCallout["callout"];
|
|
6
7
|
render?: (props: Omit<Props, "render">) => JSX.Element;
|
|
7
8
|
};
|
|
8
9
|
export declare const ResultCardCallout: React.FC<Props>;
|
|
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.ResultCardCallout = void 0;
|
|
18
18
|
const react_1 = __importDefault(require("react"));
|
|
19
19
|
const ResultCardCallout = (props) => {
|
|
20
|
-
const { callout
|
|
20
|
+
const { callout } = props;
|
|
21
21
|
const styleProp = react_1.default.useMemo(() => {
|
|
22
22
|
var _a, _b;
|
|
23
23
|
return ({
|
|
@@ -31,7 +31,7 @@ const ResultCardCallout = (props) => {
|
|
|
31
31
|
exports.ResultCardCallout = ResultCardCallout;
|
|
32
32
|
const ResultCardCalloutInner = (_a) => {
|
|
33
33
|
var { render } = _a, props = __rest(_a, ["render"]);
|
|
34
|
-
const { callout
|
|
34
|
+
const { callout } = props;
|
|
35
35
|
if (render)
|
|
36
36
|
return render(props);
|
|
37
37
|
return react_1.default.createElement("p", null, callout.title);
|
|
@@ -60,10 +60,10 @@ const ResultListInner = (props) => {
|
|
|
60
60
|
renderBefore && renderBefore(reactivesearchResultProps),
|
|
61
61
|
react_1.default.createElement("section", { className: listClassName, style: styleProp }, reactivesearchResultProps.data.map((result, key) => {
|
|
62
62
|
if (elastic_1.ElasticDocumentType.Product === result.type) {
|
|
63
|
-
return (react_1.default.createElement(ResultCard_1.ResultCard, { key: result._id, product: result, pagePosition: key + 1, render: renderResultCard }));
|
|
63
|
+
return (react_1.default.createElement(ResultCard_1.ResultCard, { key: result._id, product: result, document: result, pagePosition: key + 1, render: renderResultCard }));
|
|
64
64
|
}
|
|
65
65
|
if (!!enableCallouts && elastic_1.ElasticDocumentType.Callout === result.type) {
|
|
66
|
-
return (react_1.default.createElement(ResultCardCallout_1.ResultCardCallout, { key: result._id,
|
|
66
|
+
return (react_1.default.createElement(ResultCardCallout_1.ResultCardCallout, { key: result._id, document: result, pagePosition: key + 1, callout: result.callout, render: renderResultCardCallout }));
|
|
67
67
|
}
|
|
68
68
|
return null;
|
|
69
69
|
})),
|
|
@@ -11,6 +11,7 @@ const debug = require("debug")("reactify-search:SensorSort");
|
|
|
11
11
|
const SensorSort = () => {
|
|
12
12
|
const config = (0, hooks_1.useConfig)();
|
|
13
13
|
const curation = (0, hooks_1.useCuration)();
|
|
14
|
+
const collection = (0, hooks_1.useCollection)();
|
|
14
15
|
const { sortOption } = (0, hooks_1.useSort)();
|
|
15
16
|
const searchQuery = react_1.default.useMemo(() => {
|
|
16
17
|
if (typeof window === "undefined")
|
|
@@ -20,7 +21,7 @@ const SensorSort = () => {
|
|
|
20
21
|
}, []);
|
|
21
22
|
const { sort, query } = react_1.default.useMemo(() => {
|
|
22
23
|
return {
|
|
23
|
-
sort: buildSort(config, curation, sortOption),
|
|
24
|
+
sort: buildSort({ config, curation, sortOption, collection }),
|
|
24
25
|
query: buildQuery(curation),
|
|
25
26
|
};
|
|
26
27
|
}, [config, sortOption, curation]);
|
|
@@ -35,25 +36,30 @@ const SensorSort = () => {
|
|
|
35
36
|
}) }));
|
|
36
37
|
};
|
|
37
38
|
exports.SensorSort = SensorSort;
|
|
38
|
-
const buildSort = (
|
|
39
|
+
const buildSort = (args) => {
|
|
39
40
|
var _a;
|
|
41
|
+
const { config, curation, sortOption, collection } = args;
|
|
40
42
|
debug("buildSortQuery.start", {
|
|
41
43
|
config,
|
|
42
44
|
curation,
|
|
43
|
-
|
|
45
|
+
sortOption,
|
|
44
46
|
});
|
|
45
|
-
// return default
|
|
46
|
-
if (!
|
|
47
|
-
return
|
|
47
|
+
// return default sort option if unset
|
|
48
|
+
if (!sortOption) {
|
|
49
|
+
return collection
|
|
50
|
+
? mapCollectionPositionSortClause(collection)
|
|
51
|
+
: ["_score"];
|
|
48
52
|
}
|
|
49
53
|
// curation positions are only applied for the default `collections.position` or `_score` sort
|
|
50
54
|
// if the sort is something else, apply a normal sort which applies what the user has requested
|
|
51
|
-
if (!["
|
|
52
|
-
return [{ [
|
|
55
|
+
if (!["_score", "collections.position"].includes(sortOption.field)) {
|
|
56
|
+
return [{ [sortOption.field]: sortOption.direction }];
|
|
53
57
|
}
|
|
54
|
-
// no matching curation, return default sort
|
|
58
|
+
// no matching curation, return default sort clause
|
|
55
59
|
if (!curation) {
|
|
56
|
-
return
|
|
60
|
+
return collection
|
|
61
|
+
? mapCollectionPositionSortClause(collection)
|
|
62
|
+
: ["_score"];
|
|
57
63
|
}
|
|
58
64
|
const sorts = [];
|
|
59
65
|
// show pins first
|
|
@@ -106,8 +112,31 @@ const buildSort = (config, curation, sortState) => {
|
|
|
106
112
|
sorts.push("_doc");
|
|
107
113
|
else
|
|
108
114
|
sorts.push("_score");
|
|
115
|
+
// @todo ideally, once pins are extinguished and there are no boost rules, the rest of the
|
|
116
|
+
// result should be ordered by the shopify collection position rather than the index order,
|
|
117
|
+
// but this will need some proper testing to ensure it does not break curations
|
|
109
118
|
return sorts;
|
|
110
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* Return a sort clause which sorts by position within the given collection.
|
|
122
|
+
*/
|
|
123
|
+
function mapCollectionPositionSortClause(collection) {
|
|
124
|
+
return [
|
|
125
|
+
{
|
|
126
|
+
"collections.position": {
|
|
127
|
+
order: "asc",
|
|
128
|
+
nested: {
|
|
129
|
+
path: "collections",
|
|
130
|
+
filter: {
|
|
131
|
+
term: {
|
|
132
|
+
"collections.handle.keyword": collection.handle,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
}
|
|
111
140
|
const buildQuery = (curation) => {
|
|
112
141
|
var _a;
|
|
113
142
|
if (!curation)
|