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