aiosolr
AsyncIO Python client for Apache Solr
Requirements
This project requires Python 3.6+
Installation
To install with pip
pip install aiosolr
Usage
The connection to the Solr backend is defined during object initialization. The accepted kwargs to init are scheme, host, port, collection, and timeout.
Note: collection may also be passed at query time
import aiosolr
solr = aiosolr.Solr(host=localhost, collection="example", port=8983)
Once you have your Solr instance, there are methods available for querying.
You can use Solr's built-in get handler with the get method like:
solr.get(document_id)
to retrieve a single document.
You can use a pre-defined suggestions handler by using the suggestions method like:
solr.suggestions("suggest_handler", query="asdf")
You can also use the suggestions method to build your suggestions like:
solr.suggestions("suggest_handler", build=True)
Note: handler is a required argument for suggestions unlike for get or query
You can use the query method to query your search handler. The default handler used is "select". If you would like spellcheck suggestion turned on, pass spellcheck=True (default is False).
solr.query(handler="my_handler", query="asdf", spellcheck=True)
If spellcheck is True the query method returns a tuple with the first element being an array of documents and the 2nd element being an array of spellcheck suggestions. Otherwise, the query method returns a simple array of documents.
You can use the update method to access Solr's built-in update handler like:
solr.update(my_data)
At any point that you need to commit data to your collection you can use the commit method. Arguments should be the "handler" ("update" by default) and "soft" as a boolean indicating whether it should be a hard or soft commit (defaults to False).
There is one more method you might want to use before querying Solr especially if the query is coming from an untrusted end user. There is a clean method which can be used to strip out unwanted characters. The function signature allows the following arguments:
@staticmethod
def clean(
query, # end user query
allow_html_tags=False,
allow_http=False,
allow_wildcard=False,
escape_chars=(":", r"\:"), # tuple of (replace_me, replace_with)
max_len=200,
remove_chars=r'[\&\|\!\(\)\{\}\[\]\^"~\?\\\*]', # regex of chars to remove
):
Once you are finished with the Solr instance, you should call the method close to cleanup sessions like:
await solr.close()
Release files for aiosolr 3.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiosolr-3.1.1.tar.gz | 6.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiosolr-3.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.1 kB
Release files / aiosolr-3.1.1.tar.gz
| Download URL | aiosolr-3.1.1.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
87923ae6a4493089ba17428f819193e2d7462f8033fb9743eda05305e18abcb7
|
|
BLAKE2b-256 checksum How to use checksums |
4a501737f1d3759ca4c1a86e11f9832a2384cff33b04d967c550004bb8fc039b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.4
|
Release files / aiosolr-3.1.1-py3-none-any.whl
| Download URL | aiosolr-3.1.1-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6413cc281af89253cb0df4d01a9b0b63e04ac244168c135c2bbf21e84d93c3b4
|
|
BLAKE2b-256 checksum How to use checksums |
5c3084804ca4e8cf294b4f5a0de23b0de74f659e0955b2196148d2dd2566240d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.4
|