@openstax/ts-utils 1.25.3 → 1.25.5
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/cjs/services/searchProvider/index.d.ts +6 -0
- package/dist/cjs/services/searchProvider/memorySearchTheBadWay.js +4 -0
- package/dist/cjs/services/searchProvider/openSearch.js +26 -11
- package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
- package/dist/esm/services/searchProvider/index.d.ts +6 -0
- package/dist/esm/services/searchProvider/memorySearchTheBadWay.js +4 -0
- package/dist/esm/services/searchProvider/openSearch.js +26 -11
- package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -26,6 +26,10 @@ const memorySearchTheBadWay = () => ({ store }) => {
|
|
|
26
26
|
let weight = 0;
|
|
27
27
|
const matchFilters = (filters, matchType) => {
|
|
28
28
|
for (const field of filters) {
|
|
29
|
+
if (!('key' in field && 'value' in field)) {
|
|
30
|
+
console.warn('local search only supports key/value filters');
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
29
33
|
const docValues = (0, __1.coerceArray)(resolveField(document, field));
|
|
30
34
|
const coerceValue = getFieldType(field) === 'boolean'
|
|
31
35
|
? (input) => {
|
|
@@ -57,6 +57,7 @@ const openSearchService = (initializer = {}) => (configProvider) => {
|
|
|
57
57
|
const body = {
|
|
58
58
|
query: { bool: {} },
|
|
59
59
|
track_total_hits: true,
|
|
60
|
+
size: pageSize
|
|
60
61
|
};
|
|
61
62
|
if (options.query) {
|
|
62
63
|
body.query.bool.must = {
|
|
@@ -71,24 +72,39 @@ const openSearchService = (initializer = {}) => (configProvider) => {
|
|
|
71
72
|
if (must && must.length > 0) {
|
|
72
73
|
body.query.bool.filter = [];
|
|
73
74
|
must.forEach((filter) => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
if ('key' in filter && 'value' in filter) {
|
|
76
|
+
const { key } = filter;
|
|
77
|
+
const values = filter.value instanceof Array ? filter.value : [filter.value];
|
|
78
|
+
body.query.bool.filter.push({ terms: { [key]: values } });
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
body.query.bool.filter.push(filter);
|
|
82
|
+
}
|
|
77
83
|
});
|
|
78
84
|
}
|
|
79
85
|
if (must_not && must_not.length > 0) {
|
|
80
86
|
body.query.bool.must_not = [];
|
|
81
87
|
must_not.forEach((filter) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
if ('key' in filter && 'value' in filter) {
|
|
89
|
+
const { key } = filter;
|
|
90
|
+
const values = filter.value instanceof Array ? filter.value : [filter.value];
|
|
91
|
+
values.forEach((value) => body.query.bool.must_not.push({ term: { [key]: value } }));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
body.query.bool.must_not.push(filter);
|
|
95
|
+
}
|
|
85
96
|
});
|
|
86
97
|
}
|
|
87
98
|
if (options.should && options.should.length > 0) {
|
|
88
|
-
body.query.bool.should = options.should.map(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
body.query.bool.should = options.should.map(filter => {
|
|
100
|
+
if ('key' in filter && 'value' in filter) {
|
|
101
|
+
const { key } = filter;
|
|
102
|
+
const values = filter.value instanceof Array ? filter.value : [filter.value];
|
|
103
|
+
return { terms: { [key]: values } };
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return filter;
|
|
107
|
+
}
|
|
92
108
|
});
|
|
93
109
|
body.query.bool.minimum_should_match = 1;
|
|
94
110
|
}
|
|
@@ -98,7 +114,6 @@ const openSearchService = (initializer = {}) => (configProvider) => {
|
|
|
98
114
|
}));
|
|
99
115
|
}
|
|
100
116
|
if (options.page) {
|
|
101
|
-
body.size = pageSize;
|
|
102
117
|
body.from = (options.page - 1) * pageSize;
|
|
103
118
|
}
|
|
104
119
|
const response = await (await client()).search({
|