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

Classes

class  ResultContainer
class  Timing
class  UnresponsiveEngine

Functions

float calculate_score (MainResult|LegacyResult result, MainResult.PriorityType 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 ( MainResult | LegacyResult result,
MainResult.PriorityType priority )

Definition at line 17 of file results.py.

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

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 297 of file results.py.

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

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 357 of file results.py.

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

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

Here is the caller graph for this function: