https://github.com/factorysh/aio-sonic-rest
REST API for Sonic search daemon
https://github.com/factorysh/aio-sonic-rest
aio sonic
Last synced: 4 months ago
JSON representation
REST API for Sonic search daemon
- Host: GitHub
- URL: https://github.com/factorysh/aio-sonic-rest
- Owner: factorysh
- License: bsd-3-clause
- Created: 2019-12-28T20:49:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-12-24T13:01:44.000Z (over 5 years ago)
- Last Synced: 2024-04-21T00:58:32.935Z (about 2 years ago)
- Topics: aio, sonic
- Language: Python
- Homepage:
- Size: 72.3 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
AIO Sonic REST
==============
REST API for [Sonic](https://github.com/valeriansaliou/sonic) daemon.
It uses aiohttp, and documents are stored raw, read with mmap.
It's fast and doesn't eat all your memory.
Usage
-----
Index
```python
i = Ingestor(
dict(
name=dict(stored=True),
body=dict(indexed=True),
tags=dict(stored=True, indexed=True,),
),
password="iuNg5Ri6daik2fe2Phoo6aig",
path="./data/store/collection",
)
i.reset()
documents = [
dict(name="alice", body="Elle a mangé des carottes.", tags=["carotte"]),
dict(name="bob", body="Il fait du Django.", tags=["python", "django"]),
dict(name="charly", body="Il a un python dans son vivarium.", tags=[]),
]
i.ingest(documents)
```
Search
```python
s = Search("./data/store/collection", password="iuNg5Ri6daik2fe2Phoo6aig")
size, results = await s.search("python", ["tags", "body"])
```
Rest it
```python
app = web.Application()
sonic_rest(app, s)
```
Query it
```python
resp = await client.get("/query?q=python")
resp = await client.get("/suggest?s=car")
```
All this code are in test files.
Tests
-----
Start the sonic daemon
docker-compose up -d
Run tests
pytest
Or, simpler:
make test
Licence
-------
3 terms BSD licence, ©2019 Mathieu Lecarme