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..7468853 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,16 @@ 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() + return results + + def get_nb_docs_sync(): statement = select(QtyDocumentInQdrant.document_in_qdrant) with session_maker() as s: