public function executeSearch(sfWebRequest $request) { $culture = $this->getUser()->getCulture(); $this->page = $this->getRequestParameter('page', 1); $tag = $request->getParameter("tag", false); $tag = str_replace("_2E_", ".", $tag); if ($tag) { $this->q = "#{$tag}"; } else { $this->q = $request->getParameter("q"); } $request->setAttribute("q", $this->q); $resultsArray = array(); $cl = $this->resetSphinxClient(); $needle = $this->q; $this->ext = ""; if (strlen($needle) > 0 && strpos($needle, '#') === 0) { $this->ext = "_tag"; $needle = substr($needle, 1); } else { $needle = SfVoUtil::stripAccents($this->q); } $this->politicoCounts = false; $this->partidoCounts = false; $this->propuestaCounts = false; if ($needle) { if ($this->ext == "_tag") { $cl->SetMatchMode(SPH_MATCH_PHRASE); $cl->SetSortMode(SPH_SORT_EXTENDED, "cnt DESC"); $this->politicoCounts = array(); $this->partidoCounts = array(); $this->propuestaCounts = array(); $indexes = "partido_tag_{$culture}, politico_tag_{$culture}, propuesta_tag_{$culture}"; $this->res = $cl->Query($needle, $indexes); if ($this->res !== false) { $this->total = $this->res['total']; $this->totalFound = $this->res['total_found']; $cl->SetLimits(($this->page - 1) * $this->limit, $this->limit); $this->res = $cl->Query($needle, $indexes); } } else { $cl->SetFieldWeights(array('abreviatura_partido' => 5, 'nombre' => 5, 'apellidos' => 5, 'alias' => 5, 'titulo' => 5, 'nombre_insti' => 8, 'nombre_ele' => 9)); $cl->SetSortMode(SPH_SORT_EXPR, "@weight + ( 1 * votes/max_votes )"); $indexes = "politico_{$culture}, partido_{$culture},propuesta_{$culture}, institucion_{$culture}, usuario, eleccion_{$culture}"; $this->res = $cl->Query($needle, $indexes); if ($this->res !== false) { $this->total = $this->res['total']; $this->totalFound = $this->res['total_found']; $cl->SetLimits(($this->page - 1) * $this->limit, $this->limit); $this->res = $cl->Query($needle, $indexes); } } if ($this->res !== false && isset($this->res["matches"]) && is_array($this->res["matches"])) { foreach ($this->res["matches"] as $match) { //echo "<pre>";print_r( $match );echo "</pre>"; switch ($match['attrs']['type']) { case 1: if ($this->ext == "_tag") { $this->politicoCounts[$match['attrs']['politico_id']] = $match['attrs']['cnt']; $resultsArray[] = PoliticoPeer::retrieveByPK($match['attrs']['politico_id']); } else { $resultsArray[] = PoliticoPeer::retrieveByPK($match['id']); } break; case 2: if ($this->ext == "_tag") { $this->partidoCounts[$match['attrs']['partido_id']] = $match['attrs']['cnt']; $resultsArray[] = PartidoPeer::retrieveByPK($match['attrs']['partido_id']); } else { $resultsArray[] = PartidoPeer::retrieveByPK($match['id']); } break; case 3: if ($this->ext == "_tag") { $this->propuestaCounts[$match['attrs']['propuesta_id']] = $match['attrs']['cnt']; $resultsArray[] = PropuestaPeer::retrieveByPK($match['attrs']['propuesta_id']); } else { $resultsArray[] = PropuestaPeer::retrieveByPK($match['id']); } break; case 101: $resultsArray[] = InstitucionPeer::retrieveByPK($match['id']); break; case 102: $resultsArray[] = SfGuardUserPeer::retrieveByPK($match['id']); break; case 103: $resultsArray[] = ConvocatoriaPeer::retrieveByPK($match['id']); break; } } } } $this->results = $resultsArray; $this->title = sfContext::getInstance()->getI18N()->__('"%1%" en Voota', array('%1%' => $this->q)); $descStr = ""; foreach ($resultsArray as $idx => $result) { if ($idx < 3) { $descStr .= ($descStr ? ', ' : '') . $result; } } $this->response->addMeta('Description', sfContext::getInstance()->getI18N()->__('Resultados de la búsqueda "%1%" en Voota: %2%, ...', array('%1%' => $this->q, '%2%' => $descStr))); $this->response->setTitle($this->title); }