@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
|
@@ -23,6 +23,10 @@ export const memorySearchTheBadWay = () => ({ store }) => {
|
|
|
23
23
|
let weight = 0;
|
|
24
24
|
const matchFilters = (filters, matchType) => {
|
|
25
25
|
for (const field of filters) {
|
|
26
|
+
if (!('key' in field && 'value' in field)) {
|
|
27
|
+
console.warn('local search only supports key/value filters');
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
26
30
|
const docValues = coerceArray(resolveField(document, field));
|
|
27
31
|
const coerceValue = getFieldType(field) === 'boolean'
|
|
28
32
|
? (input) => {
|
|
@@ -54,6 +54,7 @@ export const openSearchService = (initializer = {}) => (configProvider) => {
|
|
|
54
54
|
const body = {
|
|
55
55
|
query: { bool: {} },
|
|
56
56
|
track_total_hits: true,
|
|
57
|
+
size: pageSize
|
|
57
58
|
};
|
|
58
59
|
if (options.query) {
|
|
59
60
|
body.query.bool.must = {
|
|
@@ -68,24 +69,39 @@ export const openSearchService = (initializer = {}) => (configProvider) => {
|
|
|
68
69
|
if (must && must.length > 0) {
|
|
69
70
|
body.query.bool.filter = [];
|
|
70
71
|
must.forEach((filter) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
if ('key' in filter && 'value' in filter) {
|
|
73
|
+
const { key } = filter;
|
|
74
|
+
const values = filter.value instanceof Array ? filter.value : [filter.value];
|
|
75
|
+
body.query.bool.filter.push({ terms: { [key]: values } });
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
body.query.bool.filter.push(filter);
|
|
79
|
+
}
|
|
74
80
|
});
|
|
75
81
|
}
|
|
76
82
|
if (must_not && must_not.length > 0) {
|
|
77
83
|
body.query.bool.must_not = [];
|
|
78
84
|
must_not.forEach((filter) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
if ('key' in filter && 'value' in filter) {
|
|
86
|
+
const { key } = filter;
|
|
87
|
+
const values = filter.value instanceof Array ? filter.value : [filter.value];
|
|
88
|
+
values.forEach((value) => body.query.bool.must_not.push({ term: { [key]: value } }));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
body.query.bool.must_not.push(filter);
|
|
92
|
+
}
|
|
82
93
|
});
|
|
83
94
|
}
|
|
84
95
|
if (options.should && options.should.length > 0) {
|
|
85
|
-
body.query.bool.should = options.should.map(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
96
|
+
body.query.bool.should = options.should.map(filter => {
|
|
97
|
+
if ('key' in filter && 'value' in filter) {
|
|
98
|
+
const { key } = filter;
|
|
99
|
+
const values = filter.value instanceof Array ? filter.value : [filter.value];
|
|
100
|
+
return { terms: { [key]: values } };
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
return filter;
|
|
104
|
+
}
|
|
89
105
|
});
|
|
90
106
|
body.query.bool.minimum_should_match = 1;
|
|
91
107
|
}
|
|
@@ -95,7 +111,6 @@ export const openSearchService = (initializer = {}) => (configProvider) => {
|
|
|
95
111
|
}));
|
|
96
112
|
}
|
|
97
113
|
if (options.page) {
|
|
98
|
-
body.size = pageSize;
|
|
99
114
|
body.from = (options.page - 1) * pageSize;
|
|
100
115
|
}
|
|
101
116
|
const response = await (await client()).search({
|