diff --git a/libreforms_fastapi/app/__init__.py b/libreforms_fastapi/app/__init__.py index 8fc2ad1..66ec6ef 100644 --- a/libreforms_fastapi/app/__init__.py +++ b/libreforms_fastapi/app/__init__.py @@ -582,7 +582,7 @@ async def api_form_search(form_name: str, background_tasks: BackgroundTasks, req if form_name not in get_form_names(): raise HTTPException(status_code=404, detail=f"Form '{form_name}' not found") - if search_term is None: + if search_term is None or len(search_term) == 0: return {"error": "No search term provided"} # Ugh, I'd like to find a more efficient way to get the user data. But alas, that diff --git a/libreforms_fastapi/utils/document_database.py b/libreforms_fastapi/utils/document_database.py index 42653e0..72bcea8 100644 --- a/libreforms_fastapi/utils/document_database.py +++ b/libreforms_fastapi/utils/document_database.py @@ -323,6 +323,8 @@ def create_document(self, form_name:str, json_data, metadata={}): "metadata": { # self.document_id_field: document_id, self.is_deleted_field: metadata.get(self.is_deleted_field, False), + self.document_id_field: document_id, + self.form_name_field: form_name, self.timezone_field: metadata.get(self.timezone_field, self.timezone.key), self.created_at_field: metadata.get(self.created_at_field, current_timestamp.isoformat()), self.last_modified_field: metadata.get(self.last_modified_field, current_timestamp.isoformat()), @@ -393,10 +395,6 @@ def fuzzy_search_documents(self, search_term:str, limit_users:Union[bool, dict]= elif isinstance(limit_users[f], str): d = [x for x in d if x['metadata'][self.created_by_field] == limit_users[f]] - for item in d: - item['metadata'][self.document_id_field] = item.doc_id - item['metadata'][self.form_name_field] = f - data.extend(d)