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

Classes

class  SXNGPlugin
 

Functions

bool|str filter_url_field ("Result|LegacyResult" result, str field_name, str url_src)
 
 extract_doi (url)
 
str get_doi_resolver ()
 

Variables

list ahmia_blacklist = []
 
 regex = re.compile(r'10\.\d{4,9}/[^\s]+')
 

Function Documentation

◆ extract_doi()

searx.plugins.oa_doi_rewrite.extract_doi ( url)

Definition at line 74 of file oa_doi_rewrite.py.

74def extract_doi(url):
75 m = regex.search(url.path)
76 if m:
77 return m.group(0)
78 for _, v in parse_qsl(url.query):
79 m = regex.search(v)
80 if m:
81 return m.group(0)
82 return None
83
84

Referenced by filter_url_field().

+ Here is the caller graph for this function:

◆ filter_url_field()

bool | str searx.plugins.oa_doi_rewrite.filter_url_field ( "Result|LegacyResult" result,
str field_name,
str url_src )
Returns bool ``True`` to use URL unchanged (``False`` to ignore URL).
If URL should be modified, the returned string is the new URL to use.

Definition at line 26 of file oa_doi_rewrite.py.

26def filter_url_field(result: "Result|LegacyResult", field_name: str, url_src: str) -> bool | str:
27 """Returns bool ``True`` to use URL unchanged (``False`` to ignore URL).
28 If URL should be modified, the returned string is the new URL to use."""
29
30 if field_name != "url":
31 return True # use it unchanged
32
33 doi = extract_doi(result.parsed_url)
34 if doi and len(doi) < 50:
35 for suffix in ("/", ".pdf", ".xml", "/full", "/meta", "/abstract"):
36 doi = doi.removesuffix(suffix)
37 new_url = get_doi_resolver() + doi
38 if "doi" not in result:
39 result["doi"] = doi
40 log.debug("oa_doi_rewrite: [URL field: %s] %s -> %s", field_name, url_src, new_url)
41 return new_url # use new url
42
43 return True # use it unchanged
44
45

References extract_doi(), and get_doi_resolver().

+ Here is the call graph for this function:

◆ get_doi_resolver()

str searx.plugins.oa_doi_rewrite.get_doi_resolver ( )

Definition at line 85 of file oa_doi_rewrite.py.

85def get_doi_resolver() -> str:
86 doi_resolvers = get_setting("doi_resolvers")
87 selected_resolver = sxng_request.preferences.get_value('doi_resolver')[0]
88 if selected_resolver not in doi_resolvers:
89 selected_resolver = get_setting("default_doi_resolver")
90 return doi_resolvers[selected_resolver]

References searx.get_setting().

Referenced by filter_url_field().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ ahmia_blacklist

list searx.plugins.oa_doi_rewrite.ahmia_blacklist = []

Definition at line 23 of file oa_doi_rewrite.py.

◆ regex

searx.plugins.oa_doi_rewrite.regex = re.compile(r'10\.\d{4,9}/[^\s]+')

Definition at line 71 of file oa_doi_rewrite.py.