Skip to main content

Search abstraction layer

Project description

Tests

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


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.5.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

salinic-0.3.5-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file salinic-0.3.5.tar.gz.

File metadata

  • Download URL: salinic-0.3.5.tar.gz
  • Upload date:
  • Size: 13.4 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

Hashes for salinic-0.3.5.tar.gz
Algorithm Hash digest
SHA256 99f5adf06df65951c6c7e14cab3d1482ec16c5dc7c60083ee6ee3256b6a1808a
MD5 58e0d2831c305905f027cf2a5d8dd6d0
BLAKE2b-256 0c4efd0eb868044e775758cb91f1ad9386908c82583a0e2a8e83dd51e2c33a91

See more details on using hashes here.

File details

Details for the file salinic-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: salinic-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 18.1 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

Hashes for salinic-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ccffccb49aa1d8c1f93c7761fd55a65a57f53734de8e79c4f106432cc1cf4430
MD5 be9dbf4c2723628f03add20fb2be630a
BLAKE2b-256 dc4ba83f3d58c1b735eda1f29c61345631e332ef6a2f79584fbc3c7d20056b98

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page