summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2024-03-06 08:18:24 +0100
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-03-06 12:33:29 +0100
commit3529f0af504d1cf9278a08af64a052950ede4c10 (patch)
treed26e49303ca96abf3287e75a5b227d4e989e8df5
parent76b18545e41ae88b00e80af590b7e27e87b16cb1 (diff)
downloadsearxng-3529f0af504d1cf9278a08af64a052950ede4c10.tar.gz
searxng-3529f0af504d1cf9278a08af64a052950ede4c10.zip
[fix] engine searchcode.com - paging is broken in searchcode.com's API
paging is broken in searchcode.com's API .. not sure it will ever been fixed / this commit disables paging in the engine and BTW pylint `searchcode_code.py`. Closes: https://github.com/searxng/searxng/issues/3287 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
-rw-r--r--searx/engines/searchcode_code.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/searx/engines/searchcode_code.py b/searx/engines/searchcode_code.py
index a4b0308f9..a53c72094 100644
--- a/searx/engines/searchcode_code.py
+++ b/searx/engines/searchcode_code.py
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
-"""
- Searchcode (IT)
+# lint: pylint
+"""Searchcode (IT)
+
"""
from json import loads
@@ -18,24 +19,29 @@ about = {
# engine dependent config
categories = ['it']
-paging = True
-
-# search-url
-url = 'https://searchcode.com/'
-search_url = url + 'api/codesearch_I/?{query}&p={pageno}'
+search_api = 'https://searchcode.com/api/codesearch_I/?'
# special code-endings which are not recognised by the file ending
code_endings = {'cs': 'c#', 'h': 'c', 'hpp': 'cpp', 'cxx': 'cpp'}
+# paging is broken in searchcode.com's API .. not sure it will ever been fixed
+# paging = True
-# do search-request
-def request(query, params):
- params['url'] = search_url.format(query=urlencode({'q': query}), pageno=params['pageno'] - 1)
+def request(query, params):
+ args = urlencode(
+ {
+ 'q': query,
+ # paging is broken in searchcode.com's API
+ # 'p': params['pageno'] - 1,
+ # 'per_page': 10,
+ }
+ )
+ params['url'] = search_api + args
+ logger.debug("query_url --> %s", params['url'])
return params
-# get response from search-request
def response(resp):
results = []
@@ -47,7 +53,7 @@ def response(resp):
title = "" + result['name'] + " - " + result['filename']
repo = result['repo']
- lines = dict()
+ lines = {}
for line, code in result['lines'].items():
lines[int(line)] = code