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

Uploaded Source

Built Distribution

salinic-0.6.1-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: salinic-0.6.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.1 Linux/6.5.0-1025-azure

File hashes

Hashes for salinic-0.6.1.tar.gz
Algorithm Hash digest
SHA256 b88181ce18fa1a434aa39d1b7d96387605e6610c4cda681a03e9bab2a77547e9
MD5 37f977d4b4ccc4dd99481dc27e6ae2a8
BLAKE2b-256 f2562a3cdf342aa8c0ed272a048686819f441439eef7dc79d352e9dfd24fa941

See more details on using hashes here.

File details

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

File metadata

  • Download URL: salinic-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.13.1 Linux/6.5.0-1025-azure

File hashes

Hashes for salinic-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 01db1d2861b4fc8b4bf8e451553668479bd229eca4090155e9c760344080ebea
MD5 2d89649a1bd44403de59ebd82fa4d08d
BLAKE2b-256 147a865ebda332f8a6e2e9dd74827174b14c8b5b149c77a3a5f7ca2907265fd6

See more details on using hashes here.

Supported by

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