mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
avoid wrapping outermost search in parens
This commit is contained in:
parent
03b9f2a3f6
commit
586ea07869
2 changed files with 14 additions and 7 deletions
|
@ -548,7 +548,8 @@ impl BackendService for Backend {
|
|||
//-----------------------------------------------
|
||||
|
||||
fn build_search_string(&self, input: pb::SearchNode) -> Result<pb::String> {
|
||||
Ok(write_nodes(&[input.try_into()?]).into())
|
||||
let node: Node = input.try_into()?;
|
||||
Ok(write_nodes(&node.into_node_list()).into())
|
||||
}
|
||||
|
||||
fn search_cards(&self, input: pb::SearchCardsIn) -> Result<pb::SearchCardsOut> {
|
||||
|
@ -573,12 +574,8 @@ impl BackendService for Backend {
|
|||
fn join_search_nodes(&self, input: pb::JoinSearchNodesIn) -> Result<pb::String> {
|
||||
let sep = input.joiner().into();
|
||||
let existing_nodes = {
|
||||
let node = input.existing_node.unwrap_or_default().try_into()?;
|
||||
if let Node::Group(nodes) = node {
|
||||
nodes
|
||||
} else {
|
||||
vec![node]
|
||||
}
|
||||
let node: Node = input.existing_node.unwrap_or_default().try_into()?;
|
||||
node.into_node_list()
|
||||
};
|
||||
let additional_node = input.additional_node.unwrap_or_default().try_into()?;
|
||||
Ok(concatenate_searches(sep, existing_nodes, additional_node).into())
|
||||
|
|
|
@ -46,6 +46,16 @@ impl Node {
|
|||
Node::Not(Box::new(self))
|
||||
}
|
||||
}
|
||||
|
||||
/// If we're a group, return the contained elements.
|
||||
/// If we're a single node, return ourselves in an one-element vec.
|
||||
pub fn into_node_list(self) -> Vec<Node> {
|
||||
if let Node::Group(nodes) = self {
|
||||
nodes
|
||||
} else {
|
||||
vec![self]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
|
|
Loading…
Reference in a new issue