.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
doku.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""
3 Doku Wiki
4"""
5
6from urllib.parse import urlencode
7from lxml.html import fromstring
8from searx.utils import extract_text, eval_xpath
9
10# about
11about = {
12 "website": 'https://www.dokuwiki.org/',
13 "wikidata_id": 'Q851864',
14 "official_api_documentation": 'https://www.dokuwiki.org/devel:xmlrpc',
15 "use_official_api": False,
16 "require_api_key": False,
17 "results": 'HTML',
18}
19
20# engine dependent config
21categories = ['general'] # 'images', 'music', 'videos', 'files'
22paging = False
23number_of_results = 5
24
25# search-url
26# Doku is OpenSearch compatible
27base_url = 'http://localhost:8090'
28search_url = (
29 # fmt: off
30 '/?do=search'
31 '&{query}'
32 # fmt: on
33)
34# '&startRecord={offset}'
35# '&maximumRecords={limit}'
36
37
38# do search-request
39def request(query, params):
40
41 params['url'] = base_url + search_url.format(query=urlencode({'id': query}))
42
43 return params
44
45
46# get response from search-request
47def response(resp):
48 results = []
49
50 doc = fromstring(resp.text)
51
52 # parse results
53 # Quickhits
54 for r in eval_xpath(doc, '//div[@class="search_quickresult"]/ul/li'):
55 try:
56 res_url = eval_xpath(r, './/a[@class="wikilink1"]/@href')[-1]
57 except: # pylint: disable=bare-except
58 continue
59
60 if not res_url:
61 continue
62
63 title = extract_text(eval_xpath(r, './/a[@class="wikilink1"]/@title'))
64
65 # append result
66 results.append({'title': title, 'content': "", 'url': base_url + res_url})
67
68 # Search results
69 for r in eval_xpath(doc, '//dl[@class="search_results"]/*'):
70 try:
71 if r.tag == "dt":
72 res_url = eval_xpath(r, './/a[@class="wikilink1"]/@href')[-1]
73 title = extract_text(eval_xpath(r, './/a[@class="wikilink1"]/@title'))
74 elif r.tag == "dd":
75 content = extract_text(eval_xpath(r, '.'))
76
77 # append result
78 results.append({'title': title, 'content': content, 'url': base_url + res_url})
79 except: # pylint: disable=bare-except
80 continue
81
82 if not res_url:
83 continue
84
85 # return results
86 return results
response(resp)
Definition doku.py:47
request(query, params)
Definition doku.py:39