Skip to content

Commit

Permalink
Fixes in search.indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub committed Dec 10, 2024
1 parent 792d526 commit d2184fa
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions gramps_webapi/api/search/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -304,22 +307,21 @@ 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(
query,
limit=pagesize,
offset=offset,
order_by=sort,
where=where,
where=where or None,
vector_search=self.use_semantic_text,
)
total = results["total"]
Expand Down

0 comments on commit d2184fa

Please sign in to comment.