| Class | ScopedSearch::QueryLanguage::AST::LogicalOperatorNode |
| In: |
lib/scoped_search/query_language/ast.rb
|
| Parent: | OperatorNode |
Checks whether another node is comparable so that it can be used for tree simplification. A node can only be simplified if the logical operator is equal.
# File lib/scoped_search/query_language/ast.rb, line 123
123: def compatible_with(node)
124: node.kind_of?(LogicalOperatorNode) && node.operator == self.operator
125: end
Simplifies nested AND and OR constructs to single constructs with multiple arguments: e.g. (a AND (b AND c)) -> (a AND b AND c)
# File lib/scoped_search/query_language/ast.rb, line 129
129: def simplify
130: if children.length == 1
131: # AND or OR constructs do nothing if they only have one operand
132: # So remove the logal operator from the AST by simply using the opeand
133: return children.first.simplify
134: else
135: # nested AND or OR constructs can be combined into one construct
136: @children = children.map { |c| c.simplify }.map { |c| self.compatible_with(c) ? c.children : c }.flatten
137: return self
138: end
139: end