import streamlit as st from import_data.utils.typesense_client import client def rechercher_documents(cette_requete, ces_filtres=None, facette_par=None, query_by="texte,embedding", sort_by="_text_match:desc,creation_timestamp:desc", nb_buckets=10, prefix=False, per_page=10, page=1): parametres_recherche = { 'q': cette_requete, 'query_by': query_by, 'sort_by': sort_by.replace( "_text_match", f"_text_match(buckets: {nb_buckets})"), "exclude_fields": "embedding", "prefix": str(prefix).lower(), 'per_page': per_page, 'page': page } if ces_filtres: parametres_recherche['filter_by'] = ces_filtres if facette_par: parametres_recherche['facet_by'] = facette_par st.write("Search parameters:", parametres_recherche) all_results = [] try: results = client.collections['social_media_posts'].documents.search(parametres_recherche) all_results.extend(results['hits']) return results except Exception as e: st.error(f"Error during search: {str(e)}") # Error handling