From d2184fadb0f48986fcf4a6772ebd000f746b311f Mon Sep 17 00:00:00 2001 From: David Straub Date: Wed, 11 Dec 2024 00:32:38 +0100 Subject: [PATCH] Fixes in search.indexer --- gramps_webapi/api/search/indexer.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/gramps_webapi/api/search/indexer.py b/gramps_webapi/api/search/indexer.py index 738cddaa..a5474355 100644 --- a/gramps_webapi/api/search/indexer.py +++ b/gramps_webapi/api/search/indexer.py @@ -202,12 +202,15 @@ def delete_object(self, handle: str, class_name: str) -> None: obj_id = self._object_id_public(handle=handle, class_name=class_name) self.index_public.delete([obj_id]) - def add_or_update_object(self, handle: str, db_handle: DbReadBase, class_name: str): + def add_or_update_object( + self, handle: str, db_handle: DbReadBase, class_name: str + ) -> None: """Add an object to the index or update it if it exists.""" obj_dict = obj_strings_from_handle( db_handle, class_name, handle, semantic=self.use_semantic_text ) - self._add_objects([obj_dict]) + if obj_dict is not None: + self._add_objects([obj_dict]) def reindex_incremental( self, db_handle: DbReadBase, progress_cb: Optional[Callable] = None @@ -246,22 +249,22 @@ def progress(i): for class_name, handles in update_info["new"].items(): obj_dicts = [] for handle in handles: - obj_dicts.append( - obj_strings_from_handle( - db_handle, class_name, handle, semantic=self.use_semantic_text - ) + obj_strings = obj_strings_from_handle( + db_handle, class_name, handle, semantic=self.use_semantic_text ) + if obj_strings is not None: + obj_dicts.append(obj_strings) i = progress(i) self._add_objects(obj_dicts) # update objects for class_name, handles in update_info["updated"].items(): obj_dicts = [] for handle in handles: - obj_dicts.append( - obj_strings_from_handle( - db_handle, class_name, handle, semantic=self.use_semantic_text - ) + obj_strings = obj_strings_from_handle( + db_handle, class_name, handle, semantic=self.use_semantic_text ) + if obj_strings is not None: + obj_dicts.append(obj_strings) i = progress(i) self._add_objects(obj_dicts) @@ -304,14 +307,13 @@ def search( raise ValueError("Invalid operator for change condition") ops = {">": "$gt", "<": "$lt", ">=": "$gte", "<=": "$lte"} where["change"] = {ops[change_op]: change_value} - where = where or None offset = (page - 1) * pagesize if not query or query.strip() == "*": results = search.get( limit=pagesize, offset=offset, order_by=sort, - where=where, + where=where or None, ) else: results = search.query( @@ -319,7 +321,7 @@ def search( limit=pagesize, offset=offset, order_by=sort, - where=where, + where=where or None, vector_search=self.use_semantic_text, ) total = results["total"]