From 2115e0d7f76978520a5a82212811679cc0635680 Mon Sep 17 00:00:00 2001 From: filou Date: Thu, 19 Dec 2024 22:43:37 +0100 Subject: [PATCH] update parents for table & documents calls --- core/bin/core_api.rs | 7 ++++++- core/src/data_sources/data_source.rs | 15 +++++++++++++++ core/src/databases/table.rs | 3 +++ core/src/search_stores/search_store.rs | 4 +++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/core/bin/core_api.rs b/core/bin/core_api.rs index e40a5f562fb53..0e920b2ea6b44 100644 --- a/core/bin/core_api.rs +++ b/core/bin/core_api.rs @@ -1550,6 +1550,7 @@ async fn data_sources_documents_update_parents( .update_parents( state.store.clone(), state.qdrant_clients.clone(), + state.search_store.clone(), document_id, payload.parents, ) @@ -2536,7 +2537,11 @@ async fn tables_update_parents( None, ), Ok(Some(table)) => match table - .update_parents(state.store.clone(), payload.parents.clone()) + .update_parents( + state.store.clone(), + state.search_store.clone(), + payload.parents.clone(), + ) .await { Err(e) => error_response( diff --git a/core/src/data_sources/data_source.rs b/core/src/data_sources/data_source.rs index f1fbf0e992eb2..29ec8e6e535c2 100644 --- a/core/src/data_sources/data_source.rs +++ b/core/src/data_sources/data_source.rs @@ -469,6 +469,7 @@ impl DataSource { &self, store: Box, qdrant_clients: QdrantClients, + search_store: Box, document_id: String, parents: Vec, ) -> Result<()> { @@ -485,6 +486,20 @@ impl DataSource { self.update_document_payload(qdrant_clients, document_id_hash, "parents", parents) .await?; + + let document = store + .load_data_source_document( + &self.project, + &self.data_source_id(), + &document_id.to_string(), + &None, + ) + .await?; + + search_store + .index_node(Node::from(document.unwrap())) + .await?; + Ok(()) } diff --git a/core/src/databases/table.rs b/core/src/databases/table.rs index f0694e3c7cd19..450164244b3bc 100644 --- a/core/src/databases/table.rs +++ b/core/src/databases/table.rs @@ -222,6 +222,7 @@ impl Table { pub async fn update_parents( &self, store: Box, + search_store: Box, parents: Vec, ) -> Result<()> { store @@ -232,6 +233,8 @@ impl Table { &parents, ) .await?; + + search_store.index_node(Node::from(self.clone())).await?; Ok(()) } } diff --git a/core/src/search_stores/search_store.rs b/core/src/search_stores/search_store.rs index abac1c8295c73..1583d8b0fcc0b 100644 --- a/core/src/search_stores/search_store.rs +++ b/core/src/search_stores/search_store.rs @@ -146,7 +146,9 @@ impl SearchStore for ElasticsearchSearchStore { async fn index_node(&self, node: Node) -> Result<()> { // todo(kw-search): fail on error let now = utils::now(); - let response = self + // Note: in elasticsearch, the index API updates the document if it + // already exists. + let response = self .client .index(IndexParts::IndexId(NODES_INDEX_NAME, &node.unique_id())) .timeout("200ms")