205 def extend(self, engine_name: str | None, results):
206 if self._closed:
207 return
208
209 standard_result_count = 0
210 error_msgs = set()
211
212 for result in list(results):
213
214 if isinstance(result, Result):
215 result.engine = result.engine or engine_name
216 result.normalize_result_fields()
217
218 if isinstance(result, BaseAnswer) and self.on_result(result):
219 self.answers.add(result)
220 else:
221
222 raise NotImplementedError(f"no handler implemented to process the result of type {result}")
223
224 else:
225 result['engine'] = result.get('engine') or engine_name or ""
226 result = LegacyResult(result)
227
228 if 'suggestion' in result and self.on_result(result):
229 self.suggestions.add(result['suggestion'])
230 elif 'answer' in result and self.on_result(result):
231 warnings.warn(
232 f"answer results from engine {result.engine}"
233 " are without typification / migrate to Answer class.",
234 DeprecationWarning,
235 )
236 self.answers.add(result)
237 elif 'correction' in result and self.on_result(result):
238 self.corrections.add(result['correction'])
239 elif 'infobox' in result and self.on_result(result):
240 self._merge_infobox(result)
241 elif 'number_of_results' in result and self.on_result(result):
242 self._number_of_results.append(result['number_of_results'])
243 elif 'engine_data' in result and self.on_result(result):
244 self.engine_data[result.engine][result['key']] = result['engine_data']
245 elif result.url:
246
247 if not self._is_valid_url_result(result, error_msgs):
248 continue
249
250 result.normalize_result_fields()
251
252
253 if not self.on_result(result):
254 continue
255 self.__merge_url_result(result, standard_result_count + 1)
256 standard_result_count += 1
257 elif self.on_result(result):
258 self.__merge_result_no_url(result, standard_result_count + 1)
259 standard_result_count += 1
260
261 if len(error_msgs) > 0:
262 for msg in error_msgs:
263 count_error(engine_name, 'some results are invalids: ' + msg, secondary=True)
264
265 if engine_name in engines:
266 histogram_observe(standard_result_count, 'engine', engine_name, 'result', 'count')
267
268 if not self.paging and engine_name in engines and engines[engine_name].paging:
269 self.paging = True
270