litestar-pydotorg
  • Litestar
  • Python.org
/

Learn

  • Getting Started
    • Installation
    • Quickstart
  • Guides
    • Development Guide
    • Contribution Guide
    • Testing Guide
    • Debugging Guide
    • API Usage Guide
    • Authentication Guide
    • Feature Flags
    • Configuration Guide
    • Deployment Guide
    • Docker Guide
    • Troubleshooting Guide
  • Cookbook
    • Domain Patterns
    • Authentication Recipes
    • Database Recipes
    • Testing Recipes

Reference

  • API Reference
    • Core Infrastructure
      • Authentication
      • Caching
      • Database
      • Email
      • Exceptions
      • Feature Flags
      • RSS/Atom Feeds
      • iCalendar
      • Logging
      • Middleware
      • OpenAPI
      • Rate Limiting
      • Search
      • Security
      • Background Worker
    • Domain Modules
      • About
      • Admin
      • banners
      • blogs
      • Code Samples
      • community
      • Documentation
      • downloads
      • events
      • jobs
      • Mailing Lists
      • Minutes
      • Nominations
      • pages
      • Search
      • sponsors
      • SQLAdmin
      • Success Stories
      • users
      • Work Groups
    • Library Utilities
    • Background Tasks
    • Configuration
    • Application Entry Point
  • Architecture
    • Litestar Python.org Architecture
    • Database Schema Design
    • Domain Models Reference
    • Litestar Python.org Quick Start Guide
    • API Tags Documentation Index
    • Rate Limiting Architecture Design
    • ADR-001: Use Litestar as Web Framework
    • ADR-002: Use SAQ for Background Task Processing
  • Changelog

Project

  • GitHub

On this page

  • Module Contents
    • IndexedDocument
      • model_config
      • id
      • title
      • description
      • content
      • url
      • content_type
      • created
      • modified
      • status
      • tags
      • searchable_text
    • SearchQuery
      • model_config
      • query
      • indexes
      • filters
      • limit
      • offset
      • attributes_to_retrieve
      • attributes_to_highlight
    • SearchResult
      • model_config
      • hits
      • total
      • offset
      • limit
      • processing_time_ms
      • query
    • SearchService
      • __init__()
      • clear_index()
      • client
      • close()
      • configure_index()
      • create_index()
      • delete_documents()
      • delete_index()
      • get_index_stats()
      • index_documents()
      • is_available()
      • search()
      • update_documents()
  • Schemas
    • SearchQuery
      • query
      • indexes
      • filters
      • limit
      • offset
      • attributes_to_retrieve
      • attributes_to_highlight
      • model_config
    • SearchHit
      • id
      • index
      • title
      • description
      • url
      • content_type
      • created
      • modified
      • highlight
      • extra
      • model_config
    • SearchResult
      • hits
      • total
      • offset
      • limit
      • processing_time_ms
      • query
      • model_config
    • IndexedDocument
      • id
      • title
      • description
      • content
      • url
      • content_type
      • created
      • modified
      • status
      • tags
      • searchable_text
      • model_config
    • JobDocument
      • content_type
      • company_name
      • location
      • remote
      • job_types
      • model_config
    • EventDocument
      • content_type
      • venue
      • location
      • start_date
      • end_date
      • model_config
    • BlogDocument
      • content_type
      • author
      • published
      • model_config
    • PageDocument
      • content_type
      • path
      • model_config
  • Service
    • SearchService
      • __init__()
      • client
      • close()
      • create_index()
      • delete_index()
      • configure_index()
      • index_documents()
      • update_documents()
      • delete_documents()
      • clear_index()
      • is_available()
      • search()
      • get_index_stats()
  1. litestar-pydotorg /
  2. API Reference /
  3. Core Infrastructure /
  4. Search

Search¶

Full-text search infrastructure.

Module Contents¶

Search functionality using Meilisearch.

class IndexedDocument[source]¶

Bases: BaseModel

Base schema for indexed documents in Meilisearch.

model_config: ClassVar[ConfigDict] = {}¶

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

id: str¶
title: str¶
description: str | None¶
content: str | None¶
url: str¶
content_type: str¶
created: datetime | None¶
modified: datetime | None¶
status: str | None¶
tags: list[str]¶
searchable_text: str | None¶
class SearchQuery[source]¶

Bases: BaseModel

Search query parameters.

model_config: ClassVar[ConfigDict] = {}¶

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

query: str¶
indexes: list[str] | None¶
filters: dict[str, Any] | None¶
limit: int¶
offset: int¶
attributes_to_retrieve: list[str] | None¶
attributes_to_highlight: list[str] | None¶
class SearchResult[source]¶

Bases: BaseModel

Search results response.

model_config: ClassVar[ConfigDict] = {}¶

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

hits: list[SearchHit]¶
total: int¶
offset: int¶
limit: int¶
processing_time_ms: int¶
query: str¶
class SearchService[source]¶

Bases: object

Service for interacting with Meilisearch.

__init__(url, api_key=None, index_prefix='pydotorg_')[source]¶

Initialize the Meilisearch service.

Parameters:
  • url (str) – Meilisearch server URL.

  • api_key (str | None) – Optional API key for authentication.

  • index_prefix (str) – Prefix for all index names.

async clear_index(index)[source]¶

Clear all documents from an index.

Parameters:

index (str) – Base index name.

Return type:

TaskInfo

Returns:

Task information for the clear operation.

property client: meilisearch_python_sdk.AsyncClient¶

Get or create the Meilisearch async client.

async close()[source]¶

Close the Meilisearch client connection.

Return type:

None

async configure_index(index, searchable_attributes=None, filterable_attributes=None, sortable_attributes=None, ranking_rules=None)[source]¶

Configure index settings.

Parameters:
  • index (str) – Base index name.

  • searchable_attributes (list[str] | None) – Fields to search in (order matters for ranking).

  • filterable_attributes (list[str] | None) – Fields that can be used in filters.

  • sortable_attributes (list[str] | None) – Fields that can be used for sorting.

  • ranking_rules (list[str] | None) – Custom ranking rules.

Return type:

None

async create_index(index, primary_key='id')[source]¶

Create a new search index.

Parameters:
  • index (str) – Base index name.

  • primary_key (str) – Primary key field name.

Return type:

TaskInfo

Returns:

Task information for the index creation.

async delete_documents(index, document_ids)[source]¶

Delete documents from an index.

Parameters:
  • index (str) – Base index name.

  • document_ids (list[str]) – List of document IDs to delete.

Return type:

TaskInfo

Returns:

Task information for the deletion operation.

async delete_index(index)[source]¶

Delete a search index.

Parameters:

index (str) – Base index name.

Return type:

TaskInfo

Returns:

Task information for the index deletion.

async get_index_stats(index)[source]¶

Get statistics for an index.

Parameters:

index (str) – Base index name.

Return type:

dict[str, Any]

Returns:

Index statistics.

async index_documents(index, documents, primary_key='id')[source]¶

Index documents into Meilisearch.

Parameters:
  • index (str) – Base index name.

  • documents (list[IndexedDocument] | list[dict[str, Any]]) – List of documents to index.

  • primary_key (str) – Primary key field name.

Return type:

TaskInfo

Returns:

Task information for the indexing operation.

async is_available()[source]¶

Check if Meilisearch service is available.

Return type:

bool

Returns:

True if Meilisearch is reachable, False otherwise.

async search(query)[source]¶

Search across specified indexes.

Parameters:

query (SearchQuery) – Search query parameters.

Return type:

SearchResult

Returns:

Aggregated search results.

async update_documents(index, documents, primary_key='id')[source]¶

Update existing documents in Meilisearch.

Parameters:
  • index (str) – Base index name.

  • documents (list[IndexedDocument] | list[dict[str, Any]]) – List of documents to update.

  • primary_key (str) – Primary key field name.

Return type:

TaskInfo

Returns:

Task information for the update operation.

Schemas¶

Search request and response schemas.

Search schemas for Meilisearch integration.

class SearchQuery[source]¶

Bases: BaseModel

Search query parameters.

query: str¶
indexes: list[str] | None¶
filters: dict[str, Any] | None¶
limit: int¶
offset: int¶
attributes_to_retrieve: list[str] | None¶
attributes_to_highlight: list[str] | None¶
model_config: ClassVar[ConfigDict] = {}¶

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class SearchHit[source]¶

Bases: BaseModel

A single search result hit.

id: str¶
index: str¶
title: str¶
description: str | None¶
url: str¶
content_type: str¶
created: datetime | None¶
modified: datetime | None¶
highlight: dict[str, list[str]] | None¶
extra: dict[str, Any] | None¶
model_config: ClassVar[ConfigDict] = {}¶

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class SearchResult[source]¶

Bases: BaseModel

Search results response.

hits: list[SearchHit]¶
total: int¶
offset: int¶
limit: int¶
processing_time_ms: int¶
query: str¶
model_config: ClassVar[ConfigDict] = {}¶

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class IndexedDocument[source]¶

Bases: BaseModel

Base schema for indexed documents in Meilisearch.

id: str¶
title: str¶
description: str | None¶
content: str | None¶
url: str¶
content_type: str¶
created: datetime | None¶
modified: datetime | None¶
status: str | None¶
tags: list[str]¶
searchable_text: str | None¶
model_config: ClassVar[ConfigDict] = {}¶

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class JobDocument[source]¶

Bases: IndexedDocument

Job posting document for search indexing.

content_type: str¶
company_name: str¶
location: str | None¶
remote: bool¶
job_types: list[str]¶
model_config: ClassVar[ConfigDict] = {}¶

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class EventDocument[source]¶

Bases: IndexedDocument

Event document for search indexing.

content_type: str¶
venue: str | None¶
location: str | None¶
start_date: datetime | None¶
end_date: datetime | None¶
model_config: ClassVar[ConfigDict] = {}¶

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class BlogDocument[source]¶

Bases: IndexedDocument

Blog entry document for search indexing.

content_type: str¶
author: str | None¶
published: datetime | None¶
model_config: ClassVar[ConfigDict] = {}¶

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class PageDocument[source]¶

Bases: IndexedDocument

CMS page document for search indexing.

content_type: str¶
path: str¶
model_config: ClassVar[ConfigDict] = {}¶

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Service¶

Search service implementation.

Meilisearch service for search functionality.

class SearchService[source]¶

Bases: object

Service for interacting with Meilisearch.

__init__(url, api_key=None, index_prefix='pydotorg_')[source]¶

Initialize the Meilisearch service.

Parameters:
  • url (str) – Meilisearch server URL.

  • api_key (str | None) – Optional API key for authentication.

  • index_prefix (str) – Prefix for all index names.

property client: meilisearch_python_sdk.AsyncClient¶

Get or create the Meilisearch async client.

async close()[source]¶

Close the Meilisearch client connection.

Return type:

None

async create_index(index, primary_key='id')[source]¶

Create a new search index.

Parameters:
  • index (str) – Base index name.

  • primary_key (str) – Primary key field name.

Return type:

TaskInfo

Returns:

Task information for the index creation.

async delete_index(index)[source]¶

Delete a search index.

Parameters:

index (str) – Base index name.

Return type:

TaskInfo

Returns:

Task information for the index deletion.

async configure_index(index, searchable_attributes=None, filterable_attributes=None, sortable_attributes=None, ranking_rules=None)[source]¶

Configure index settings.

Parameters:
  • index (str) – Base index name.

  • searchable_attributes (list[str] | None) – Fields to search in (order matters for ranking).

  • filterable_attributes (list[str] | None) – Fields that can be used in filters.

  • sortable_attributes (list[str] | None) – Fields that can be used for sorting.

  • ranking_rules (list[str] | None) – Custom ranking rules.

Return type:

None

async index_documents(index, documents, primary_key='id')[source]¶

Index documents into Meilisearch.

Parameters:
  • index (str) – Base index name.

  • documents (list[IndexedDocument] | list[dict[str, Any]]) – List of documents to index.

  • primary_key (str) – Primary key field name.

Return type:

TaskInfo

Returns:

Task information for the indexing operation.

async update_documents(index, documents, primary_key='id')[source]¶

Update existing documents in Meilisearch.

Parameters:
  • index (str) – Base index name.

  • documents (list[IndexedDocument] | list[dict[str, Any]]) – List of documents to update.

  • primary_key (str) – Primary key field name.

Return type:

TaskInfo

Returns:

Task information for the update operation.

async delete_documents(index, document_ids)[source]¶

Delete documents from an index.

Parameters:
  • index (str) – Base index name.

  • document_ids (list[str]) – List of document IDs to delete.

Return type:

TaskInfo

Returns:

Task information for the deletion operation.

async clear_index(index)[source]¶

Clear all documents from an index.

Parameters:

index (str) – Base index name.

Return type:

TaskInfo

Returns:

Task information for the clear operation.

async is_available()[source]¶

Check if Meilisearch service is available.

Return type:

bool

Returns:

True if Meilisearch is reachable, False otherwise.

async search(query)[source]¶

Search across specified indexes.

Parameters:

query (SearchQuery) – Search query parameters.

Return type:

SearchResult

Returns:

Aggregated search results.

async get_index_stats(index)[source]¶

Get statistics for an index.

Parameters:

index (str) – Base index name.

Return type:

dict[str, Any]

Returns:

Index statistics.

Previous
Rate Limiting
Next
Security

2025, Jacob Coffee

Made with Sphinx and Shibuya theme.