// Copyright 2023, DragonflyDB authors. All rights reserved. // See LICENSE for licensing terms. // #include "core/search/ast_expr.h" #include #include #include #include #include "base/logging.h" using namespace std; namespace dfly::search { AstTermNode::AstTermNode(string term) : term{term} { } AstRangeNode::AstRangeNode(double lo, bool lo_excl, double hi, bool hi_excl) : lo{lo_excl ? nextafter(lo, hi) : lo}, hi{hi_excl ? nextafter(hi, lo) : hi} { } AstNegateNode::AstNegateNode(AstNode&& node) : node{make_unique(std::move(node))} { } AstLogicalNode::AstLogicalNode(AstNode&& l, AstNode&& r, LogicOp op) : op{op}, nodes{} { // If either node is already a logical node with the same op, // we can re-use it, as logical ops are associative. for (auto* node : {&l, &r}) { if (auto* ln = get_if(node); ln && ln->op == op) { *this = std::move(*ln); nodes.emplace_back(std::move(*(node == &l ? &r : &l))); return; } } nodes.emplace_back(std::move(l)); nodes.emplace_back(std::move(r)); } AstFieldNode::AstFieldNode(string field, AstNode&& node) : field{field.substr(1)}, node{make_unique(std::move(node))} { } AstTagsNode::AstTagsNode(std::string tag) { tags = {std::move(tag)}; } AstTagsNode::AstTagsNode(AstExpr&& l, std::string tag) { DCHECK(holds_alternative(l)); auto& tags_node = get(l); tags = std::move(tags_node.tags); tags.push_back(std::move(tag)); } AstKnnNode::AstKnnNode(uint32_t limit, std::string_view field, OwnedFtVector vec, std::string_view score_alias) : filter{nullptr}, limit{limit}, field{field.substr(1)}, vec{std::move(vec)}, score_alias{score_alias} { } AstKnnNode::AstKnnNode(AstNode&& filter, AstKnnNode&& self) { *this = std::move(self); this->filter = make_unique(std::move(filter)); } } // namespace dfly::search