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.3.6.tar.gz
(13.5 kB
view details)
Built Distribution
salinic-0.3.6-py3-none-any.whl
(18.2 kB
view details)
File details
Details for the file salinic-0.3.6.tar.gz
.
File metadata
- Download URL: salinic-0.3.6.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.4 Linux/5.15.0-1041-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf884a48bf517fa730088ccc003c3c60226012f1406908dc64ddd830785904d7 |
|
MD5 | f72d04b2cb9f58ad9b65fe81e98282cd |
|
BLAKE2b-256 | d9a06ef8193c0bb3a17393922882e4cb527d2dc84a44a8a76fe7298d87d4730d |
File details
Details for the file salinic-0.3.6-py3-none-any.whl
.
File metadata
- Download URL: salinic-0.3.6-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.4 Linux/5.15.0-1041-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a8148f0154f326e67eeac0b67ab246e20520305eae5758307d778a8f6011576 |
|
MD5 | 9f2db2b10930d04abd1f96b438af1ee1 |
|
BLAKE2b-256 | b5b01145b50d66f296487104701dbc9b57149f1058a12ff5fbf0856b5ca38eb7 |