Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smartmonkey-git/py-toshi-client
Python Client for the Full-Text Search Engine Toshi
https://github.com/smartmonkey-git/py-toshi-client
client elasticsearch python search-engine
Last synced: about 1 month ago
JSON representation
Python Client for the Full-Text Search Engine Toshi
- Host: GitHub
- URL: https://github.com/smartmonkey-git/py-toshi-client
- Owner: SmartMonkey-git
- License: mit
- Created: 2024-06-05T10:39:48.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-07-02T08:20:14.000Z (5 months ago)
- Last Synced: 2024-10-11T22:04:29.119Z (about 1 month ago)
- Topics: client, elasticsearch, python, search-engine
- Language: Python
- Homepage: https://pypi.org/project/toshi-client/
- Size: 85.9 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Toshi Python Client
This repository is a client for the [Full-Text Search Engine Toshi](https://github.com/toshi-search/Toshi). It allows you to use all features implemented in the Toshi engine.### How to install
The client is available as a package on [Pypi](https://pypi.org/project/toshi-client/) and can be installed via:
```shell
pip install toshi-client
```### Examples
For a full set of examples check out the [integration tests](https://github.com/SmartMonkey-git/py-toshi-client/blob/main/tests/test_integration_sync.py).Here is a basic example:
1. Create an index and submit it
```python
from toshi_client.client import ToshiClient
from toshi_client.index.index_builder import IndexBuilder
from toshi_client.index.field_options import TextOptionIndexingbuilder = IndexBuilder()
builder.add_text_field(name="lyrics", stored=True, indexing=TextOptionIndexing())
builder.add_i64_field(name="year", stored=True, indexed=True)
builder.add_u64_field(name="idx", stored=True, indexed=True)
builder.add_text_field(name="artist", stored=True, indexing=TextOptionIndexing())
builder.add_text_field(name="genre", stored=True, indexing=TextOptionIndexing())
builder.add_text_field(name="song", stored=True, indexing=TextOptionIndexing())
builder.add_facet_field(name="test_facet", stored=True)index = builder.build("lyrics")
client = ToshiClient("http://localhost:8080")
client.create_index(index=index)
```2. Create a document class according to the just created index
```python
from toshi_client.models.document import Documentclass Lyrics(Document):
@staticmethod
def index_name() -> str:
return "lyrics"def __init__(
self,
lyrics: str,
year: int,
idx: int,
artist: str,
genre: str,
song: str,
):
self.lyrics = lyrics
self.year = year
self.idx = idx
self.artist = artist
self.genre = genre
self.song = song
```
3. Submit a document to Toshi```python
doc = Lyrics(
lyrics="Gold on the ceiling, I ain't blind, just a matter of time",
year=2011,
idx=2,
artist="The Black Keys",
genre="Rock",
song="Gold on the Ceiling",
)
client.add_document(document=doc)
```
4. Use a query of your choice to retrieve it```python
from toshi_client.query.term_query import TermQueryquery = TermQuery(term="ceiling", field_name="lyrics")
documents = client.search(query, Lyrics)
```