From e12361b781ec298d78ffe615c2d120d217cff161 Mon Sep 17 00:00:00 2001 From: Sandra Guerreiro Date: Thu, 2 Apr 2026 18:27:13 +0200 Subject: [PATCH 1/2] feat(collections): returns collections with categories --- src/app/search/api/router.py | 15 ++++++++------- src/app/services/sql_db/queries.py | 12 ++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/app/search/api/router.py b/src/app/search/api/router.py index ac20c5c..f7ae3a9 100644 --- a/src/app/search/api/router.py +++ b/src/app/search/api/router.py @@ -22,7 +22,7 @@ from src.app.search.services.search import SearchService, get_search_service from src.app.services.data_collection import get_data_collection_service from src.app.services.sql_db.queries import ( - get_collections_sync, + get_collections_info_sync, get_documents_payload_by_ids_sync, get_nb_docs_sync, ) @@ -67,16 +67,17 @@ def get_params( @router.get("/collections") async def get_corpus(): - collections = await run_in_threadpool(get_collections_sync) + collections = await run_in_threadpool(get_collections_info_sync) return [ { - "name": name, - "lang": lang, - "model": model, - "corpus": f"{name}_{lang}_{model}", + "name": source_name, + "category": ( + category_name.replace(" ", "_").lower() if category_name else None + ), + "is_active": is_active, } - for name, lang, model in collections + for source_name, is_active, category_name in collections ] diff --git a/src/app/services/sql_db/queries.py b/src/app/services/sql_db/queries.py index 31a9ba8..522e31a 100644 --- a/src/app/services/sql_db/queries.py +++ b/src/app/services/sql_db/queries.py @@ -8,6 +8,7 @@ from sqlalchemy import func, select from welearn_database.data.enumeration import Step from welearn_database.data.models import ( + Category, ChatMessage, ContextDocument, Corpus, @@ -47,6 +48,17 @@ def get_collections_sync(): return s.execute(statement).all() +def get_collections_info_sync(): + stmt = select( + Corpus.source_name, Corpus.is_active, Category.title.label("category_name") + ).outerjoin(Category, Corpus.category_id == Category.id) + + with session_maker() as session: + results = session.execute(stmt).all() + print(results) + return results + + def get_nb_docs_sync(): statement = select(QtyDocumentInQdrant.document_in_qdrant) with session_maker() as s: From 6603b06f429f7dded979d5cd67165cc8ead66f34 Mon Sep 17 00:00:00 2001 From: Sandra Guerreiro Date: Thu, 2 Apr 2026 18:28:41 +0200 Subject: [PATCH 2/2] Apply suggestion from @sandragjacinto --- src/app/services/sql_db/queries.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/services/sql_db/queries.py b/src/app/services/sql_db/queries.py index 522e31a..7468853 100644 --- a/src/app/services/sql_db/queries.py +++ b/src/app/services/sql_db/queries.py @@ -55,7 +55,6 @@ def get_collections_info_sync(): with session_maker() as session: results = session.execute(stmt).all() - print(results) return results