Skip to content

Commit

Permalink
[feat] engine: implementation of stract (beta)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro authored and dalf committed Jan 7, 2024
1 parent 2f7c800 commit 621e131
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
43 changes: 43 additions & 0 deletions searx/engines/stract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# lint: pylint
"""Stract is an independent open source search engine.
At this state, it's still in beta and hence this implementation will need to be updated once beta ends.
"""

from json import dumps

about = {
"website": "https://stract.com/",
"use_official_api": True,
"official_api_documentation": "https://stract.com/beta/api/docs/#/search/api",
"require_api_key": False,
"results": "JSON",
}
categories = ['general']
paging = True

search_url = "https://stract.com/beta/api/search"


def request(query, params):
params['url'] = search_url
params['method'] = "POST"
params['headers'] = {'Accept': 'application/json', 'Content-Type': 'application/json'}
params['data'] = dumps({'query': query, 'page': params['pageno'] - 1})

return params


def response(resp):
results = []

for result in resp.json()["webpages"]:
results.append(
{
'url': result['url'],
'title': result['title'],
'content': ''.join(fragment['text'] for fragment in result['snippet']['text']['fragments']),
}
)

return results
5 changes: 5 additions & 0 deletions searx/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2079,6 +2079,11 @@ engines:
timeout: 5.0
disabled: true

- name: stract
engine: stract
shortcut: str
disabled: true

- name: svgrepo
engine: svgrepo
shortcut: svg
Expand Down

0 comments on commit 621e131

Please sign in to comment.