Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions meilisearch_python_sdk/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,25 @@ def _pre_update_documents_plugins(self) -> list[AsyncPlugin | AsyncDocumentPlugi

return plugins

async def compact(self) -> TaskInfo:
"""Appends a new task to the queue to compact the database.

This defragments the LMDB database potentially speeds up indexing and searching.
NOTE: This is only available in Meilisearch v1.23.0+

Raises:
MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples
>>> from meilisearch_python_sdk import AsyncClient
>>> async with AsyncClient("http://localhost.com", "masterKey") as client:
>>> index = client.index("movies")
>>> index.compact()
"""
response = await self._http_requests.post(f"{self._base_url_with_uid}/compact")
return TaskInfo(**response.json())

async def delete(self) -> TaskInfo:
"""Deletes the index.

Expand Down Expand Up @@ -4921,6 +4940,25 @@ def _pre_update_documents_plugins(self) -> list[Plugin | DocumentPlugin] | None:

return plugins

def compact(self) -> TaskInfo:
"""Appends a new task to the queue to compact the database.

This defragments the LMDB database potentially speeds up indexing and searching.
NOTE: This is only available in Meilisearch v1.23.0+

Raises:
MeilisearchCommunicationError: If there was an error communicating with the server.
MeilisearchApiError: If the Meilisearch API returned an error.

Examples
>>> from meilisearch_python_sdk import Client
>>> client = Client("http://localhost.com", "masterKey")
>>> index = client.index("movies")
>>> index.compact()
"""
response = self._http_requests.post(f"{self._base_url_with_uid}/compact")
return TaskInfo(**response.json())

def delete(self) -> TaskInfo:
"""Deletes the index.

Expand Down
9 changes: 9 additions & 0 deletions tests/test_async_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,3 +1022,12 @@ async def test_reset_prefix_search_opt_out(async_empty_index):
result = await index.get_settings()

assert result.prefix_search == "indexingTime"


async def test_compact(async_client, async_index_with_documents):
index = await async_index_with_documents()
task = await index.compact()
await async_client.wait_for_task(task.task_uid)
result = await async_client.get_task(task_id=task.task_uid)

assert result.status == "succeeded"
9 changes: 9 additions & 0 deletions tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,3 +1023,12 @@ def test_process_search_parameters_no_media():
result = _process_search_parameters()

assert "media" not in result.keys()


def test_compact(client, index_with_documents):
index = index_with_documents()
task = index.compact()
client.wait_for_task(task.task_uid)
result = client.get_task(task_id=task.task_uid)

assert result.status == "succeeded"