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

Functions

 init (_)
 
 request (query, params)
 
EngineResults response (SXNG_Response resp)
 

Variables

str base_url = 'http://localhost:8983'
 
str collection = ''
 
int rows = 10
 
str sort = ''
 
str field_list = 'name'
 
str default_fields = ''
 
str query_fields = ''
 
str _search_url = ''
 
bool paging = True
 

Detailed Description

.. sidebar:: info

   - :origin:`solr.py <searx/engines/solr.py>`
   - `Solr <https://solr.apache.org>`_
   - `Solr Resources <https://solr.apache.org/resources.html>`_
   - `Install Solr <https://solr.apache.org/guide/installing-solr.html>`_

Solr_ is a popular search engine based on Lucene, just like Elasticsearch_.  But
instead of searching in indices, you can search in collections.

Example
=======

This is an example configuration for searching in the collection
``my-collection`` and get the results in ascending order.

.. code:: yaml

  - name: solr
    engine: solr
    shortcut: slr
    base_url: http://localhost:8983
    collection: my-collection
    sort: asc
    enable_http: true

Function Documentation

◆ init()

searx.engines.solr.init ( _)

Definition at line 49 of file solr.py.

49def init(_):
50 if collection == '':
51 raise ValueError('collection cannot be empty')
52
53 global _search_url
54 _search_url = base_url + '/solr/' + collection + '/select?{params}'
55
56

◆ request()

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

Definition at line 57 of file solr.py.

57def request(query, params):
58 query_params = {'q': query, 'rows': rows}
59 if field_list != '':
60 query_params['fl'] = field_list
61 if query_fields != '':
62 query_params['qf'] = query_fields
63 if default_fields != '':
64 query_params['df'] = default_fields
65 if sort != '':
66 query_params['sort'] = sort
67
68 if 'pageno' in params:
69 query_params['start'] = rows * (params['pageno'] - 1)
70
71 params['url'] = _search_url.format(params=urlencode(query_params))
72
73 return params
74
75

◆ response()

EngineResults searx.engines.solr.response ( SXNG_Response resp)

Definition at line 76 of file solr.py.

76def response(resp: SXNG_Response) -> EngineResults:
77 try:
78 resp_json = resp.json()
79 except Exception as e:
80 raise SearxEngineAPIException("failed to parse response") from e
81
82 if "error" in resp_json:
83 raise SearxEngineAPIException(resp_json["error"]["msg"])
84
85 res = EngineResults()
86
87 for result in resp_json["response"]["docs"]:
88 kvmap = {key: str(value) for key, value in result.items()}
89 if not kvmap:
90 continue
91 res.add(res.types.KeyValue(kvmap=kvmap))
92
93 return res

Variable Documentation

◆ _search_url

str searx.engines.solr._search_url = ''
protected

Definition at line 45 of file solr.py.

◆ base_url

str searx.engines.solr.base_url = 'http://localhost:8983'

Definition at line 38 of file solr.py.

◆ collection

str searx.engines.solr.collection = ''

Definition at line 39 of file solr.py.

◆ default_fields

str searx.engines.solr.default_fields = ''

Definition at line 43 of file solr.py.

◆ field_list

str searx.engines.solr.field_list = 'name'

Definition at line 42 of file solr.py.

◆ paging

bool searx.engines.solr.paging = True

Definition at line 46 of file solr.py.

◆ query_fields

str searx.engines.solr.query_fields = ''

Definition at line 44 of file solr.py.

◆ rows

int searx.engines.solr.rows = 10

Definition at line 40 of file solr.py.

◆ sort

str searx.engines.solr.sort = ''

Definition at line 41 of file solr.py.