From b48b1b5ed05fea997e52cd675cec339f27609727 Mon Sep 17 00:00:00 2001 From: Sleeps Date: Thu, 8 Oct 2026 10:53:14 +0100 Subject: [PATCH] Use Meilisearch PUT for partial caption metadata updates --- scene_search/meili.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/scene_search/meili.py b/scene_search/meili.py index c993c92..63f40b0 100644 --- a/scene_search/meili.py +++ b/scene_search/meili.py @@ -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,