Restructuration du code rechercheHisto et gestion des versions de moteur

This commit is contained in:
Michael RICOIS 2012-01-04 15:49:56 +00:00
parent 0661b2caa5
commit 1adc98970b
2 changed files with 71 additions and 11 deletions

View File

@ -82,7 +82,6 @@ Type[] = "PrivilegesDetailReturn"
Type[] = "PrivilegesDetail"
Type[] = "SearchActReturn"
Type[] = "EntrepriseActItem"
Type[] = "SupprAnnonceReturn"
Type[] = "CommandeEnqueteReturn"
Type[] = "DirigeantOp"
Type[] = "Depot"

View File

@ -2335,26 +2335,87 @@ class Interne extends WsScore
if (empty($nbRep)) $nbRep = 20;
if (empty($maxRep)) $maxRep = 200;
if (empty($annee)) $pertinence = false;
$liste = array();
$index = 'histo';
debugLog('I',"rechercheHisto de $recherche ($annee) (Max Rep=$nbRep)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
$tabFiltresAnnee = array();
$tabFiltres = array();
if ($annee<>'' && $annee*1>=1953 && $annee*1<=date('Y')*1)
$tabFiltresAnnee = array('annee1'=>$annee);
$tabFiltres = array('annee1'=>$annee);
/*
require_once 'Metier/sphinx/recherche2.php';
$ret=search2('histo', "$recherche", $tabFiltresAnnee, $deb, $nbRep, $maxRep, $pertinence);
/*require_once 'Metier/sphinx/sphinxsearch.php';
$sphinxsearch = new SphinxSearch();
$ret = $sphinxsearch->searchByHisto($recherche, $tabFiltresAnnee, $deb, $nbRep, $maxRep, $pertinence);
*/
$liste = $ret['results'];
$nbTot = $ret['nbTot'];
$duree = $ret['duration'];
$tabMots = $ret['words'];
if (SPHINX_HISTO_VERSION == 1){
require_once 'sphinxapi/sphinxapi-0.9.9.php';
} elseif (SPHINX_HISTO_VERSION == 2){
require_once 'sphinxapi/sphinxapi-2.0.2.php';
}
$cl = new SphinxClient();
$cl->SetServer (SPHINX_HISTO_HOST, SPHINX_HISTO_PORT);
$cl->SetConnectTimeout ( 1 );
$cl->SetLimits ($deb, $nbRep, $maxRep);
$cl->SetMatchMode (SPH_MATCH_EXTENDED);
foreach ($tabFiltres as $nomFiltre => $valFiltre)
$cl->SetFilter($nomFiltre, array(0=>$valFiltre));
$cl->SetRankingMode ( SPH_RANK_PROXIMITY_BM25 );
$res = $cl->Query ( $recherche, $index );
if ($res===false) {
debugLog('I',"Search Sphinx : Pas de réponse pour $recherche avec ".implode(',',$tabFiltres).' ('.$cl->GetLastError() .')',__LINE__,__FILE__, __FUNCTION__, __CLASS__);
$criteres = new RechercheHistoCriteres();
$criteres->recherche = $recherche;
$criteres->annee = $annee;
$output = new RechercheHistoReturn();
$output->criteres = $criteres;
$output->nbReponses = 0;
$output->nbReponsesTotal = 0;
$output->duree = $res[time];
$output->mots = array();
$output->reponses = array();
return $output;
}
// Le moteur est opérationel
if ( $cl->GetLastWarning() ) {
debugLog('I',"Search Sphinx : Warning pour $recherche - ".$cl->GetLastWarning(),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
//print "WARNING: " . $cl->GetLastWarning() . "\n\n";
}
debugLog('I',"'Search Sphinx dans $index de $recherche (Filtre=".implode(',',$tabFiltres)."), Deb=$deb, nbRep=$nbRep, max=$max, any=$any",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
$tabRet=array();
if ( is_array($res['matches'])) {
$iDb = new WDB();
foreach ( $res['matches'] as $doc => $docinfo )
{
$listeEtab=$iDb->select('histobodacc.bodacc_ocr',
"'Histo' as Loc, id, nomFichier, annee1, bod, texte",
"id=$doc");
$etab = $listeEtab[0];
$tabRet[]=array(
'Localisation' => $etab['Loc'],
'id' => $doc,
'Pertinence' => $docinfo['weight'],
'Fichier' => $etab['nomFichier'],
'Annee' => $etab['annee1'],
'Code' => $etab['bod'],
'Texte' => $etab['texte'],
);
}
}
debugLog('I','Search Sphinx : Retourne '. $res[total].'/'. $res[total_found] .' en '.$res[time] .'secondes',__LINE__,__FILE__, __FUNCTION__, __CLASS__);
$liste = $tabRet;
$nbTot = $res[total_found];
$duree = $res[time];
$tabMots = $res['words'];
$tabRet = array();
$k=0;