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

Functions

 init (_)
 
 request (query, params)
 
 response (resp)
 
 __get_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

◆ __get_response()

searx.engines.solr.__get_response ( resp)
private

Definition at line 89 of file solr.py.

89def __get_response(resp):
90 try:
91 resp_json = loads(resp.text)
92 except Exception as e:
93 raise SearxEngineAPIException("failed to parse response") from e
94
95 if 'error' in resp_json:
96 raise SearxEngineAPIException(resp_json['error']['msg'])
97
98 return resp_json

Referenced by searx.engines.solr.response().

+ Here is the caller graph for this function:

◆ init()

searx.engines.solr.init ( _)

Definition at line 48 of file solr.py.

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

◆ request()

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

Definition at line 56 of file solr.py.

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

◆ response()

searx.engines.solr.response ( resp)

Definition at line 75 of file solr.py.

75def response(resp):
76 resp_json = __get_response(resp)
77
78 results = []
79 for result in resp_json['response']['docs']:
80 r = {key: str(value) for key, value in result.items()}
81 if len(r) == 0:
82 continue
83 r['template'] = 'key-value.html'
84 results.append(r)
85
86 return results
87
88

References searx.engines.solr.__get_response().

+ Here is the call graph for this function:

Variable Documentation

◆ _search_url

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

Definition at line 44 of file solr.py.

◆ base_url

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

Definition at line 37 of file solr.py.

◆ collection

str searx.engines.solr.collection = ''

Definition at line 38 of file solr.py.

◆ default_fields

str searx.engines.solr.default_fields = ''

Definition at line 42 of file solr.py.

◆ field_list

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

Definition at line 41 of file solr.py.

◆ paging

bool searx.engines.solr.paging = True

Definition at line 45 of file solr.py.

◆ query_fields

str searx.engines.solr.query_fields = ''

Definition at line 43 of file solr.py.

◆ rows

int searx.engines.solr.rows = 10

Definition at line 39 of file solr.py.

◆ sort

str searx.engines.solr.sort = ''

Definition at line 40 of file solr.py.