Skip to content

Commit

Permalink
update parents for table & documents calls
Browse files Browse the repository at this point in the history
  • Loading branch information
philipperolet committed Dec 22, 2024
1 parent 433005a commit 2115e0d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
7 changes: 6 additions & 1 deletion core/bin/core_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions core/src/data_sources/data_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ impl DataSource {
&self,
store: Box<dyn Store + Sync + Send>,
qdrant_clients: QdrantClients,
search_store: Box<dyn SearchStore + Sync + Send>,
document_id: String,
parents: Vec<String>,
) -> Result<()> {
Expand All @@ -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(())
}

Expand Down
3 changes: 3 additions & 0 deletions core/src/databases/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl Table {
pub async fn update_parents(
&self,
store: Box<dyn Store + Sync + Send>,
search_store: Box<dyn SearchStore + Sync + Send>,
parents: Vec<String>,
) -> Result<()> {
store
Expand All @@ -232,6 +233,8 @@ impl Table {
&parents,
)
.await?;

search_store.index_node(Node::from(self.clone())).await?;
Ok(())
}
}
Expand Down
4 changes: 3 additions & 1 deletion core/src/search_stores/search_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 2115e0d

Please sign in to comment.