Skip to content

Commit 75ce71a

Browse files
committed
Review the way has_children / parent_title are computed
(by reverting commit ae035f4.)
1 parent 90b5c34 commit 75ce71a

File tree

1 file changed

+4
-37
lines changed

1 file changed

+4
-37
lines changed

core/src/search_stores/search_store.rs

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -122,53 +122,20 @@ impl SearchStore for ElasticsearchSearchStore {
122122
"should": filter_conditions,
123123
"minimum_should_match": 1
124124
}
125-
},
126-
"runtime_mappings": {
127-
"has_children": {
128-
"type": "boolean",
129-
"script": {
130-
"source": "def children = searchInternalByField('parent_id', doc['node_id'].value); emit(children.size() > 0);"
131-
}
132-
},
133-
"parent_title": {
134-
"type": "keyword",
135-
"script": {
136-
"source": "if (!doc['parent_id'].isEmpty()) { def parents = searchInternalByField('node_id', doc['parent_id'].value); if (parents.size() > 0) { emit(parents[0].title); } }"
137-
}
138-
}
139-
},
140-
"fields": ["*", "has_children", "parent_title"],
141-
"_source": true
125+
}
142126
}))
143127
.send()
144128
.await?;
145129

146130
match response.status_code().is_success() {
147131
true => {
132+
// get nodes from elasticsearch response in hits.hits
148133
let response_body = response.json::<serde_json::Value>().await?;
149-
let nodes: Vec<CoreContentNode> = response_body["hits"]["hits"]
134+
let nodes: Vec<Node> = response_body["hits"]["hits"]
150135
.as_array()
151136
.unwrap()
152137
.iter()
153-
.map(|h| {
154-
let base = Node::from(h.get("_source").unwrap().clone());
155-
let has_children = h
156-
.get("fields")
157-
.and_then(|fields| fields.get("has_children"))
158-
.and_then(|arr| arr.get(0))
159-
.and_then(|v| v.as_bool())
160-
.unwrap_or(false);
161-
162-
let parent_title = h
163-
.get("fields")
164-
.and_then(|fields| fields.get("parent_title"))
165-
.and_then(|arr| arr.get(0))
166-
.and_then(|v| v.as_str())
167-
.unwrap_or("")
168-
.to_string();
169-
170-
CoreContentNode::new(base, has_children, parent_title)
171-
})
138+
.map(|h| Node::from(h.get("_source").unwrap().clone()))
172139
.collect();
173140
Ok(nodes)
174141
}

0 commit comments

Comments
 (0)