@toxplanet/pegasus-sdk 1.2.5 → 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 +22 -26
- 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;
|
|
@@ -1082,6 +1088,14 @@ class ChemicalsService {
|
|
|
1082
1088
|
let searchTerm = '';
|
|
1083
1089
|
let limit = params.body?.size || 10;
|
|
1084
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
|
+
|
|
1085
1099
|
if (params.index === 'synonym_lookup_index') {
|
|
1086
1100
|
const query = params.body?.query;
|
|
1087
1101
|
searchTerm = query?.match?.chemical_name ||
|
|
@@ -1100,22 +1114,13 @@ class ChemicalsService {
|
|
|
1100
1114
|
failed: 0
|
|
1101
1115
|
},
|
|
1102
1116
|
hits: {
|
|
1103
|
-
total: {
|
|
1104
|
-
value: searchResults.results.length,
|
|
1105
|
-
relation: 'eq'
|
|
1106
|
-
},
|
|
1117
|
+
total: searchResults.total ?? { value: searchResults.results.length, relation: 'eq' },
|
|
1107
1118
|
max_score: searchResults.results[0]?.score || 0,
|
|
1108
1119
|
hits: searchResults.results.map(result => ({
|
|
1109
1120
|
_index: params.index,
|
|
1110
1121
|
_id: result.id,
|
|
1111
1122
|
_score: result.score,
|
|
1112
|
-
_source:
|
|
1113
|
-
postgres_id: result.id,
|
|
1114
|
-
chemical_name: result.name,
|
|
1115
|
-
cas_numbers: result.cas,
|
|
1116
|
-
identifier_values: result.identifiers,
|
|
1117
|
-
synonyms: result.synonyms
|
|
1118
|
-
}
|
|
1123
|
+
_source: toLegacySource(result)
|
|
1119
1124
|
}))
|
|
1120
1125
|
}
|
|
1121
1126
|
},
|
|
@@ -1139,22 +1144,13 @@ class ChemicalsService {
|
|
|
1139
1144
|
failed: 0
|
|
1140
1145
|
},
|
|
1141
1146
|
hits: {
|
|
1142
|
-
total: {
|
|
1143
|
-
value: searchResults.results.length,
|
|
1144
|
-
relation: 'eq'
|
|
1145
|
-
},
|
|
1147
|
+
total: searchResults.total ?? { value: searchResults.results.length, relation: 'eq' },
|
|
1146
1148
|
max_score: searchResults.results[0]?.score || 0,
|
|
1147
1149
|
hits: searchResults.results.map(result => ({
|
|
1148
1150
|
_index: params.index,
|
|
1149
1151
|
_id: result.id,
|
|
1150
1152
|
_score: result.score,
|
|
1151
|
-
_source:
|
|
1152
|
-
postgres_id: result.id,
|
|
1153
|
-
chemical_name: result.name,
|
|
1154
|
-
cas_numbers: result.cas,
|
|
1155
|
-
identifier_values: result.identifiers,
|
|
1156
|
-
synonyms: result.synonyms
|
|
1157
|
-
}
|
|
1153
|
+
_source: toLegacySource(result)
|
|
1158
1154
|
}))
|
|
1159
1155
|
}
|
|
1160
1156
|
},
|
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