logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://anongit.hacktivis.me/git/searx.git/

searx_engine.py (1264B)


  1. """
  2. Searx (all)
  3. @website https://github.com/asciimoo/searx
  4. @provide-api yes (https://asciimoo.github.io/searx/dev/search_api.html)
  5. @using-api yes
  6. @results JSON
  7. @stable yes (using api)
  8. @parse url, title, content
  9. """
  10. from json import loads
  11. from searx.engines import categories as searx_categories
  12. categories = searx_categories.keys()
  13. # search-url
  14. instance_urls = []
  15. instance_index = 0
  16. # do search-request
  17. def request(query, params):
  18. global instance_index
  19. params['url'] = instance_urls[instance_index % len(instance_urls)]
  20. params['method'] = 'POST'
  21. instance_index += 1
  22. params['data'] = {
  23. 'q': query,
  24. 'pageno': params['pageno'],
  25. 'language': params['language'],
  26. 'time_range': params['time_range'],
  27. 'category': params['category'],
  28. 'format': 'json'
  29. }
  30. return params
  31. # get response from search-request
  32. def response(resp):
  33. response_json = loads(resp.text)
  34. results = response_json['results']
  35. for i in ('answers', 'infoboxes'):
  36. results.extend(response_json[i])
  37. results.extend({'suggestion': s} for s in response_json['suggestions'])
  38. results.append({'number_of_results': response_json['number_of_results']})
  39. return results