/** * Executes a database query * * @access private * @global object $default Default config settings * @param string $op The operation to perform * @param array $group * @return array $results */ private function exec_db_query($op, $group) { if (empty($group)) { return array(); } $exprbuilder = new SQLQueryBuilder($this->getContext()); $exprbuilder->setIncludeStatus($this->incl_status); if (count($group) == 1) { $sql = $exprbuilder->buildComplexQuery($group[0]); } else { $sql = $exprbuilder->buildSimpleQuery($op, $group); } if (empty($sql)) { return array(); } $results = array(); global $default; $default->log->debug("SEARCH SQL: {$sql}"); $rs = DBUtil::getResultArray($sql); if (PEAR::isError($rs)) { throw new Exception($rs->getMessage()); } if (count($group) == 1) { //$default->log->debug("CASE 1"); $oCriteria = $this->checkComplexQuery($group[0]); } else { //$default->log->debug("CASE 2"); foreach ($group as $expr) { $left = $expr->left(); $right = $expr->right(); $default->log->debug("FIELD-IS: " . $left->isOpExpr()); $fieldname = $left->getField(); $value = addslashes($right->getValue()); $rsField = DBUtil::getResultArray("SELECT * FROM document_fields WHERE name = \"{$fieldname}\";"); if ($rsField[0]['data_type'] == 'LARGE TEXT') { $iCriteria = array(); $iCriteria[0] = array(); $iCriteria[0]['field'] = $fieldname; $iCriteria[0]['value'] = $value; $iCriteria[0]['not'] = $expr->not(); $oCriteria[] = $iCriteria[0]; /*$not = $expr->not()?' NOT ':''; if (strpos($value, ' ') !== false) $default->log->debug("CRITERION: $not$fieldname:\"$value\""); else $default->log->debug("CRITERION: $not$fieldname:$value");*/ } //$default->log->debug("FIELD-TYPE: " . $oCriteria[0]['field']); } } //$default->log->debug("TOTAL CRITERIA: " . count($oCriteria)); foreach ($rs as $item) { $id = $item['id']; $rank = $exprbuilder->getRanking($item); if (!array_key_exists($id, $results) || $rank > $results[$id]->Rank) { if ($this->context == ExprContext::DOCUMENT) { if (count($oCriteria) > 0 && $this->checkValues($id, $oCriteria) || count($oCriteria) == 0) { $results[$id] = new DocumentResultItem($id, $rank, $item['title'], $exprbuilder->getResultText($item), null, $this->incl_status); } } else { $results[$id] = new FolderResultItem($id, $rank, $item['title'], $exprbuilder->getResultText($item)); } } } return $results; }
private function exec_db_query($op, $group) { if (empty($group)) { return array(); } $exprbuilder = new SQLQueryBuilder($this->getContext()); $exprbuilder->setIncludeStatus($this->incl_status); if (count($group) == 1) { $sql = $exprbuilder->buildComplexQuery($group[0]); } else { $sql = $exprbuilder->buildSimpleQuery($op, $group); } if (empty($sql)) { return array(); } $results = array(); global $default; $default->log->debug("SEARCH SQL: {$sql}"); $rs = DBUtil::getResultArray($sql); if (PEAR::isError($rs)) { throw new Exception($rs->getMessage()); } foreach ($rs as $item) { $id = $item['id']; $rank = $exprbuilder->getRanking($item); if (!array_key_exists($id, $results) || $rank > $results[$id]->Rank) { if ($this->context == ExprContext::DOCUMENT) { $results[$id] = new DocumentResultItem($id, $rank, $item['title'], $exprbuilder->getResultText($item), null, $this->incl_status); } else { $results[$id] = new FolderResultItem($id, $rank, $item['title'], $exprbuilder->getResultText($item)); } } } return $results; }