terms = $terms; $this->termTableName = $termTableName; return $tqlAST->accept ($this); } /* * Visitor functions */ function visitIdentifier($tqlIdentifier) { $termId = $this->terms[$tqlIdentifier->value]; if ($termId == -1) { // term is not in vocabulary return NULL; } else { return "(SELECT DISTINCT nid FROM `$this->termTableName` WHERE tid=$termId)"; } } function visitUnaryOperation($tqlUnaryOperation) { // switch to operation visitor return $tqlUnaryOperation->acceptOperation($this); } function visitBinaryOperation($tqlBinaryOperation) { // switch to operation visitor return $tqlBinaryOperation->acceptOperation($this); } function visitNot($tqlNot) { $operand = $tqlNot->operand->accept($this); if ($operand == NULL) { // in this case we return the whole universe... :-) return "(SELECT DISTINCT nid FROM `$this->termTableName`)"; } else { return "(SELECT DISTINCT nid FROM `$this->termTableName` WHERE nid not in $operand)"; } } function visitAnd($tqlAnd) { $left = $tqlAnd->left->accept($this); $right = $tqlAnd->right->accept($this); // in this case it's impossible to have any result! if ($left == NULL || $right == NULL) { return NULL; } return "($left INTERSECT DISTINCT $right)"; } function visitOr($tqlOr) { $left = $tqlOr->left->accept($this); $right = $tqlOr->right->accept($this); // in this case it's impossible to have any result! if ($left == NULL) { return $right; // might be NULL as well! } elseif ($right == NULL) { return $left; // might be NULL as well! } else { return "($left UNION DISTINCT $right)"; } } function visitXor($tqlXor) { $left = $tqlXor->left->accept($this); $right = $tqlXor->right->accept($this); if ($left == NULL) { return $right; // might be NULL as well! } elseif ($right == NULL) { return $left; // might be NULL as well! } else { return "(($left EXCEPT DISTINCT $right) UNION ($right EXCEPT $left))"; } } }