.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.results Namespace Reference

Classes

class  ResultContainer
class  Timing
class  UnresponsiveEngine

Functions

float calculate_score (result, priority)
 merge_two_infoboxes (LegacyResult origin, LegacyResult other)
 merge_two_main_results (MainResult|LegacyResult origin, MainResult|LegacyResult other)

Function Documentation

◆ calculate_score()

float searx.results.calculate_score ( result,
priority )

Definition at line 17 of file results.py.

17def calculate_score(result, priority) -> float:
18 weight = 1.0
19
20 for result_engine in result['engines']:
21 if hasattr(searx.engines.engines.get(result_engine), 'weight'):
22 weight *= float(searx.engines.engines[result_engine].weight)
23
24 weight *= len(result['positions'])
25 score = 0
26
27 for position in result['positions']:
28 if priority == 'low':
29 continue
30 if priority == 'high':
31 score += weight
32 else:
33 score += weight / position
34
35 return score
36
37

Referenced by searx.results.ResultContainer.close().

Here is the caller graph for this function:

◆ merge_two_infoboxes()

searx.results.merge_two_infoboxes ( LegacyResult origin,
LegacyResult other )
Merges the values from ``other`` into ``origin``.

Definition at line 292 of file results.py.

292def merge_two_infoboxes(origin: LegacyResult, other: LegacyResult):
293 """Merges the values from ``other`` into ``origin``."""
294 # pylint: disable=too-many-branches
295 weight1 = getattr(searx.engines.engines[origin.engine], "weight", 1)
296 weight2 = getattr(searx.engines.engines[other.engine], "weight", 1)
297
298 if weight2 > weight1:
299 origin.engine = other.engine
300
301 origin.engines |= other.engines
302
303 if other.urls:
304 url_items = origin.get("urls", [])
305
306 for url2 in other.urls:
307 unique_url = True
308 entity_url2 = url2.get("entity")
309
310 for url1 in origin.get("urls", []):
311 if (entity_url2 is not None and entity_url2 == url1.get("entity")) or (
312 url1.get("url") == url2.get("url")
313 ):
314 unique_url = False
315 break
316 if unique_url:
317 url_items.append(url2)
318
319 origin.urls = url_items
320
321 if other.img_src:
322 if not origin.img_src:
323 origin.img_src = other.img_src
324 elif weight2 > weight1:
325 origin.img_src = other.img_src
326
327 if other.attributes:
328 if not origin.attributes:
329 origin.attributes = other.attributes
330 else:
331 attr_names_1 = set()
332 for attr in origin.attributes:
333 label = attr.get("label")
334 if label:
335 attr_names_1.add(label)
336
337 entity = attr.get("entity")
338 if entity:
339 attr_names_1.add(entity)
340
341 for attr in other.attributes:
342 if attr.get("label") not in attr_names_1 and attr.get('entity') not in attr_names_1:
343 origin.attributes.append(attr)
344
345 if other.content:
346 if not origin.content:
347 origin.content = other.content
348 elif len(other.content) > len(origin.content):
349 origin.content = other.content
350
351

Referenced by searx.results.ResultContainer._merge_infobox().

Here is the caller graph for this function:

◆ merge_two_main_results()

searx.results.merge_two_main_results ( MainResult | LegacyResult origin,
MainResult | LegacyResult other )
Merges the values from ``other`` into ``origin``.

Definition at line 352 of file results.py.

352def merge_two_main_results(origin: MainResult | LegacyResult, other: MainResult | LegacyResult):
353 """Merges the values from ``other`` into ``origin``."""
354
355 if len(other.content) > len(origin.content):
356 # use content with more text
357 origin.content = other.content
358
359 # use title with more text
360 if len(other.title) > len(origin.title):
361 origin.title = other.title
362
363 # merge all result's parameters not found in origin
364 if isinstance(other, MainResult) and isinstance(origin, MainResult):
365 origin.defaults_from(other)
366 elif isinstance(other, LegacyResult) and isinstance(origin, LegacyResult):
367 origin.defaults_from(other)
368
369 # add engine to list of result-engines
370 origin.engines.add(other.engine or "")
371
372 # use https, ftps, .. if possible
373 if origin.parsed_url and not origin.parsed_url.scheme.endswith("s"):
374 if other.parsed_url and other.parsed_url.scheme.endswith("s"):
375 origin.parsed_url = origin.parsed_url._replace(scheme=other.parsed_url.scheme)
376 origin.url = origin.parsed_url.geturl()

Referenced by searx.results.ResultContainer._merge_main_result().

Here is the caller graph for this function: