@toxplanet/pegasus-sdk 1.2.4 → 1.2.6
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/lib/chemicals.js +140 -106
- package/lib/search.js +6 -3
- package/package.json +1 -1
package/lib/chemicals.js
CHANGED
|
@@ -734,7 +734,7 @@ class ChemicalsService {
|
|
|
734
734
|
*/
|
|
735
735
|
async searchByName(searchTerm, limit = 10) {
|
|
736
736
|
if (!searchTerm) {
|
|
737
|
-
return { results: [] };
|
|
737
|
+
return { results: [], total: { value: 0, relation: 'eq' } };
|
|
738
738
|
}
|
|
739
739
|
|
|
740
740
|
try {
|
|
@@ -771,7 +771,10 @@ class ChemicalsService {
|
|
|
771
771
|
score: hit._score
|
|
772
772
|
}));
|
|
773
773
|
|
|
774
|
-
return {
|
|
774
|
+
return {
|
|
775
|
+
results,
|
|
776
|
+
total: result?.hits?.total ?? { value: results.length, relation: 'eq' }
|
|
777
|
+
};
|
|
775
778
|
} catch (error) {
|
|
776
779
|
logError('pegasus-sdk', 'ChemicalsService', 'searchByName', error);
|
|
777
780
|
throw error;
|
|
@@ -786,7 +789,7 @@ class ChemicalsService {
|
|
|
786
789
|
*/
|
|
787
790
|
async searchBySynonym(synonymTerm, limit = 10) {
|
|
788
791
|
if (!synonymTerm) {
|
|
789
|
-
return { results: [] };
|
|
792
|
+
return { results: [], total: { value: 0, relation: 'eq' } };
|
|
790
793
|
}
|
|
791
794
|
|
|
792
795
|
try {
|
|
@@ -823,7 +826,10 @@ class ChemicalsService {
|
|
|
823
826
|
score: hit._score
|
|
824
827
|
}));
|
|
825
828
|
|
|
826
|
-
return {
|
|
829
|
+
return {
|
|
830
|
+
results,
|
|
831
|
+
total: result?.hits?.total ?? { value: results.length, relation: 'eq' }
|
|
832
|
+
};
|
|
827
833
|
} catch (error) {
|
|
828
834
|
logError('pegasus-sdk', 'ChemicalsService', 'searchBySynonym', error);
|
|
829
835
|
throw error;
|
|
@@ -896,13 +902,16 @@ class ChemicalsService {
|
|
|
896
902
|
index: async (params) => {
|
|
897
903
|
const chemical = params.body;
|
|
898
904
|
const result = await this.createChemical(chemical);
|
|
899
|
-
|
|
905
|
+
|
|
900
906
|
return {
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
907
|
+
body: {
|
|
908
|
+
_index: params.index,
|
|
909
|
+
_id: result.chemicalId,
|
|
910
|
+
_version: 1,
|
|
911
|
+
result: 'created',
|
|
912
|
+
_source: result
|
|
913
|
+
},
|
|
914
|
+
statusCode: 200
|
|
906
915
|
};
|
|
907
916
|
},
|
|
908
917
|
|
|
@@ -958,7 +967,10 @@ class ChemicalsService {
|
|
|
958
967
|
|
|
959
968
|
if (cdiDocuments.length === 0) {
|
|
960
969
|
logInfo('pegasus-sdk', `[ChemicalsService.bulk] No CDI documents to index, returning empty no-op response`);
|
|
961
|
-
return {
|
|
970
|
+
return {
|
|
971
|
+
body: { took: 0, errors: false, items: [] },
|
|
972
|
+
statusCode: 200
|
|
973
|
+
};
|
|
962
974
|
}
|
|
963
975
|
|
|
964
976
|
logInfo('pegasus-sdk', `[ChemicalsService.bulk] Calling bulkIndexFielded with ${cdiDocuments.length} CDI documents`);
|
|
@@ -972,17 +984,20 @@ class ChemicalsService {
|
|
|
972
984
|
}
|
|
973
985
|
|
|
974
986
|
return {
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
987
|
+
body: {
|
|
988
|
+
took: 1,
|
|
989
|
+
errors: result.errors.length > 0,
|
|
990
|
+
items: result.results.map((res, idx) => ({
|
|
991
|
+
index: {
|
|
992
|
+
_index: 'chemical_data_index',
|
|
993
|
+
_id: cdiDocuments[idx].source_id,
|
|
994
|
+
status: res.success ? 200 : 400,
|
|
995
|
+
result: res.success ? 'created' : 'error',
|
|
996
|
+
...(res.success ? {} : { error: { type: 'mapper_parsing_exception', reason: res.error } })
|
|
997
|
+
}
|
|
998
|
+
}))
|
|
999
|
+
},
|
|
1000
|
+
statusCode: 200
|
|
986
1001
|
};
|
|
987
1002
|
} catch (error) {
|
|
988
1003
|
logError('pegasus-sdk', 'ChemicalsService.bulk', 'Fatal error during bulk indexing', error);
|
|
@@ -992,46 +1007,61 @@ class ChemicalsService {
|
|
|
992
1007
|
|
|
993
1008
|
get: async (params) => {
|
|
994
1009
|
const result = await this.getChemicalBySourceId(params.id);
|
|
995
|
-
|
|
1010
|
+
|
|
996
1011
|
if (!result) {
|
|
997
1012
|
return {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1013
|
+
body: {
|
|
1014
|
+
_index: params.index,
|
|
1015
|
+
_id: params.id,
|
|
1016
|
+
found: false
|
|
1017
|
+
},
|
|
1018
|
+
statusCode: 200
|
|
1001
1019
|
};
|
|
1002
1020
|
}
|
|
1003
|
-
|
|
1021
|
+
|
|
1004
1022
|
return {
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1023
|
+
body: {
|
|
1024
|
+
_index: params.index,
|
|
1025
|
+
_id: params.id,
|
|
1026
|
+
_version: 1,
|
|
1027
|
+
found: true,
|
|
1028
|
+
_source: result
|
|
1029
|
+
},
|
|
1030
|
+
statusCode: 200
|
|
1010
1031
|
};
|
|
1011
1032
|
},
|
|
1012
1033
|
|
|
1013
1034
|
update: async (params) => {
|
|
1014
1035
|
const result = await this.updateChemical(params.id, params.body);
|
|
1015
|
-
|
|
1036
|
+
|
|
1016
1037
|
return {
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1038
|
+
body: {
|
|
1039
|
+
_index: params.index,
|
|
1040
|
+
_id: params.id,
|
|
1041
|
+
_version: 2,
|
|
1042
|
+
result: result ? 'updated' : 'noop',
|
|
1043
|
+
_source: result
|
|
1044
|
+
},
|
|
1045
|
+
statusCode: 200
|
|
1022
1046
|
};
|
|
1023
1047
|
},
|
|
1024
1048
|
|
|
1025
1049
|
delete: async (params) => {
|
|
1026
1050
|
if (params.index === 'synonym_lookup_index') {
|
|
1027
|
-
return {
|
|
1051
|
+
return {
|
|
1052
|
+
body: { _index: params.index, _id: params.id, result: 'not_found' },
|
|
1053
|
+
statusCode: 200
|
|
1054
|
+
};
|
|
1028
1055
|
}
|
|
1029
1056
|
const result = await this.deleteBySourceId(params.id);
|
|
1030
|
-
|
|
1057
|
+
|
|
1031
1058
|
return {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1059
|
+
body: {
|
|
1060
|
+
_index: params.index,
|
|
1061
|
+
_id: params.id,
|
|
1062
|
+
result: result ? 'deleted' : 'not_found'
|
|
1063
|
+
},
|
|
1064
|
+
statusCode: 200
|
|
1035
1065
|
};
|
|
1036
1066
|
},
|
|
1037
1067
|
|
|
@@ -1039,12 +1069,18 @@ class ChemicalsService {
|
|
|
1039
1069
|
const sourceId = params.body?.query?.term?.chemical_set_identifier
|
|
1040
1070
|
|| params.body?.query?.term?.source_id;
|
|
1041
1071
|
if (!sourceId) {
|
|
1042
|
-
return {
|
|
1072
|
+
return {
|
|
1073
|
+
body: { deleted: 0, failures: [] },
|
|
1074
|
+
statusCode: 200
|
|
1075
|
+
};
|
|
1043
1076
|
}
|
|
1044
1077
|
const result = await this.deleteBySourceId(sourceId);
|
|
1045
1078
|
return {
|
|
1046
|
-
|
|
1047
|
-
|
|
1079
|
+
body: {
|
|
1080
|
+
deleted: result ? 1 : 0,
|
|
1081
|
+
failures: []
|
|
1082
|
+
},
|
|
1083
|
+
statusCode: 200
|
|
1048
1084
|
};
|
|
1049
1085
|
},
|
|
1050
1086
|
|
|
@@ -1052,86 +1088,84 @@ class ChemicalsService {
|
|
|
1052
1088
|
let searchTerm = '';
|
|
1053
1089
|
let limit = params.body?.size || 10;
|
|
1054
1090
|
|
|
1091
|
+
const toLegacySource = (r) => ({
|
|
1092
|
+
chemical_name: r.name,
|
|
1093
|
+
chemical_name_sensitive: r.name,
|
|
1094
|
+
chemical_name_sort: (r.name || '').toLowerCase(),
|
|
1095
|
+
chemical_identifier: [...(r.cas || []), ...(r.identifiers || [])],
|
|
1096
|
+
chemical_set_identifier: (r.cas && r.cas[0]) || r.id || ''
|
|
1097
|
+
});
|
|
1098
|
+
|
|
1055
1099
|
if (params.index === 'synonym_lookup_index') {
|
|
1056
1100
|
const query = params.body?.query;
|
|
1057
|
-
searchTerm = query?.match?.chemical_name ||
|
|
1058
|
-
query?.term?.chemical_name ||
|
|
1101
|
+
searchTerm = query?.match?.chemical_name ||
|
|
1102
|
+
query?.term?.chemical_name ||
|
|
1059
1103
|
query?.query_string?.query || '';
|
|
1060
1104
|
const searchResults = await this.searchBySynonym(searchTerm, limit);
|
|
1061
|
-
|
|
1105
|
+
|
|
1062
1106
|
return {
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
hits: {
|
|
1072
|
-
total: {
|
|
1073
|
-
value: searchResults.results.length,
|
|
1074
|
-
relation: 'eq'
|
|
1107
|
+
body: {
|
|
1108
|
+
took: 1,
|
|
1109
|
+
timed_out: false,
|
|
1110
|
+
_shards: {
|
|
1111
|
+
total: 1,
|
|
1112
|
+
successful: 1,
|
|
1113
|
+
skipped: 0,
|
|
1114
|
+
failed: 0
|
|
1075
1115
|
},
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
}))
|
|
1089
|
-
}
|
|
1116
|
+
hits: {
|
|
1117
|
+
total: searchResults.total ?? { value: searchResults.results.length, relation: 'eq' },
|
|
1118
|
+
max_score: searchResults.results[0]?.score || 0,
|
|
1119
|
+
hits: searchResults.results.map(result => ({
|
|
1120
|
+
_index: params.index,
|
|
1121
|
+
_id: result.id,
|
|
1122
|
+
_score: result.score,
|
|
1123
|
+
_source: toLegacySource(result)
|
|
1124
|
+
}))
|
|
1125
|
+
}
|
|
1126
|
+
},
|
|
1127
|
+
statusCode: 200
|
|
1090
1128
|
};
|
|
1091
1129
|
} else {
|
|
1092
1130
|
const query = params.body?.query;
|
|
1093
|
-
searchTerm = query?.match?.chemical_name ||
|
|
1094
|
-
query?.term?.chemical_name ||
|
|
1131
|
+
searchTerm = query?.match?.chemical_name ||
|
|
1132
|
+
query?.term?.chemical_name ||
|
|
1095
1133
|
query?.query_string?.query || '';
|
|
1096
1134
|
const searchResults = await this.searchByName(searchTerm, limit);
|
|
1097
|
-
|
|
1135
|
+
|
|
1098
1136
|
return {
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
hits: {
|
|
1108
|
-
total: {
|
|
1109
|
-
value: searchResults.results.length,
|
|
1110
|
-
relation: 'eq'
|
|
1137
|
+
body: {
|
|
1138
|
+
took: 1,
|
|
1139
|
+
timed_out: false,
|
|
1140
|
+
_shards: {
|
|
1141
|
+
total: 1,
|
|
1142
|
+
successful: 1,
|
|
1143
|
+
skipped: 0,
|
|
1144
|
+
failed: 0
|
|
1111
1145
|
},
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
}))
|
|
1125
|
-
}
|
|
1146
|
+
hits: {
|
|
1147
|
+
total: searchResults.total ?? { value: searchResults.results.length, relation: 'eq' },
|
|
1148
|
+
max_score: searchResults.results[0]?.score || 0,
|
|
1149
|
+
hits: searchResults.results.map(result => ({
|
|
1150
|
+
_index: params.index,
|
|
1151
|
+
_id: result.id,
|
|
1152
|
+
_score: result.score,
|
|
1153
|
+
_source: toLegacySource(result)
|
|
1154
|
+
}))
|
|
1155
|
+
}
|
|
1156
|
+
},
|
|
1157
|
+
statusCode: 200
|
|
1126
1158
|
};
|
|
1127
1159
|
}
|
|
1128
1160
|
},
|
|
1129
1161
|
|
|
1130
1162
|
count: async (params) => {
|
|
1131
1163
|
if (params.index === 'synonym_lookup_index') {
|
|
1132
|
-
|
|
1164
|
+
const result = await this.getTotalSynonymCount();
|
|
1165
|
+
return { body: result, statusCode: 200 };
|
|
1133
1166
|
}
|
|
1134
|
-
|
|
1167
|
+
const result = await this.countAll();
|
|
1168
|
+
return { body: result, statusCode: 200 };
|
|
1135
1169
|
}
|
|
1136
1170
|
};
|
|
1137
1171
|
}
|
package/lib/search.js
CHANGED
|
@@ -94,7 +94,7 @@ class SearchService {
|
|
|
94
94
|
*/
|
|
95
95
|
async searchChemicals(query, options = {}) {
|
|
96
96
|
if (!query) {
|
|
97
|
-
return { results: [] };
|
|
97
|
+
return { results: [], total: { value: 0, relation: 'eq' } };
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
// Extract options with defaults
|
|
@@ -165,7 +165,10 @@ class SearchService {
|
|
|
165
165
|
score: hit._score
|
|
166
166
|
}));
|
|
167
167
|
|
|
168
|
-
return {
|
|
168
|
+
return {
|
|
169
|
+
results,
|
|
170
|
+
total: result?.hits?.total ?? { value: results.length, relation: 'eq' }
|
|
171
|
+
};
|
|
169
172
|
} catch (error) {
|
|
170
173
|
logError('pegasus-sdk', 'SearchService', 'searchChemicals', error);
|
|
171
174
|
throw error;
|
|
@@ -356,7 +359,7 @@ class SearchService {
|
|
|
356
359
|
chemical_set_identifier: (r.cas && r.cas[0]) || r.id || '',
|
|
357
360
|
}
|
|
358
361
|
})),
|
|
359
|
-
total: { value: pegasusResults.results.length, relation: 'eq' }
|
|
362
|
+
total: pegasusResults.total ?? { value: pegasusResults.results.length, relation: 'eq' }
|
|
360
363
|
},
|
|
361
364
|
timed_out: false,
|
|
362
365
|
_shards: { total: 1, successful: 1, failed: 0 }
|
package/package.json
CHANGED