@webiny/api-headless-cms-ddb-es 6.3.0 → 6.4.0-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/configurations.js +27 -35
- package/configurations.js.map +1 -1
- package/definitions/entry.js +7 -9
- package/definitions/entry.js.map +1 -1
- package/definitions/group.js +7 -9
- package/definitions/group.js.map +1 -1
- package/definitions/model.js +7 -9
- package/definitions/model.js.map +1 -1
- package/definitions/types.d.ts +1 -0
- package/definitions/types.js +0 -3
- package/elasticsearch/createElasticsearchIndex.js +50 -67
- package/elasticsearch/createElasticsearchIndex.js.map +1 -1
- package/elasticsearch/deleteElasticsearchIndex.js +18 -26
- package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
- package/exports/api/cms/opensearch.js +2 -4
- package/feature.js +144 -153
- package/feature.js.map +1 -1
- package/features/CmsEntryOpenSearchBodyModifier/abstractions.js +2 -1
- package/features/CmsEntryOpenSearchBodyModifier/abstractions.js.map +1 -1
- package/features/CmsEntryOpenSearchBodyModifier/index.js +0 -2
- package/features/CmsEntryOpenSearchFieldIndex/CmsEntryOpenSearchFieldIndexRegistry.js +28 -27
- package/features/CmsEntryOpenSearchFieldIndex/CmsEntryOpenSearchFieldIndexRegistry.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndex.js +2 -1
- package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndexRegistry.js +2 -1
- package/features/CmsEntryOpenSearchFieldIndex/abstractions/CmsEntryOpenSearchFieldIndexRegistry.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/constants.js +2 -1
- package/features/CmsEntryOpenSearchFieldIndex/constants.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/feature.js +13 -12
- package/features/CmsEntryOpenSearchFieldIndex/feature.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js +48 -65
- package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/DefaultFieldIndex.js +20 -30
- package/features/CmsEntryOpenSearchFieldIndex/fields/DefaultFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/JsonFieldIndex.js +15 -16
- package/features/CmsEntryOpenSearchFieldIndex/fields/JsonFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/LongTextFieldIndex.js +15 -18
- package/features/CmsEntryOpenSearchFieldIndex/fields/LongTextFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/NumberFieldIndex.js +24 -29
- package/features/CmsEntryOpenSearchFieldIndex/fields/NumberFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js +99 -144
- package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/RichTextFieldIndex.js +15 -16
- package/features/CmsEntryOpenSearchFieldIndex/fields/RichTextFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/index.js +0 -2
- package/features/CmsEntryOpenSearchFilter/CmsEntryOpenSearchFilterRegistry.js +26 -28
- package/features/CmsEntryOpenSearchFilter/CmsEntryOpenSearchFilterRegistry.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilter.js +2 -1
- package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilter.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilterRegistry.js +2 -1
- package/features/CmsEntryOpenSearchFilter/abstractions/CmsEntryOpenSearchFilterRegistry.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/constants.js +2 -1
- package/features/CmsEntryOpenSearchFilter/constants.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/feature.js +9 -8
- package/features/CmsEntryOpenSearchFilter/feature.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/fields/DefaultFilter.js +18 -15
- package/features/CmsEntryOpenSearchFilter/fields/DefaultFilter.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/fields/ObjectFilter.js +35 -53
- package/features/CmsEntryOpenSearchFilter/fields/ObjectFilter.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/fields/RefFilter.js +27 -40
- package/features/CmsEntryOpenSearchFilter/fields/RefFilter.js.map +1 -1
- package/features/CmsEntryOpenSearchFilter/index.js +0 -2
- package/features/CmsEntryOpenSearchFullTextSearch/abstractions.js +2 -1
- package/features/CmsEntryOpenSearchFullTextSearch/abstractions.js.map +1 -1
- package/features/CmsEntryOpenSearchFullTextSearch/index.js +0 -2
- package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js +10 -9
- package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchIndex/abstractions.js +2 -1
- package/features/CmsEntryOpenSearchIndex/abstractions.js.map +1 -1
- package/features/CmsEntryOpenSearchIndex/feature.js +6 -5
- package/features/CmsEntryOpenSearchIndex/feature.js.map +1 -1
- package/features/CmsEntryOpenSearchIndex/index.js +0 -2
- package/features/CmsEntryOpenSearchQueryModifier/abstractions.js +2 -1
- package/features/CmsEntryOpenSearchQueryModifier/abstractions.js.map +1 -1
- package/features/CmsEntryOpenSearchQueryModifier/index.js +0 -2
- package/features/CmsEntryOpenSearchSortModifier/abstractions.js +2 -1
- package/features/CmsEntryOpenSearchSortModifier/abstractions.js.map +1 -1
- package/features/CmsEntryOpenSearchSortModifier/index.js +0 -2
- package/features/CmsEntryOpenSearchValueSearch/CmsEntryOpenSearchValueSearchRegistry.js +24 -20
- package/features/CmsEntryOpenSearchValueSearch/CmsEntryOpenSearchValueSearchRegistry.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearch.js +2 -1
- package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearch.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearchRegistry.js +2 -1
- package/features/CmsEntryOpenSearchValueSearch/abstractions/CmsEntryOpenSearchValueSearchRegistry.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/feature.js +9 -8
- package/features/CmsEntryOpenSearchValueSearch/feature.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/fields/RefSearch.js +14 -16
- package/features/CmsEntryOpenSearchValueSearch/fields/RefSearch.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js +31 -42
- package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/fields/TimeSearch.js +15 -17
- package/features/CmsEntryOpenSearchValueSearch/fields/TimeSearch.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/index.js +0 -2
- package/features/CmsEntryOpenSearchValuesModifier/abstractions.js +2 -1
- package/features/CmsEntryOpenSearchValuesModifier/abstractions.js.map +1 -1
- package/features/CmsEntryOpenSearchValuesModifier/index.js +0 -2
- package/helpers/entryIndexHelpers.js +71 -123
- package/helpers/entryIndexHelpers.js.map +1 -1
- package/helpers/fieldIdentifier.js +18 -30
- package/helpers/fieldIdentifier.js.map +1 -1
- package/helpers/index.js +0 -2
- package/index.js +0 -2
- package/operations/entry/dataLoader/DataLoaderCache.js +22 -26
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
- package/operations/entry/dataLoader/constants.js +2 -1
- package/operations/entry/dataLoader/constants.js.map +1 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js +6 -15
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
- package/operations/entry/dataLoader/getAllEntryRevisions.js +18 -29
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +27 -37
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +27 -37
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.js +32 -46
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
- package/operations/entry/dataLoader/index.js +8 -9
- package/operations/entry/dataLoader/index.js.map +1 -1
- package/operations/entry/dataLoader/types.js +0 -3
- package/operations/entry/dataLoaders.js +81 -99
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +6 -24
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -1
- package/operations/entry/elasticsearch/body.js +74 -125
- package/operations/entry/elasticsearch/body.js.map +1 -1
- package/operations/entry/elasticsearch/fields/createSystemField.js +6 -7
- package/operations/entry/elasticsearch/fields/createSystemField.js.map +1 -1
- package/operations/entry/elasticsearch/fields/live.js +45 -40
- package/operations/entry/elasticsearch/fields/live.js.map +1 -1
- package/operations/entry/elasticsearch/fields/location.js +45 -40
- package/operations/entry/elasticsearch/fields/location.js.map +1 -1
- package/operations/entry/elasticsearch/fields/state.js +99 -88
- package/operations/entry/elasticsearch/fields/state.js.map +1 -1
- package/operations/entry/elasticsearch/fields.js +193 -217
- package/operations/entry/elasticsearch/fields.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/applyFiltering.js +32 -45
- package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/exec.js +85 -114
- package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/index.js +0 -2
- package/operations/entry/elasticsearch/filtering/path.js +24 -33
- package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/populated.js +8 -14
- package/operations/entry/elasticsearch/filtering/populated.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/values.js +11 -12
- package/operations/entry/elasticsearch/filtering/values.js.map +1 -1
- package/operations/entry/elasticsearch/fullTextSearch.js +43 -80
- package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
- package/operations/entry/elasticsearch/fullTextSearchFields.js +7 -17
- package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -1
- package/operations/entry/elasticsearch/initialQuery.js +37 -80
- package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
- package/operations/entry/elasticsearch/keyword.js +13 -27
- package/operations/entry/elasticsearch/keyword.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/operator.js +9 -20
- package/operations/entry/elasticsearch/plugins/operator.js.map +1 -1
- package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js +6 -4
- package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js.map +1 -1
- package/operations/entry/elasticsearch/sort.js +69 -92
- package/operations/entry/elasticsearch/sort.js.map +1 -1
- package/operations/entry/elasticsearch/transformValueForSearch.js +9 -14
- package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -1
- package/operations/entry/elasticsearch/types.js +0 -3
- package/operations/entry/index.js +1322 -1709
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.js +43 -63
- package/operations/entry/keys.js.map +1 -1
- package/operations/entry/recordType.js +4 -9
- package/operations/entry/recordType.js.map +1 -1
- package/operations/entry/transformations/convertEntryKeys.js +21 -26
- package/operations/entry/transformations/convertEntryKeys.js.map +1 -1
- package/operations/entry/transformations/index.js +85 -114
- package/operations/entry/transformations/index.js.map +1 -1
- package/operations/entry/transformations/modifyEntryValues.d.ts +1 -1
- package/operations/entry/transformations/modifyEntryValues.js +12 -17
- package/operations/entry/transformations/modifyEntryValues.js.map +1 -1
- package/operations/entry/transformations/transformEntryKeys.js +13 -16
- package/operations/entry/transformations/transformEntryKeys.js.map +1 -1
- package/operations/entry/transformations/transformEntryToIndex.js +17 -22
- package/operations/entry/transformations/transformEntryToIndex.js.map +1 -1
- package/operations/group/index.js +113 -134
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.js +128 -156
- package/operations/model/index.js.map +1 -1
- package/package.json +23 -23
- package/tasks/createIndexTaskPlugin.js +35 -38
- package/tasks/createIndexTaskPlugin.js.map +1 -1
- package/types.js +7 -13
- package/types.js.map +1 -1
- package/values/NoValueContainer.js +8 -10
- package/values/NoValueContainer.js.map +1 -1
- package/definitions/types.js.map +0 -1
- package/exports/api/cms/opensearch.js.map +0 -1
- package/features/CmsEntryOpenSearchBodyModifier/index.js.map +0 -1
- package/features/CmsEntryOpenSearchFieldIndex/index.js.map +0 -1
- package/features/CmsEntryOpenSearchFilter/index.js.map +0 -1
- package/features/CmsEntryOpenSearchFullTextSearch/index.js.map +0 -1
- package/features/CmsEntryOpenSearchIndex/index.js.map +0 -1
- package/features/CmsEntryOpenSearchQueryModifier/index.js.map +0 -1
- package/features/CmsEntryOpenSearchSortModifier/index.js.map +0 -1
- package/features/CmsEntryOpenSearchValueSearch/index.js.map +0 -1
- package/features/CmsEntryOpenSearchValuesModifier/index.js.map +0 -1
- package/helpers/index.js.map +0 -1
- package/index.js.map +0 -1
- package/operations/entry/dataLoader/types.js.map +0 -1
- package/operations/entry/elasticsearch/filtering/index.js.map +0 -1
- package/operations/entry/elasticsearch/types.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import error from "@webiny/error";
|
|
2
2
|
import { createOperatorPluginList } from "../plugins/operator.js";
|
|
3
3
|
import { createBaseQuery } from "../initialQuery.js";
|
|
4
4
|
import { parseWhereKey } from "@webiny/api-opensearch";
|
|
@@ -6,120 +6,91 @@ import { getWhereValues } from "./values.js";
|
|
|
6
6
|
import { getPopulated } from "./populated.js";
|
|
7
7
|
import { createApplyFiltering } from "./applyFiltering.js";
|
|
8
8
|
import { assignMinimumShouldMatchToQuery } from "../assignMinimumShouldMatchToQuery.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
9
|
+
const createExecFiltering = (params)=>{
|
|
10
|
+
const { fields, plugins, model, valueSearchRegistry, filterRegistry } = params;
|
|
11
|
+
const operatorPlugins = createOperatorPluginList({
|
|
12
|
+
plugins
|
|
13
|
+
});
|
|
14
|
+
const applyFiltering = createApplyFiltering({
|
|
15
|
+
operatorPlugins,
|
|
16
|
+
valueSearchRegistry
|
|
17
|
+
});
|
|
18
|
+
const getFilter = (type)=>filterRegistry.get(type);
|
|
19
|
+
const execFiltering = (params)=>{
|
|
20
|
+
const { where: initialWhere, query, isValues = false } = params;
|
|
21
|
+
const keys = Object.keys(initialWhere);
|
|
22
|
+
if (0 === keys.length) return;
|
|
23
|
+
const where = structuredClone(initialWhere);
|
|
24
|
+
for(const key in where){
|
|
25
|
+
const value = where[key];
|
|
26
|
+
if (void 0 === value) continue;
|
|
27
|
+
if ("AND" === key) {
|
|
28
|
+
const childWhereList = getWhereValues(value, "AND");
|
|
29
|
+
const childQuery = createBaseQuery();
|
|
30
|
+
for (const childWhere of childWhereList)execFiltering({
|
|
31
|
+
query: childQuery,
|
|
32
|
+
where: childWhere,
|
|
33
|
+
isValues
|
|
34
|
+
});
|
|
35
|
+
const childQueryBool = getPopulated(childQuery);
|
|
36
|
+
if (0 === Object.keys(childQueryBool).length) continue;
|
|
37
|
+
query.filter.push({
|
|
38
|
+
bool: childQueryBool
|
|
39
|
+
});
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if ("OR" === key) {
|
|
43
|
+
const childWhereList = getWhereValues(value, "OR");
|
|
44
|
+
const should = [];
|
|
45
|
+
for (const childWhere of childWhereList){
|
|
46
|
+
const childQuery = createBaseQuery();
|
|
47
|
+
execFiltering({
|
|
48
|
+
query: childQuery,
|
|
49
|
+
where: childWhere,
|
|
50
|
+
isValues
|
|
51
|
+
});
|
|
52
|
+
const childQueryBool = getPopulated(childQuery);
|
|
53
|
+
if (0 !== Object.keys(childQueryBool).length) should.push({
|
|
54
|
+
bool: childQueryBool
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (0 === should.length) continue;
|
|
58
|
+
query.should.push(...should);
|
|
59
|
+
assignMinimumShouldMatchToQuery({
|
|
60
|
+
query
|
|
61
|
+
});
|
|
62
|
+
continue;
|
|
63
|
+
} else if ("values" === key) {
|
|
64
|
+
execFiltering({
|
|
65
|
+
query,
|
|
66
|
+
where: where[key],
|
|
67
|
+
isValues: true
|
|
68
|
+
});
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const { field: whereFieldId, operator } = parseWhereKey(key);
|
|
72
|
+
let fieldId = isValues ? `values.${whereFieldId}` : whereFieldId;
|
|
73
|
+
const cmsModelField = model.fields.find((f)=>f.fieldId === fieldId);
|
|
74
|
+
if (cmsModelField || fields[fieldId]) {
|
|
75
|
+
if (cmsModelField) fieldId = cmsModelField.fieldId;
|
|
76
|
+
} else throw new error(`There is no CMS Model Field "${fieldId}".`);
|
|
77
|
+
const field = fields[fieldId];
|
|
78
|
+
if (!field) throw new error(`There is no field "${fieldId}".`, "EXEC_FILTERING_ERROR");
|
|
79
|
+
const filter = getFilter(field.type);
|
|
80
|
+
filter.exec({
|
|
81
|
+
applyFiltering,
|
|
82
|
+
getFilter,
|
|
83
|
+
key,
|
|
84
|
+
value,
|
|
85
|
+
operator,
|
|
86
|
+
field,
|
|
87
|
+
fields,
|
|
88
|
+
query
|
|
89
|
+
});
|
|
51
90
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
query.filter.push({
|
|
57
|
-
bool: childQueryBool
|
|
58
|
-
});
|
|
59
|
-
continue;
|
|
60
|
-
} else if (key === "OR") {
|
|
61
|
-
const childWhereList = getWhereValues(value, "OR");
|
|
62
|
-
const should = [];
|
|
63
|
-
for (const childWhere of childWhereList) {
|
|
64
|
-
const childQuery = createBaseQuery();
|
|
65
|
-
execFiltering({
|
|
66
|
-
query: childQuery,
|
|
67
|
-
where: childWhere,
|
|
68
|
-
isValues
|
|
69
|
-
});
|
|
70
|
-
const childQueryBool = getPopulated(childQuery);
|
|
71
|
-
if (Object.keys(childQueryBool).length === 0) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
should.push({
|
|
75
|
-
bool: childQueryBool
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
if (should.length === 0) {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
query.should.push(...should);
|
|
82
|
-
assignMinimumShouldMatchToQuery({
|
|
83
|
-
query
|
|
84
|
-
});
|
|
85
|
-
continue;
|
|
86
|
-
} else if (key === "values") {
|
|
87
|
-
execFiltering({
|
|
88
|
-
query,
|
|
89
|
-
where: where[key],
|
|
90
|
-
isValues: true
|
|
91
|
-
});
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
const {
|
|
95
|
-
field: whereFieldId,
|
|
96
|
-
operator
|
|
97
|
-
} = parseWhereKey(key);
|
|
98
|
-
let fieldId = isValues ? `values.${whereFieldId}` : whereFieldId;
|
|
99
|
-
const cmsModelField = model.fields.find(f => f.fieldId === fieldId);
|
|
100
|
-
if (!cmsModelField && !fields[fieldId]) {
|
|
101
|
-
throw new WebinyError(`There is no CMS Model Field "${fieldId}".`);
|
|
102
|
-
} else if (cmsModelField) {
|
|
103
|
-
fieldId = cmsModelField.fieldId;
|
|
104
|
-
}
|
|
105
|
-
const field = fields[fieldId];
|
|
106
|
-
if (!field) {
|
|
107
|
-
throw new WebinyError(`There is no field "${fieldId}".`, "EXEC_FILTERING_ERROR");
|
|
108
|
-
}
|
|
109
|
-
const filter = getFilter(field.type);
|
|
110
|
-
filter.exec({
|
|
111
|
-
applyFiltering,
|
|
112
|
-
getFilter,
|
|
113
|
-
key,
|
|
114
|
-
value,
|
|
115
|
-
operator,
|
|
116
|
-
field,
|
|
117
|
-
fields,
|
|
118
|
-
query
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
return execFiltering;
|
|
91
|
+
};
|
|
92
|
+
return execFiltering;
|
|
123
93
|
};
|
|
94
|
+
export { createExecFiltering };
|
|
124
95
|
|
|
125
96
|
//# sourceMappingURL=exec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/filtering/exec.js","sources":["../../../../../src/operations/entry/elasticsearch/filtering/exec.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { ModelFields } from \"~/operations/entry/elasticsearch/types.js\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type {\n OpenSearchBoolQueryConfig,\n QueryDslQueryContainer as Query\n} from \"@webiny/api-opensearch/types.js\";\nimport { createOperatorPluginList } from \"~/operations/entry/elasticsearch/plugins/operator.js\";\nimport { createBaseQuery } from \"~/operations/entry/elasticsearch/initialQuery.js\";\nimport { parseWhereKey } from \"@webiny/api-opensearch\";\nimport { getWhereValues } from \"./values.js\";\nimport { getPopulated } from \"./populated.js\";\nimport { createApplyFiltering } from \"./applyFiltering.js\";\nimport { assignMinimumShouldMatchToQuery } from \"~/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js\";\nimport type { CmsEntryOpenSearchValueSearchRegistry } from \"~/features/CmsEntryOpenSearchValueSearch/index.js\";\nimport type { CmsEntryOpenSearchFilterRegistry } from \"~/features/CmsEntryOpenSearchFilter/index.js\";\n\nexport interface CreateExecParams {\n model: CmsModel;\n fields: ModelFields;\n plugins: PluginsContainer;\n valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface;\n filterRegistry: CmsEntryOpenSearchFilterRegistry.Interface;\n}\nexport interface IExecParams {\n where: CmsEntryListWhere;\n query: OpenSearchBoolQueryConfig;\n isValues?: boolean;\n}\nexport interface CreateExecFilteringResponse {\n (params: IExecParams): void;\n}\nexport const createExecFiltering = (params: CreateExecParams): CreateExecFilteringResponse => {\n const { fields, plugins, model, valueSearchRegistry, filterRegistry } = params;\n\n const operatorPlugins = createOperatorPluginList({\n plugins\n });\n\n const applyFiltering = createApplyFiltering({\n operatorPlugins,\n valueSearchRegistry\n });\n\n const getFilter = (type: string) => {\n return filterRegistry.get(type);\n };\n\n const execFiltering = (params: IExecParams) => {\n const { where: initialWhere, query, isValues = false } = params;\n const keys = Object.keys(initialWhere);\n if (keys.length === 0) {\n return;\n }\n const where = structuredClone(initialWhere);\n\n for (const key in where) {\n const value = where[key as keyof typeof where];\n if (value === undefined) {\n continue;\n } else if (key === \"AND\") {\n const childWhereList = getWhereValues(value, \"AND\");\n const childQuery = createBaseQuery();\n for (const childWhere of childWhereList) {\n execFiltering({ query: childQuery, where: childWhere, isValues });\n }\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n query.filter.push({ bool: childQueryBool });\n continue;\n } else if (key === \"OR\") {\n const childWhereList = getWhereValues(value, \"OR\");\n const should: Query[] = [];\n for (const childWhere of childWhereList) {\n const childQuery = createBaseQuery();\n execFiltering({ query: childQuery, where: childWhere, isValues });\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n should.push({ bool: childQueryBool });\n }\n if (should.length === 0) {\n continue;\n }\n query.should.push(...should);\n assignMinimumShouldMatchToQuery({ query });\n continue;\n } else if (key === \"values\") {\n execFiltering({\n query,\n where: where[key] as CmsEntryListWhere,\n isValues: true\n });\n continue;\n }\n const { field: whereFieldId, operator } = parseWhereKey(key);\n let fieldId: string = isValues ? `values.${whereFieldId}` : whereFieldId;\n\n const cmsModelField = model.fields.find(f => f.fieldId === fieldId);\n if (!cmsModelField && !fields[fieldId]) {\n throw new WebinyError(`There is no CMS Model Field \"${fieldId}\".`);\n } else if (cmsModelField) {\n fieldId = cmsModelField.fieldId;\n }\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(`There is no field \"${fieldId}\".`, \"EXEC_FILTERING_ERROR\");\n }\n const filter = getFilter(field.type);\n\n filter.exec({\n applyFiltering,\n getFilter,\n key,\n value,\n operator,\n field,\n fields,\n query\n });\n }\n };\n\n return execFiltering;\n};\n"],"names":["createExecFiltering","params","fields","plugins","model","valueSearchRegistry","filterRegistry","operatorPlugins","createOperatorPluginList","applyFiltering","createApplyFiltering","getFilter","type","execFiltering","initialWhere","query","isValues","keys","Object","where","structuredClone","key","value","undefined","childWhereList","getWhereValues","childQuery","createBaseQuery","childWhere","childQueryBool","getPopulated","should","assignMinimumShouldMatchToQuery","whereFieldId","operator","parseWhereKey","fieldId","cmsModelField","f","WebinyError","field","filter"],"mappings":";;;;;;;;AAiCO,MAAMA,sBAAsB,CAACC;IAChC,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAEC,KAAK,EAAEC,mBAAmB,EAAEC,cAAc,EAAE,GAAGL;IAExE,MAAMM,kBAAkBC,yBAAyB;QAC7CL;IACJ;IAEA,MAAMM,iBAAiBC,qBAAqB;QACxCH;QACAF;IACJ;IAEA,MAAMM,YAAY,CAACC,OACRN,eAAe,GAAG,CAACM;IAG9B,MAAMC,gBAAgB,CAACZ;QACnB,MAAM,EAAE,OAAOa,YAAY,EAAEC,KAAK,EAAEC,WAAW,KAAK,EAAE,GAAGf;QACzD,MAAMgB,OAAOC,OAAO,IAAI,CAACJ;QACzB,IAAIG,AAAgB,MAAhBA,KAAK,MAAM,EACX;QAEJ,MAAME,QAAQC,gBAAgBN;QAE9B,IAAK,MAAMO,OAAOF,MAAO;YACrB,MAAMG,QAAQH,KAAK,CAACE,IAA0B;YAC9C,IAAIC,AAAUC,WAAVD,OACA;YACG,IAAID,AAAQ,UAARA,KAAe;gBACtB,MAAMG,iBAAiBC,eAAeH,OAAO;gBAC7C,MAAMI,aAAaC;gBACnB,KAAK,MAAMC,cAAcJ,eACrBX,cAAc;oBAAE,OAAOa;oBAAY,OAAOE;oBAAYZ;gBAAS;gBAEnE,MAAMa,iBAAiBC,aAAaJ;gBACpC,IAAIR,AAAuC,MAAvCA,OAAO,IAAI,CAACW,gBAAgB,MAAM,EAClC;gBAEJd,MAAM,MAAM,CAAC,IAAI,CAAC;oBAAE,MAAMc;gBAAe;gBACzC;YACJ;YAAO,IAAIR,AAAQ,SAARA,KAAc;gBACrB,MAAMG,iBAAiBC,eAAeH,OAAO;gBAC7C,MAAMS,SAAkB,EAAE;gBAC1B,KAAK,MAAMH,cAAcJ,eAAgB;oBACrC,MAAME,aAAaC;oBACnBd,cAAc;wBAAE,OAAOa;wBAAY,OAAOE;wBAAYZ;oBAAS;oBAC/D,MAAMa,iBAAiBC,aAAaJ;oBACpC,IAAIR,AAAuC,MAAvCA,OAAO,IAAI,CAACW,gBAAgB,MAAM,EAGtCE,OAAO,IAAI,CAAC;wBAAE,MAAMF;oBAAe;gBACvC;gBACA,IAAIE,AAAkB,MAAlBA,OAAO,MAAM,EACb;gBAEJhB,MAAM,MAAM,CAAC,IAAI,IAAIgB;gBACrBC,gCAAgC;oBAAEjB;gBAAM;gBACxC;YACJ,OAAO,IAAIM,AAAQ,aAARA,KAAkB;gBACzBR,cAAc;oBACVE;oBACA,OAAOI,KAAK,CAACE,IAAI;oBACjB,UAAU;gBACd;gBACA;YACJ;YACA,MAAM,EAAE,OAAOY,YAAY,EAAEC,QAAQ,EAAE,GAAGC,cAAcd;YACxD,IAAIe,UAAkBpB,WAAW,CAAC,OAAO,EAAEiB,cAAc,GAAGA;YAE5D,MAAMI,gBAAgBjC,MAAM,MAAM,CAAC,IAAI,CAACkC,CAAAA,IAAKA,EAAE,OAAO,KAAKF;YAC3D,IAAI,AAACC,iBAAkBnC,MAAM,CAACkC,QAAQ,EAE/B;gBAAA,IAAIC,eACPD,UAAUC,cAAc,OAAO;YACnC,OAHI,MAAM,IAAIE,MAAY,CAAC,6BAA6B,EAAEH,QAAQ,EAAE,CAAC;YAKrE,MAAMI,QAAQtC,MAAM,CAACkC,QAAQ;YAC7B,IAAI,CAACI,OACD,MAAM,IAAID,MAAY,CAAC,mBAAmB,EAAEH,QAAQ,EAAE,CAAC,EAAE;YAE7D,MAAMK,SAAS9B,UAAU6B,MAAM,IAAI;YAEnCC,OAAO,IAAI,CAAC;gBACRhC;gBACAE;gBACAU;gBACAC;gBACAY;gBACAM;gBACAtC;gBACAa;YACJ;QACJ;IACJ;IAEA,OAAOF;AACX"}
|
|
@@ -1,36 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (field.path) {
|
|
25
|
-
fieldPath = typeof field.path === "function" ? field.path(value) : field.path;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const result = field.parents.map(p => p.storageId).concat([fieldPath]);
|
|
29
|
-
return {
|
|
30
|
-
basePath: result.join("."),
|
|
31
|
-
path: result.concat(keyword ? ["keyword"] : []).join(".")
|
|
1
|
+
const createFieldPathFactory = ({ valueSearchRegistry })=>(params)=>{
|
|
2
|
+
const { field, key, value, keyword, originalValue } = params;
|
|
3
|
+
const search = valueSearchRegistry.get(field.type);
|
|
4
|
+
let fieldPath = null;
|
|
5
|
+
if (search) fieldPath = search.createPath({
|
|
6
|
+
field: field.field,
|
|
7
|
+
value,
|
|
8
|
+
key,
|
|
9
|
+
originalValue
|
|
10
|
+
});
|
|
11
|
+
if (!fieldPath) {
|
|
12
|
+
fieldPath = field.field.storageId;
|
|
13
|
+
if (field.path) fieldPath = "function" == typeof field.path ? field.path(value) : field.path;
|
|
14
|
+
}
|
|
15
|
+
const result = field.parents.map((p)=>p.storageId).concat([
|
|
16
|
+
fieldPath
|
|
17
|
+
]);
|
|
18
|
+
return {
|
|
19
|
+
basePath: result.join("."),
|
|
20
|
+
path: result.concat(keyword ? [
|
|
21
|
+
"keyword"
|
|
22
|
+
] : []).join(".")
|
|
23
|
+
};
|
|
32
24
|
};
|
|
33
|
-
|
|
34
|
-
};
|
|
25
|
+
export { createFieldPathFactory };
|
|
35
26
|
|
|
36
27
|
//# sourceMappingURL=path.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/filtering/path.js","sources":["../../../../../src/operations/entry/elasticsearch/filtering/path.ts"],"sourcesContent":["import type { ModelField } from \"~/operations/entry/elasticsearch/types.js\";\nimport type { CmsEntryOpenSearchValueSearchRegistry } from \"~/features/CmsEntryOpenSearchValueSearch/index.js\";\n\ninterface FieldPathFactoryParams {\n valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface;\n}\ninterface FieldPathParams {\n field: ModelField;\n key: string;\n value: any;\n originalValue: any;\n keyword: boolean;\n}\n\nexport const createFieldPathFactory = ({ valueSearchRegistry }: FieldPathFactoryParams) => {\n return (params: FieldPathParams) => {\n const { field, key, value, keyword, originalValue } = params;\n const search = valueSearchRegistry.get(field.type);\n\n let fieldPath: string | null = null;\n if (search) {\n fieldPath = search.createPath({ field: field.field, value, key, originalValue });\n }\n if (!fieldPath) {\n fieldPath = field.field.storageId;\n if (field.path) {\n fieldPath = typeof field.path === \"function\" ? field.path(value) : field.path;\n }\n }\n\n const result: string[] = field.parents.map(p => p.storageId).concat([fieldPath]);\n\n return {\n basePath: result.join(\".\"),\n path: result.concat(keyword ? [\"keyword\"] : []).join(\".\")\n };\n };\n};\n"],"names":["createFieldPathFactory","valueSearchRegistry","params","field","key","value","keyword","originalValue","search","fieldPath","result","p"],"mappings":"AAcO,MAAMA,yBAAyB,CAAC,EAAEC,mBAAmB,EAA0B,GAC3E,CAACC;QACJ,MAAM,EAAEC,KAAK,EAAEC,GAAG,EAAEC,KAAK,EAAEC,OAAO,EAAEC,aAAa,EAAE,GAAGL;QACtD,MAAMM,SAASP,oBAAoB,GAAG,CAACE,MAAM,IAAI;QAEjD,IAAIM,YAA2B;QAC/B,IAAID,QACAC,YAAYD,OAAO,UAAU,CAAC;YAAE,OAAOL,MAAM,KAAK;YAAEE;YAAOD;YAAKG;QAAc;QAElF,IAAI,CAACE,WAAW;YACZA,YAAYN,MAAM,KAAK,CAAC,SAAS;YACjC,IAAIA,MAAM,IAAI,EACVM,YAAY,AAAsB,cAAtB,OAAON,MAAM,IAAI,GAAkBA,MAAM,IAAI,CAACE,SAASF,MAAM,IAAI;QAErF;QAEA,MAAMO,SAAmBP,MAAM,OAAO,CAAC,GAAG,CAACQ,CAAAA,IAAKA,EAAE,SAAS,EAAE,MAAM,CAAC;YAACF;SAAU;QAE/E,OAAO;YACH,UAAUC,OAAO,IAAI,CAAC;YACtB,MAAMA,OAAO,MAAM,CAACJ,UAAU;gBAAC;aAAU,GAAG,EAAE,EAAE,IAAI,CAAC;QACzD;IACJ"}
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
continue;
|
|
1
|
+
const getPopulated = (query)=>{
|
|
2
|
+
const result = {};
|
|
3
|
+
let key;
|
|
4
|
+
for(key in query){
|
|
5
|
+
const value = query[key];
|
|
6
|
+
if (!(void 0 === value || Array.isArray(value) && 0 === value.length)) result[key] = value;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
* TODO figure out better types.
|
|
11
|
-
*/
|
|
12
|
-
// @ts-expect-error
|
|
13
|
-
result[key] = value;
|
|
14
|
-
}
|
|
15
|
-
return result;
|
|
8
|
+
return result;
|
|
16
9
|
};
|
|
10
|
+
export { getPopulated };
|
|
17
11
|
|
|
18
12
|
//# sourceMappingURL=populated.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/filtering/populated.js","sources":["../../../../../src/operations/entry/elasticsearch/filtering/populated.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\n\nexport const getPopulated = (\n query: OpenSearchBoolQueryConfig\n): Partial<OpenSearchBoolQueryConfig> => {\n const result: Partial<OpenSearchBoolQueryConfig> = {};\n let key: keyof OpenSearchBoolQueryConfig;\n for (key in query) {\n const value = query[key];\n if (value === undefined || (Array.isArray(value) && value.length === 0)) {\n continue;\n }\n /**\n * TODO figure out better types.\n */\n // @ts-expect-error\n result[key] = value;\n }\n return result;\n};\n"],"names":["getPopulated","query","result","key","value","undefined","Array"],"mappings":"AAEO,MAAMA,eAAe,CACxBC;IAEA,MAAMC,SAA6C,CAAC;IACpD,IAAIC;IACJ,IAAKA,OAAOF,MAAO;QACf,MAAMG,QAAQH,KAAK,CAACE,IAAI;QACxB,KAAIC,CAAAA,AAAUC,WAAVD,SAAwBE,MAAM,OAAO,CAACF,UAAUA,AAAiB,MAAjBA,MAAM,MAAM,AAAK,GAOrEF,MAAM,CAACC,IAAI,GAAGC;IAClB;IACA,OAAOF;AACX"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
const getWhereValues = (value, condition)=>{
|
|
3
|
+
const values = value;
|
|
4
|
+
if (Array.isArray(values)) {
|
|
5
|
+
if (0 === values.length) throw new error(`Trying to run filtering with "${condition}", but the value sent is empty array.`, `MALFORMED_${condition}_CONDITION`, {
|
|
6
|
+
value
|
|
7
|
+
});
|
|
8
|
+
} else throw new error(`Trying to run filtering with "${condition}", but the value sent is not an array.`, `MALFORMED_${condition}_CONDITION`, {
|
|
9
|
+
value
|
|
7
10
|
});
|
|
8
|
-
|
|
9
|
-
throw new WebinyError(`Trying to run filtering with "${condition}", but the value sent is empty array.`, `MALFORMED_${condition}_CONDITION`, {
|
|
10
|
-
value
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
return values;
|
|
11
|
+
return values;
|
|
14
12
|
};
|
|
13
|
+
export { getWhereValues };
|
|
15
14
|
|
|
16
15
|
//# sourceMappingURL=values.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/filtering/values.js","sources":["../../../../../src/operations/entry/elasticsearch/filtering/values.ts"],"sourcesContent":["import type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport WebinyError from \"@webiny/error\";\n\nexport const getWhereValues = (value: unknown, condition: \"AND\" | \"OR\") => {\n const values = value as CmsEntryListWhere[] | undefined;\n if (!Array.isArray(values)) {\n throw new WebinyError(\n `Trying to run filtering with \"${condition}\", but the value sent is not an array.`,\n `MALFORMED_${condition}_CONDITION`,\n {\n value\n }\n );\n } else if (values.length === 0) {\n throw new WebinyError(\n `Trying to run filtering with \"${condition}\", but the value sent is empty array.`,\n `MALFORMED_${condition}_CONDITION`,\n {\n value\n }\n );\n }\n return values;\n};\n"],"names":["getWhereValues","value","condition","values","Array","WebinyError"],"mappings":";AAGO,MAAMA,iBAAiB,CAACC,OAAgBC;IAC3C,MAAMC,SAASF;IACf,IAAKG,MAAM,OAAO,CAACD,SAQZ;QAAA,IAAIA,AAAkB,MAAlBA,OAAO,MAAM,EACpB,MAAM,IAAIE,MACN,CAAC,8BAA8B,EAAEH,UAAU,qCAAqC,CAAC,EACjF,CAAC,UAAU,EAAEA,UAAU,UAAU,CAAC,EAClC;YACID;QACJ;IAER,OAfI,MAAM,IAAII,MACN,CAAC,8BAA8B,EAAEH,UAAU,sCAAsC,CAAC,EAClF,CAAC,UAAU,EAAEA,UAAU,UAAU,CAAC,EAClC;QACID;IACJ;IAWR,OAAOE;AACX"}
|
|
@@ -1,88 +1,51 @@
|
|
|
1
1
|
import { normalizeValue } from "@webiny/api-opensearch";
|
|
2
|
-
/**
|
|
3
|
-
* Our default implementation works with the AND operator for the multiple words query string.
|
|
4
|
-
*/
|
|
5
2
|
const defaultFullTextSearch = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
fields: Object.values(fields).map(createFieldPath),
|
|
18
|
-
query: `*${prepareTerm(term)}*`,
|
|
19
|
-
default_operator: "and"
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
3
|
+
apply: (params)=>{
|
|
4
|
+
const { query, term, fields, createFieldPath, prepareTerm } = params;
|
|
5
|
+
query.must.push({
|
|
6
|
+
query_string: {
|
|
7
|
+
allow_leading_wildcard: true,
|
|
8
|
+
fields: Object.values(fields).map(createFieldPath),
|
|
9
|
+
query: `*${prepareTerm(term)}*`,
|
|
10
|
+
default_operator: "and"
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
23
14
|
};
|
|
24
|
-
const getFullTextSearch = params
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* We need to find the most specific implementation for the given model.
|
|
35
|
-
* Also, we need to use the first possible implementation if the specific one is not found.
|
|
36
|
-
*/
|
|
37
|
-
let fallback = null;
|
|
38
|
-
for (const item of reversed) {
|
|
39
|
-
const models = item.models || [];
|
|
40
|
-
/**
|
|
41
|
-
* We take the first available implementation for the given model.
|
|
42
|
-
*/
|
|
43
|
-
if (models.includes(model.modelId)) {
|
|
44
|
-
return item;
|
|
45
|
-
} else if (!fallback && models.length === 0) {
|
|
46
|
-
/**
|
|
47
|
-
* Then we set the first possible implementation, which has no models defined, as the default one.
|
|
48
|
-
* It is important not to set the one which has models defined as they are specifically for the targeted model.
|
|
49
|
-
*/
|
|
50
|
-
fallback = item;
|
|
15
|
+
const getFullTextSearch = (params)=>{
|
|
16
|
+
const { fullTextSearches, model } = params;
|
|
17
|
+
const reversed = [
|
|
18
|
+
...fullTextSearches
|
|
19
|
+
].reverse();
|
|
20
|
+
let fallback = null;
|
|
21
|
+
for (const item of reversed){
|
|
22
|
+
const models = item.models || [];
|
|
23
|
+
if (models.includes(model.modelId)) return item;
|
|
24
|
+
if (!fallback && 0 === models.length) fallback = item;
|
|
51
25
|
}
|
|
52
|
-
|
|
53
|
-
return fallback || defaultFullTextSearch;
|
|
26
|
+
return fallback || defaultFullTextSearch;
|
|
54
27
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return field.path(term);
|
|
76
|
-
} else if (field.systemField) {
|
|
77
|
-
return field.path || field.field.storageId;
|
|
78
|
-
}
|
|
79
|
-
return `values.${field.path || field.field.storageId}`;
|
|
80
|
-
},
|
|
81
|
-
fields,
|
|
82
|
-
query,
|
|
83
|
-
term,
|
|
84
|
-
prepareTerm: normalizeValue
|
|
85
|
-
});
|
|
28
|
+
const applyFullTextSearch = (params)=>{
|
|
29
|
+
const { fullTextSearches, query, term, fields, model } = params;
|
|
30
|
+
const keys = Object.keys(fields);
|
|
31
|
+
if (!term || 0 === term.length || 0 === keys.length) return;
|
|
32
|
+
const fullTextSearch = getFullTextSearch({
|
|
33
|
+
fullTextSearches,
|
|
34
|
+
model
|
|
35
|
+
});
|
|
36
|
+
fullTextSearch.apply({
|
|
37
|
+
model,
|
|
38
|
+
createFieldPath: (field)=>{
|
|
39
|
+
if ("function" == typeof field.path) return field.path(term);
|
|
40
|
+
if (field.systemField) return field.path || field.field.storageId;
|
|
41
|
+
return `values.${field.path || field.field.storageId}`;
|
|
42
|
+
},
|
|
43
|
+
fields,
|
|
44
|
+
query,
|
|
45
|
+
term,
|
|
46
|
+
prepareTerm: normalizeValue
|
|
47
|
+
});
|
|
86
48
|
};
|
|
49
|
+
export { applyFullTextSearch };
|
|
87
50
|
|
|
88
51
|
//# sourceMappingURL=fullTextSearch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/fullTextSearch.js","sources":["../../../../src/operations/entry/elasticsearch/fullTextSearch.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\nimport { normalizeValue } from \"@webiny/api-opensearch\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsEntryOpenSearchFullTextSearch } from \"~/features/CmsEntryOpenSearchFullTextSearch/index.js\";\nimport type { ModelFields } from \"~/operations/entry/elasticsearch/types.js\";\n\n/**\n * Our default implementation works with the AND operator for the multiple words query string.\n */\nconst defaultFullTextSearch: CmsEntryOpenSearchFullTextSearch.Interface = {\n apply: params => {\n const { query, term, fields, createFieldPath, prepareTerm } = params;\n\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: Object.values(fields).map(createFieldPath),\n query: `*${prepareTerm(term)}*`,\n default_operator: \"and\"\n }\n });\n }\n};\n\ninterface GetFullTextSearchParams {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n}\nconst getFullTextSearch = (\n params: GetFullTextSearchParams\n): CmsEntryOpenSearchFullTextSearch.Interface => {\n const { fullTextSearches, model } = params;\n /**\n * We need to reverse the list, so we can take the last one first - possibility to override existing implementations.\n */\n const reversed = [...fullTextSearches].reverse();\n /**\n * We need to find the most specific implementation for the given model.\n * Also, we need to use the first possible implementation if the specific one is not found.\n */\n let fallback: CmsEntryOpenSearchFullTextSearch.Interface | null = null;\n for (const item of reversed) {\n const models = item.models || [];\n /**\n * We take the first available implementation for the given model.\n */\n if (models.includes(model.modelId)) {\n return item;\n } else if (!fallback && models.length === 0) {\n /**\n * Then we set the first possible implementation, which has no models defined, as the default one.\n * It is important not to set the one which has models defined as they are specifically for the targeted model.\n */\n fallback = item;\n }\n }\n\n return fallback || defaultFullTextSearch;\n};\n\ninterface Params {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n query: OpenSearchBoolQueryConfig;\n term?: string;\n fields: ModelFields;\n}\nexport const applyFullTextSearch = (params: Params): void => {\n const { fullTextSearches, query, term, fields, model } = params;\n const keys = Object.keys(fields);\n if (!term || term.length === 0 || keys.length === 0) {\n return;\n }\n\n const fullTextSearch = getFullTextSearch({\n fullTextSearches,\n model\n });\n\n fullTextSearch.apply({\n model,\n createFieldPath: field => {\n if (typeof field.path === \"function\") {\n return field.path(term);\n } else if (field.systemField) {\n return field.path || field.field.storageId;\n }\n return `values.${field.path || field.field.storageId}`;\n },\n fields,\n query,\n term,\n prepareTerm: normalizeValue\n });\n};\n"],"names":["defaultFullTextSearch","params","query","term","fields","createFieldPath","prepareTerm","Object","getFullTextSearch","fullTextSearches","model","reversed","fallback","item","models","applyFullTextSearch","keys","fullTextSearch","field","normalizeValue"],"mappings":";AASA,MAAMA,wBAAoE;IACtE,OAAOC,CAAAA;QACH,MAAM,EAAEC,KAAK,EAAEC,IAAI,EAAEC,MAAM,EAAEC,eAAe,EAAEC,WAAW,EAAE,GAAGL;QAE9DC,MAAM,IAAI,CAAC,IAAI,CAAC;YACZ,cAAc;gBACV,wBAAwB;gBACxB,QAAQK,OAAO,MAAM,CAACH,QAAQ,GAAG,CAACC;gBAClC,OAAO,CAAC,CAAC,EAAEC,YAAYH,MAAM,CAAC,CAAC;gBAC/B,kBAAkB;YACtB;QACJ;IACJ;AACJ;AAMA,MAAMK,oBAAoB,CACtBP;IAEA,MAAM,EAAEQ,gBAAgB,EAAEC,KAAK,EAAE,GAAGT;IAIpC,MAAMU,WAAW;WAAIF;KAAiB,CAAC,OAAO;IAK9C,IAAIG,WAA8D;IAClE,KAAK,MAAMC,QAAQF,SAAU;QACzB,MAAMG,SAASD,KAAK,MAAM,IAAI,EAAE;QAIhC,IAAIC,OAAO,QAAQ,CAACJ,MAAM,OAAO,GAC7B,OAAOG;QACJ,IAAI,CAACD,YAAYE,AAAkB,MAAlBA,OAAO,MAAM,EAKjCF,WAAWC;IAEnB;IAEA,OAAOD,YAAYZ;AACvB;AASO,MAAMe,sBAAsB,CAACd;IAChC,MAAM,EAAEQ,gBAAgB,EAAEP,KAAK,EAAEC,IAAI,EAAEC,MAAM,EAAEM,KAAK,EAAE,GAAGT;IACzD,MAAMe,OAAOT,OAAO,IAAI,CAACH;IACzB,IAAI,CAACD,QAAQA,AAAgB,MAAhBA,KAAK,MAAM,IAAUa,AAAgB,MAAhBA,KAAK,MAAM,EACzC;IAGJ,MAAMC,iBAAiBT,kBAAkB;QACrCC;QACAC;IACJ;IAEAO,eAAe,KAAK,CAAC;QACjBP;QACA,iBAAiBQ,CAAAA;YACb,IAAI,AAAsB,cAAtB,OAAOA,MAAM,IAAI,EACjB,OAAOA,MAAM,IAAI,CAACf;YACf,IAAIe,MAAM,WAAW,EACxB,OAAOA,MAAM,IAAI,IAAIA,MAAM,KAAK,CAAC,SAAS;YAE9C,OAAO,CAAC,OAAO,EAAEA,MAAM,IAAI,IAAIA,MAAM,KAAK,CAAC,SAAS,EAAE;QAC1D;QACAd;QACAF;QACAC;QACA,aAAagB;IACjB;AACJ"}
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
term
|
|
4
|
-
|
|
5
|
-
fields
|
|
6
|
-
|
|
7
|
-
if (!targets?.length || !term || term.trim().length === 0) {
|
|
8
|
-
return {};
|
|
9
|
-
}
|
|
10
|
-
const result = {};
|
|
11
|
-
for (const key in fields) {
|
|
12
|
-
if (targets.includes(key) === false) {
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
result[key] = fields[key];
|
|
16
|
-
}
|
|
17
|
-
return result;
|
|
1
|
+
const createFullTextSearchFields = (params)=>{
|
|
2
|
+
const { term, targets, fields } = params;
|
|
3
|
+
if (!targets?.length || !term || 0 === term.trim().length) return {};
|
|
4
|
+
const result = {};
|
|
5
|
+
for(const key in fields)if (false !== targets.includes(key)) result[key] = fields[key];
|
|
6
|
+
return result;
|
|
18
7
|
};
|
|
8
|
+
export { createFullTextSearchFields };
|
|
19
9
|
|
|
20
10
|
//# sourceMappingURL=fullTextSearchFields.js.map
|