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

Functions

 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ['science']
 
tuple base_url
 
bool paging = True
 
int number_of_results = 10
 
dict shorcut_dict
 

Detailed Description

BASE (Scholar publications)

Function Documentation

◆ request()

searx.engines.base.request ( query,
params )

Definition at line 56 of file base.py.

56def request(query, params):
57 # replace shortcuts with API advanced search keywords
58 for key, val in shorcut_dict.items():
59 query = re.sub(key, val, query)
60
61 # basic search
62 offset = (params['pageno'] - 1) * number_of_results
63
64 string_args = {
65 'query': urlencode({'query': query}),
66 'offset': offset,
67 'hits': number_of_results,
68 }
69
70 params['url'] = base_url.format(**string_args)
71
72 params['headers']['User-Agent'] = searx_useragent()
73 return params
74
75

◆ response()

searx.engines.base.response ( resp)

Definition at line 76 of file base.py.

76def response(resp):
77 results = []
78
79 search_results = etree.XML(resp.content)
80
81 for entry in search_results.xpath('./result/doc'):
82 content = "No description available"
83 url = ""
84 title = ""
85 date = datetime.now() # needed in case no dcdate is available for an item
86
87 for item in entry:
88 if item.attrib["name"] == "dcdate":
89 date = item.text
90
91 elif item.attrib["name"] == "dctitle":
92 title = item.text
93
94 elif item.attrib["name"] == "dclink":
95 url = item.text
96
97 elif item.attrib["name"] == "dcdescription":
98 content = item.text[:300]
99 if len(item.text) > 300:
100 content += "..."
101
102 # dates returned by the BASE API are not several formats
103 publishedDate = None
104 for date_format in ['%Y-%m-%dT%H:%M:%SZ', '%Y-%m-%d', '%Y-%m', '%Y']:
105 try:
106 publishedDate = datetime.strptime(date, date_format)
107 break
108 except: # pylint: disable=bare-except
109 pass
110
111 if publishedDate is not None:
112 res_dict = {'url': url, 'title': title, 'publishedDate': publishedDate, 'content': content}
113 else:
114 res_dict = {'url': url, 'title': title, 'content': content}
115
116 results.append(res_dict)
117
118 return results

Variable Documentation

◆ about

dict searx.engines.base.about
Initial value:
1= {
2 "website": 'https://base-search.net',
3 "wikidata_id": 'Q448335',
4 "official_api_documentation": 'https://api.base-search.net/',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'XML',
8}

Definition at line 13 of file base.py.

◆ base_url

tuple searx.engines.base.base_url
Initial value:
1= (
2 'https://api.base-search.net/cgi-bin/BaseHttpSearchInterface.fcgi'
3 + '?func=PerformSearch&{query}&boost=oa&hits={hits}&offset={offset}'
4)

Definition at line 24 of file base.py.

◆ categories

list searx.engines.base.categories = ['science']

Definition at line 22 of file base.py.

◆ number_of_results

int searx.engines.base.number_of_results = 10

Definition at line 31 of file base.py.

◆ paging

bool searx.engines.base.paging = True

Definition at line 30 of file base.py.

◆ shorcut_dict

dict searx.engines.base.shorcut_dict
Initial value:
1= {
2 # user-friendly keywords
3 'format:': 'dcformat:',
4 'author:': 'dccreator:',
5 'collection:': 'dccollection:',
6 'hdate:': 'dchdate:',
7 'contributor:': 'dccontributor:',
8 'coverage:': 'dccoverage:',
9 'date:': 'dcdate:',
10 'abstract:': 'dcdescription:',
11 'urls:': 'dcidentifier:',
12 'language:': 'dclanguage:',
13 'publisher:': 'dcpublisher:',
14 'relation:': 'dcrelation:',
15 'rights:': 'dcrights:',
16 'source:': 'dcsource:',
17 'subject:': 'dcsubject:',
18 'title:': 'dctitle:',
19 'type:': 'dcdctype:',
20}

Definition at line 34 of file base.py.