Use Meilisearch PUT for partial caption metadata updates

This commit is contained in:
Sleeps
2026-10-08 10:53:14 +01:00
parent 05d1d8e369
commit b48b1b5ed0
+20 -4
View File
@@ -68,14 +68,25 @@ class Meili:
f"{self.url}/indexes/{self.index}/documents",
))
def add_documents(self, documents: list[dict]) -> None:
def add_documents(
self,
documents: list[dict],
*,
wait: bool = False,
) -> None:
"""Replace complete documents (used for indexing and targeted repairs)."""
if not documents:
return
self._check(self.session.post(
response = self._check(self.session.post(
f"{self.url}/indexes/{self.index}/documents",
params={"primaryKey": "id"},
json=documents,
))
if wait:
task_uid = response.json().get("taskUid")
if task_uid is None:
raise RuntimeError("Meilisearch replacement did not return a taskUid")
self.wait_for_task(int(task_uid))
def wait_for_task(self, task_uid: int, *, timeout_seconds: float = 120) -> dict:
deadline = time.monotonic() + timeout_seconds
@@ -105,12 +116,17 @@ class Meili:
*,
wait: bool = False,
) -> None:
"""Partially update existing documents without replacing omitted fields."""
"""Update only supplied caption fields, preserving identities and vectors.
POST replaces an entire Meilisearch document; PUT is the partial-update
endpoint. Using POST here previously deleted titles, Jellyfin item IDs,
and SigLIP vectors whenever a caption was synchronised.
"""
if not documents:
return
self.ensure_index()
response = self._check(
self.session.post(
self.session.put(
f"{self.url}/indexes/{self.index}/documents",
params={"primaryKey": "id"},
json=documents,