.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
microsoft_learn.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Engine for Microsoft Learn, Microsoft's technical knowledge base.
3
4To use this engine add the following entry to your engines list
5in ``settings.yml``:
6
7.. code:: yaml
8
9 - name: microsoft learn
10 engine: microsoft_learn
11 shortcut: msl
12 disabled: false
13"""
14
15from urllib.parse import urlencode
16from searx.result_types import EngineResults
17
18engine_type = "online"
19language_support = True
20categories = ["it"]
21paging = True
22page_size = 10
23time_range_support = False
24
25search_api = "https://learn.microsoft.com/api/search?"
26
27about = {
28 "website": "https://learn.microsoft.com",
29 "wikidata_id": "Q123663245",
30 "official_api_documentation": None,
31 "use_official_api": False,
32 "require_api_key": False,
33 "results": "JSON",
34}
35
36
37def request(query, params):
38
39 if params['language'] == 'all':
40 params['language'] = 'en-us'
41
42 query_params = [
43 ("search", query),
44 ("locale", params["language"]),
45 ("scoringprofile", "semantic-answers"),
46 ("facet", "category"),
47 ("facet", "products"),
48 ("facet", "tags"),
49 ("$top", "10"),
50 ("$skip", (params["pageno"] - 1) * page_size),
51 ("expandScope", "true"),
52 ("includeQuestion", "false"),
53 ("applyOperator", "false"),
54 ("partnerId", "LearnSite"),
55 ]
56
57 params["url"] = search_api + urlencode(query_params)
58 return params
59
60
61def response(resp) -> EngineResults:
62 res = EngineResults()
63 json_data = resp.json()
64
65 for result in json_data["results"]:
66 res.add(res.types.MainResult(url=result["url"], title=result["title"], content=result.get("description", "")))
67
68 return res