.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.yacy Namespace Reference

Functions

 init (_)
 
str _base_url ()
 
 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ['general']
 
bool paging = True
 
int number_of_results = 10
 
str http_digest_auth_user = ""
 
str http_digest_auth_pass = ""
 
str search_mode = 'global'
 
str search_type = 'text'
 
list base_url = 'https://yacy.searchlab.eu'
 

Detailed Description

YaCy_ is a free distributed search engine, built on the principles of
peer-to-peer (P2P) networks.

API: Dev:APIyacysearch_

Releases:

- https://github.com/yacy/yacy_search_server/tags
- https://download.yacy.net/

.. _Yacy: https://yacy.net/
.. _Dev:APIyacysearch: https://wiki.yacy.net/index.php/Dev:APIyacysearch

Configuration
=============

The engine has the following (additional) settings:

- :py:obj:`http_digest_auth_user`
- :py:obj:`http_digest_auth_pass`
- :py:obj:`search_mode`
- :py:obj:`search_type`

The :py:obj:`base_url` has to be set in the engine named `yacy` and is used by
all yacy engines.

.. code:: yaml

  - name: yacy
    engine: yacy
    categories: general
    search_type: text
    shortcut: ya
    base_url:
      - https://yacy.searchlab.eu
      - https://search.lomig.me
      - https://yacy.ecosys.eu
      - https://search.webproject.link

  - name: yacy images
    engine: yacy
    categories: images
    search_type: image
    shortcut: yai
    disabled: true


Implementations
===============

Function Documentation

◆ _base_url()

str searx.engines.yacy._base_url ( )
protected

Definition at line 115 of file yacy.py.

115def _base_url() -> str:
116 from searx.engines import engines # pylint: disable=import-outside-toplevel
117
118 url = engines['yacy'].base_url # type: ignore
119 if isinstance(url, list):
120 url = random.choice(url)
121 return url
122
123
::1337x
Definition 1337x.py:1

◆ init()

searx.engines.yacy.init ( _)

Definition at line 105 of file yacy.py.

105def init(_):
106 valid_types = [
107 'text',
108 'image',
109 # 'app', 'audio', 'video',
110 ]
111 if search_type not in valid_types:
112 raise ValueError('search_type "%s" is not one of %s' % (search_type, valid_types))
113
114

◆ request()

searx.engines.yacy.request ( query,
params )

Definition at line 124 of file yacy.py.

124def request(query, params):
125
126 offset = (params['pageno'] - 1) * number_of_results
127 args = {
128 'query': query,
129 'startRecord': offset,
130 'maximumRecords': number_of_results,
131 'contentdom': search_type,
132 'resource': search_mode,
133 }
134
135 # add language tag if specified
136 if params['language'] != 'all':
137 args['lr'] = 'lang_' + params['language'].split('-')[0]
138
139 params["url"] = f"{_base_url()}/yacysearch.json?{urlencode(args)}"
140
141 if http_digest_auth_user and http_digest_auth_pass:
142 params['auth'] = DigestAuth(http_digest_auth_user, http_digest_auth_pass)
143
144 return params
145
146

◆ response()

searx.engines.yacy.response ( resp)

Definition at line 147 of file yacy.py.

147def response(resp):
148 results = []
149
150 raw_search_results = loads(resp.text)
151
152 # return empty array if there are no results
153 if not raw_search_results:
154 return []
155
156 search_results = raw_search_results.get('channels', [])
157
158 if len(search_results) == 0:
159 return []
160
161 for result in search_results[0].get('items', []):
162 # parse image results
163 if search_type == 'image':
164 result_url = ''
165 if 'url' in result:
166 result_url = result['url']
167 elif 'link' in result:
168 result_url = result['link']
169 else:
170 continue
171
172 # append result
173 results.append(
174 {
175 'url': result_url,
176 'title': result['title'],
177 'content': '',
178 'img_src': result['image'],
179 'template': 'images.html',
180 }
181 )
182
183 # parse general results
184 else:
185 publishedDate = None
186 if 'pubDate' in result:
187 publishedDate = parser.parse(result['pubDate'])
188
189 # append result
190 results.append(
191 {
192 'url': result['link'] or '',
193 'title': result['title'],
194 'content': html_to_text(result['description']),
195 'publishedDate': publishedDate,
196 }
197 )
198
199 # TODO parse video, audio and file results
200
201 return results

Variable Documentation

◆ about

dict searx.engines.yacy.about
Initial value:
1= {
2 "website": 'https://yacy.net/',
3 "wikidata_id": 'Q1759675',
4 "official_api_documentation": 'https://wiki.yacy.net/index.php/Dev:API',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 66 of file yacy.py.

◆ base_url

list searx.engines.yacy.base_url = 'https://yacy.searchlab.eu'

Definition at line 99 of file yacy.py.

◆ categories

list searx.engines.yacy.categories = ['general']

Definition at line 76 of file yacy.py.

◆ http_digest_auth_pass

str searx.engines.yacy.http_digest_auth_pass = ""

Definition at line 81 of file yacy.py.

◆ http_digest_auth_user

str searx.engines.yacy.http_digest_auth_user = ""

Definition at line 79 of file yacy.py.

◆ number_of_results

int searx.engines.yacy.number_of_results = 10

Definition at line 78 of file yacy.py.

◆ paging

bool searx.engines.yacy.paging = True

Definition at line 77 of file yacy.py.

◆ search_mode

str searx.engines.yacy.search_mode = 'global'

Definition at line 84 of file yacy.py.

◆ search_type

str searx.engines.yacy.search_type = 'text'

Definition at line 94 of file yacy.py.