SetFilter('annee1', array(0=>$formR['annee1'])); $sphinx->SetRankingMode ( SPH_RANK_PROXIMITY_BM25 ); $sphinxreturn = $sphinx->Query($formR['recherche'], $index); $gDatabaseJO->select_db('histobodacc'); foreach ( $sphinxreturn['matches'] as $doc => $docinfo ) { $requette = "SELECT Histo as Loc, id, nomFichier, annee1, bod, texte FROM bodacc_cor WHERE id=$doc"; $req = $gDatabaseJO->query($requette); $ligne = $req->fetch_assoc(); $etab = $ligne[0]; $tabRet[] = array( 'Localisation' => $etab['Loc'], 'id' => $doc, 'Pertinence' => $docinfo['weight'], 'Fichier' => $etab['nomFichier'], 'Annee' => $etab['annee1'], 'Code' => $etab['bod'], 'Texte' => $etab['texte'], ); } return array( 'results' => $tabRet, 'nbRet' => $sphinxreturn['total'], 'nbTot' => $sphinxreturn['total_found'], 'duration' => $sphinxreturn['time'], 'words' => $sphinxreturn['words'], ); } $dsn="mysql:host=127.0.0.1; dbname=test; charset=utf8;"; $username="member"; $password=""; $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'); $db=new PDO($dsn, $username, $password, $options); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE); $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); $query=$db->prepare(" SELECT * FROM test WHERE MATCH (name, location) AGAINST (:search IN BOOLEAN MODE) LIMIT 0, 10 "); $query->bindValue(':search', $search, PDO::PARAM_STR); $query->execute(); while($data=$query->fetch(PDO::FETCH_ASSOC)){ } SELECT select_expr [, select_expr ...] FROM index [, index2 ...] [WHERE where_condition] [GROUP BY {col_name | expr_alias} [, {sol_name | expr_alias}]] [WITHIN GROUP ORDER BY {col_name | expr_alias} {ASC | DESC}] [ORDER BY {col_name | expr_alias} {ASC | DESC} [, ...]] [LIMIT [offset,] row_count] [OPTION opt_name = opt_value [, ...]] */ class SdMetier_Search_Histo { protected $index = 'histo'; protected $host; protected $port; protected $username = 'member'; protected $password = ''; protected $db; protected $query; public function __construct() { $this->host = SPHINX_HISTO_HOST; $this->port = SPHINX_HISTO_PORT; $this->setDb(); } protected function setDb() { $dsn="mysql:host=".$this->host."; dbname=".$this->index."; charset=utf8;"; $username="member"; $password=""; $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'); $this->db=new PDO($dsn, $this->username, $this->password, $options); $this->db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE); $this->db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); } protected function setQuery() { $this->query = "SELECT id"; $this->query.= " FROM ".$this->index.""; $this->query.= " WHERE annee1=".$annee." AND MATCH()"; $this->query.= " [GROUP BY {col_name | expr_alias} [, {sol_name | expr_alias}]]"; $this->query.= " [WITHIN GROUP ORDER BY {col_name | expr_alias} {ASC | DESC}]"; $this->query.= " [ORDER BY {col_name | expr_alias} {ASC | DESC} [, ...]]"; $this->query.= " [LIMIT [offset,] row_count]"; $this->query.= " OPTION ranker=proximity_bm25"; } public function Query() { $query=$db->prepare(" SELECT select_expr [, select_expr ...] FROM ".$this->index." [WHERE where_condition] [GROUP BY {col_name | expr_alias} [, {sol_name | expr_alias}]] [WITHIN GROUP ORDER BY {col_name | expr_alias} {ASC | DESC}] [ORDER BY {col_name | expr_alias} {ASC | DESC} [, ...]] [LIMIT [offset,] row_count] [OPTION opt_name = opt_value [, ...]] "); $query->bindValue(':search', $search, PDO::PARAM_STR); $query->execute(); while($data=$query->fetch(PDO::FETCH_ASSOC)){ } } }