Skip to main content

Django integration for Manticore Search

Project description

Django Manticoresearch

Django integration for Manticore Search engine.

Installation

pip install django-manticoresearch

Configuration

Add django_manticoresearch to your INSTALLED_APPS in settings.py:

INSTALLED_APPS = [
    # ...
    'django_manticoresearch',
    # ...
]

Configure Manticore connection settings:

MANTICORE_SCHEMA = "http"
MANTICORE_HOST = "localhost"
MANTICORE_PORT = 9308

Basic Usage

Define Indices

You can define indices using two different styles:

Style 1: Tuple-based field definitions

from django_manticoresearch import ManticoreIndex, TextField, BigintField, index_registry
from myapp.models import Post

@index_registry.register
class PostIndex(ManticoreIndex):
    _index_name = "posts"
    model = Post
    
    fields = (
        TextField("title"),
        TextField("content"),
        BigintField("views"),
    )
    
    # Optional field weights for relevance scoring
    field_weights = {
        "title": 10,
        "content": 5,
    }

Style 2: Class attribute field definitions

from django_manticoresearch import ManticoreIndex, CharField, IntegerField, BooleanField
from myapp.models import Post

class PostIndex(ManticoreIndex):
    title = CharField()
    content = CharField()
    views = IntegerField()
    is_published = BooleanField(default=False)
    
    class Meta:
        index_name = 'posts'
        model = Post

Field Definitions

The following field types are available for defining index fields:

class PostIndex(ManticoreIndex):
    # Field definition in the fields tuple
    fields = (
        # Text fields for full-text search
        TextField("title"),
        TextField("content"),
        
        # Numeric fields
        IntegerField("category_id"),
        BigintField("views"),
        
        # Boolean field
        BooleanField("is_published"),
        
        # Date/time field
        DateTimeField("publication_date"),
        
        # String field (for exact match, not full-text)
        StringField("slug"),
        
        # Multi-value array field
        MVAField("tags"),
    )

Auto-Discovery of Indices

By default, django-manticoresearch automatically discovers and registers indices from all installed apps. The package looks for index definitions in these files:

  1. <app_name>/indexes.py
  2. <app_name>/indices.py

To use auto-discovery:

  1. Create one of these files in your Django app
  2. Define your ManticoreIndex classes in that file
  3. No manual registration is needed

Example app structure:

myapp/
  ├── models.py
  ├── views.py
  └── indexes.py  # Your ManticoreIndex definitions go here

You can disable auto-discovery by setting MANTICORE_AUTO_REGISTER_MODELS to False in your Django settings:

MANTICORE_AUTO_REGISTER_MODELS = False  # Default is True

If you disable auto-discovery, you'll need to manually register your indices:

from django_manticoresearch import index_registry

@index_registry.register
class MyIndex(ManticoreIndex):
    # Your index definition...

Searching

# Initialize the index
index = PostIndex()

# Basic search
results = index.search("query text")

# Advanced search with options
results = index.search(
    query="query text",
    match_fields=["title", "content"],
    enable_wildcard_search=True,
    infix_search=True
)

# Convert results to Django QuerySet
queryset = index.search_result_to_queryset(results)

Auto-Indexing

The package automatically connects signals to update indices when model instances are created, updated, or deleted.

Management Commands

Create all indices:

python manage.py indexing

Create indices for a specific app:

python manage.py indexing --app=myapp

Create indices and index all objects:

python manage.py indexing --reindex

Drop existing indices before creating:

python manage.py indexing --recreate

Features

  • Django ORM-like interface for Manticore search
  • Advanced search with wildcards, prefix, infix and full-text search
  • Automatic index management with Django signals
  • Field type validation and transformation
  • Rich query builder API
  • Highlighting support
  • Support for complex data structures

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

django_manticoresearch-0.2.0.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_manticoresearch-0.2.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file django_manticoresearch-0.2.0.tar.gz.

File metadata

  • Download URL: django_manticoresearch-0.2.0.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for django_manticoresearch-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c578a8d8a738a9a0f489507b48b9ea583ad7575a4457b0eb0adfad6d2649f919
MD5 89cea0393de705843cc37a226ccc4314
BLAKE2b-256 e8f9936fc35f5a00292580cdbc48fd29824a3b1edfadb03c041cbbc32b6c4e6d

See more details on using hashes here.

File details

Details for the file django_manticoresearch-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_manticoresearch-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df422e86c1ac21c7c87492c6ee1afb2b82bbb19f76d78c2d0e805023a8b737d6
MD5 435fe1f26ebf088c81a1baef6382d398
BLAKE2b-256 98fa075652a7f3407389701a0e0f310cf5ab6420128cbf715d60403c1a129a14

See more details on using hashes here.

Supported by

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