forked from Icycoide/searxng
Change plugin API :
- pre_search(request, search) - post_search(request, search) - on_result(request, search, result) with - request is the Flask request - search a searx.Search instance - result a searx result as usual
This commit is contained in:
parent
67e11c42b9
commit
fbb080f358
6 changed files with 54 additions and 67 deletions
|
@ -28,19 +28,19 @@ p = re.compile('.*user[ -]agent.*', re.IGNORECASE)
|
|||
# attach callback to the post search hook
|
||||
# request: flask request object
|
||||
# ctx: the whole local context of the pre search hook
|
||||
def post_search(request, ctx):
|
||||
if ctx['search'].pageno > 1:
|
||||
def post_search(request, search):
|
||||
if search.search_query.pageno > 1:
|
||||
return True
|
||||
if ctx['search'].query == 'ip':
|
||||
if search.search_query.query == 'ip':
|
||||
x_forwarded_for = request.headers.getlist("X-Forwarded-For")
|
||||
if x_forwarded_for:
|
||||
ip = x_forwarded_for[0]
|
||||
else:
|
||||
ip = request.remote_addr
|
||||
ctx['result_container'].answers.clear()
|
||||
ctx['result_container'].answers.add(ip)
|
||||
elif p.match(ctx['search'].query):
|
||||
search.result_container.answers.clear()
|
||||
search.result_container.answers.add(ip)
|
||||
elif p.match(search.search_query.query):
|
||||
ua = request.user_agent
|
||||
ctx['result_container'].answers.clear()
|
||||
ctx['result_container'].answers.add(ua)
|
||||
search.result_container.answers.clear()
|
||||
search.result_container.answers.add(ua)
|
||||
return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue