Skip to content

Commit

Permalink
Review the way has_children / parent_title are computed
Browse files Browse the repository at this point in the history
(by reverting commit ae035f4.)
  • Loading branch information
philipperolet committed Jan 14, 2025
1 parent 90b5c34 commit 75ce71a
Showing 1 changed file with 4 additions and 37 deletions.
41 changes: 4 additions & 37 deletions core/src/search_stores/search_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,53 +122,20 @@ impl SearchStore for ElasticsearchSearchStore {
"should": filter_conditions,
"minimum_should_match": 1
}
},
"runtime_mappings": {
"has_children": {
"type": "boolean",
"script": {
"source": "def children = searchInternalByField('parent_id', doc['node_id'].value); emit(children.size() > 0);"
}
},
"parent_title": {
"type": "keyword",
"script": {
"source": "if (!doc['parent_id'].isEmpty()) { def parents = searchInternalByField('node_id', doc['parent_id'].value); if (parents.size() > 0) { emit(parents[0].title); } }"
}
}
},
"fields": ["*", "has_children", "parent_title"],
"_source": true
}
}))
.send()
.await?;

match response.status_code().is_success() {
true => {
// get nodes from elasticsearch response in hits.hits
let response_body = response.json::<serde_json::Value>().await?;
let nodes: Vec<CoreContentNode> = response_body["hits"]["hits"]
let nodes: Vec<Node> = response_body["hits"]["hits"]
.as_array()
.unwrap()
.iter()
.map(|h| {
let base = Node::from(h.get("_source").unwrap().clone());
let has_children = h
.get("fields")
.and_then(|fields| fields.get("has_children"))
.and_then(|arr| arr.get(0))
.and_then(|v| v.as_bool())
.unwrap_or(false);

let parent_title = h
.get("fields")
.and_then(|fields| fields.get("parent_title"))
.and_then(|arr| arr.get(0))
.and_then(|v| v.as_str())
.unwrap_or("")
.to_string();

CoreContentNode::new(base, has_children, parent_title)
})
.map(|h| Node::from(h.get("_source").unwrap().clone()))
.collect();
Ok(nodes)
}
Expand Down

0 comments on commit 75ce71a

Please sign in to comment.