Search abstraction layer
Project description
Salinic
Salinic - provides modular search. It features a unified API that allows you to plug in different search backends. Currently, it supports Xapian and Solr backends.
Usage
Declare your search schema:
from typing import Optional
from typing_extensions import Annotated
from salinic.field import IdField, KeywordField, TextField
from salinic.schema import Schema
class MyModel(Schema):
"""Index schema"""
id: Annotated[str, IdField(primary_key=True)]
user_id: str
parent_id: str
title: Annotated[str, TextField()]
text: Annotated[Optional[str], TextField()] = None
tags: Annotated[Optional[list[str]], KeywordField()] = []
Index your documents:
from salinic import IndexRW, create_engine
engine = create_engine("xapian:////search_index")
index = IndexRW(engine, schema=MyModel)
for document in all_your_documents():
model = MyModel(
id=str(document.id),
user_id=str(document.user_id),
parent_id=document.parent_id,
title=document.title,
text=document.text,
tags=document.tags
)
index.add(model)
Search your documents:
from salinic import IndexRO, create_engine
engine = create_engine("xapian:////search_index")
index = IndexRO(engine, schema=MyModel)
sq = Search(MyModel).query(" your query string ")
for found in index.search(sq):
print(found) # found is instance of MyModel
The only modification of your for changing to different search
engine backend, is the first argument of the create_engine
method e.g. from
"xapian:////search_index" to "solr://localhost:8983/my-index-name".
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
salinic-0.6.0.tar.gz
(14.8 kB
view details)
Built Distribution
salinic-0.6.0-py3-none-any.whl
(19.7 kB
view details)
File details
Details for the file salinic-0.6.0.tar.gz
.
File metadata
- Download URL: salinic-0.6.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9db7e889178874a4d808bde01f2a82282af13861afa6ffdf9dea54366dffd72 |
|
MD5 | 794946d4f6629244f3e66ec67b5da79a |
|
BLAKE2b-256 | da273a93902776c65a6f30bc0a7dff24d491f72027a3089f8b6af744ae580b3d |
File details
Details for the file salinic-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: salinic-0.6.0-py3-none-any.whl
- Upload date:
- Size: 19.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2e1e4e30a207f351856d13ab580b4d0b7f6afd498a2e8b0340ead05375628a2 |
|
MD5 | ce5c3ada0a0e4bc220ebd89715b4f1cd |
|
BLAKE2b-256 | 2255843d4bd8f82b57e0b0d7b2d7882625a5c3fc88f817f49a6e0414e75b8d24 |