function _get_facet_summary(&$ds, $meta, $tree) { $index_defs = @$meta['search']['index']; $facet_defs = $meta['facets']; // remove the sort field unset($index_defs['sort.default']); // get count field if (isset($facet_defs['count'])) { $count = $facet_defs['count']; unset($facet_defs['count']); } $fields = array(); // get all fields to sum foreach ($facet_defs as $facet) { if ($facet['select'] == 'all') { continue; } $fields[] = "SUM(IF({$facet['select']},1,0)) AS '{$facet['name']}'"; } // add count to get total if (!isset($count)) { $count = isset($meta['fields']['url']['select']) ? 't.' . $meta['fields']['url']['select'] : 't.id'; } $fields[] = "COUNT(DISTINCT {$count}) AS total"; $fields = join(',', $fields); $generator = new SqlGenerator($meta['mysql_table'] . ' t', $fields, $index_defs); $sql = $generator->convert($tree); $ds->log(4, 'Facets SQL: ' . $sql); $r = $this->db->queryAll($sql, NULL, MDB2_FETCHMODE_ASSOC); if (PEAR::isError($r)) { return $ds->_set_error(500, 'Search (facet summary): ' . $r->message . ' ' . $r->userinfo); } // typically only 1 row of results is returned, but for union searches multiple rows are returned // in this case sum all rows together - this can contain duplicate values, but we will live with it if (count($r) <= 1) { $accuracy = 'exact'; } else { $accuracy = 'approx'; $tmp = array(); for ($i = 0; $i < count($r); $i++) { foreach ($r[$i] as $name => $value) { @($tmp[$name] += $value); } } $r = array($tmp); } // collate results $results = array(); foreach ($facet_defs as $facet) { if (!isset($results[$facet['type']])) { $results[$facet['type']] = array(); } if ($facet['select'] == 'all') { $results[$facet['type']][$facet['name']] = $r[0]['total']; } else { $results[$facet['type']][$facet['name']] = $r[0][$facet['name']]; } } $results['accuracy'] = $accuracy; if ($accuracy == 'exact') { $results['total'] = $r[0]['total']; } return $results; }
function update($tabela, $dados, $string) { if (!$tabela) { echo "Informe uma tabela."; return false; } if (!$dados) { echo "Informe valores"; return false; } if (!$string) { echo "Informe condição"; return false; } try { $this->freeSQL(SqlGenerator::update($table, $dados, $string)); return true; } catch (exception $erro) { echo "Não foi possivel alterar registro. FAILL: " . $erro->getMessage(); return false; } }