.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
metacpan.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""metacpan
3"""
4
5from urllib.parse import urlunparse
6
7# about
8about = {
9 "website": 'https://metacpan.org/',
10 "wikidata_id": 'Q841507',
11 "official_api_documentation": 'https://github.com/metacpan/metacpan-api/blob/master/docs/API-docs.md',
12 "use_official_api": True,
13 "require_api_key": False,
14 "results": 'JSON',
15}
16
17# engine dependent config
18number_of_results = 20 # Don't put this over 5000
19categories = ["it", "packages"]
20disabled = True
21shortcut = "cpan"
22paging = True
23
24query_data_template = {
25 'query': {
26 'multi_match': {
27 'type': 'most_fields',
28 'fields': ['documentation', 'documentation.*'],
29 'analyzer': 'camelcase',
30 }
31 },
32 'filter': {
33 'bool': {
34 'must': [
35 {'exists': {'field': 'documentation'}},
36 {'term': {'status': 'latest'}},
37 {'term': {'indexed': 1}},
38 {'term': {'authorized': 1}},
39 ]
40 }
41 },
42 "sort": [
43 {"_score": {"order": "desc"}},
44 {"date": {"order": "desc"}},
45 ],
46 '_source': ['documentation', "abstract"],
47 'size': number_of_results,
48}
49search_url = urlunparse(["https", "fastapi.metacpan.org", "/v1/file/_search", "", "", ""])
50
51
52def request(query, params):
53 params["url"] = search_url
54 params["method"] = "POST"
55 query_data = query_data_template
56 query_data["query"]["multi_match"]["query"] = query
57 query_data["from"] = (params["pageno"] - 1) * number_of_results
58 params["json"] = query_data
59 return params
60
61
62def response(resp):
63 results = []
64
65 search_results = resp.json()["hits"]["hits"]
66 for result in search_results:
67 fields = result["_source"]
68 module = fields["documentation"]
69 results.append(
70 {
71 "url": "https://metacpan.org/pod/" + module,
72 "title": module,
73 "content": fields.get("abstract", ""),
74 }
75 )
76
77 return results
request(query, params)
Definition metacpan.py:52