diff options
| author | Tommaso Colella <tommasocolella95@gmail.com> | 2025-04-01 13:24:35 +0000 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarIT.de> | 2025-04-12 11:14:13 +0200 |
| commit | 391bb1268dfbb61ec28ebff673ac1363c9417682 (patch) | |
| tree | afd736c9c163ace65139a968f0d138d9e6aa65cc /searx | |
| parent | 2287a6826aa612e39147d9e222736183df8f0b60 (diff) | |
[feat] engine: add microsoft learn engine
Diffstat (limited to 'searx')
| -rw-r--r-- | searx/engines/microsoft_learn.py | 68 | ||||
| -rw-r--r-- | searx/settings.yml | 5 |
2 files changed, 73 insertions, 0 deletions
diff --git a/searx/engines/microsoft_learn.py b/searx/engines/microsoft_learn.py new file mode 100644 index 000000000..cd67e3bff --- /dev/null +++ b/searx/engines/microsoft_learn.py @@ -0,0 +1,68 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""Engine for Microsoft Learn, Microsoft's technical knowledge base. + +To use this engine add the following entry to your engines list +in ``settings.yml``: + +.. code:: yaml + + - name: microsoft learn + engine: microsoft_learn + shortcut: msl + disabled: false +""" + +from urllib.parse import urlencode +from searx.result_types import EngineResults + +engine_type = "online" +language_support = True +categories = ["it"] +paging = True +page_size = 10 +time_range_support = False + +search_api = "https://learn.microsoft.com/api/search?" + +about = { + "website": "https://learn.microsoft.com", + "wikidata_id": "Q123663245", + "official_api_documentation": None, + "use_official_api": False, + "require_api_key": False, + "results": "JSON", +} + + +def request(query, params): + + if params['language'] == 'all': + params['language'] = 'en-us' + + query_params = [ + ("search", query), + ("locale", params["language"]), + ("scoringprofile", "semantic-answers"), + ("facet", "category"), + ("facet", "products"), + ("facet", "tags"), + ("$top", "10"), + ("$skip", (params["pageno"] - 1) * page_size), + ("expandScope", "true"), + ("includeQuestion", "false"), + ("applyOperator", "false"), + ("partnerId", "LearnSite"), + ] + + params["url"] = search_api + urlencode(query_params) + return params + + +def response(resp) -> EngineResults: + res = EngineResults() + json_data = resp.json() + + for result in json_data["results"]: + res.add(res.types.MainResult(url=result["url"], title=result["title"], content=result.get("description", ""))) + + return res diff --git a/searx/settings.yml b/searx/settings.yml index 4c715cc31..ec72f8736 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -1326,6 +1326,11 @@ engines: # index: my-index # auth_key: Bearer XXXX + - name: microsoft learn + engine: microsoft_learn + shortcut: msl + disabled: true + - name: mixcloud engine: mixcloud shortcut: mc |