issue #0000533 : Méthode rechercheHisto fonctionnelle
This commit is contained in:
parent
8ef44ca34d
commit
eae07a7de8
131
library/Metier/sphinx/sphinxsearch.php
Normal file
131
library/Metier/sphinx/sphinxsearch.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
require_once 'framework/common/strings.php';
|
||||
require_once realpath(dirname(__FILE__)).'/sphinxapi.php';
|
||||
|
||||
class SphinxCriteres
|
||||
{
|
||||
var $findMe = '';
|
||||
var $tabFiltres = array();
|
||||
var $position = 0;
|
||||
var $nbRep = 20;
|
||||
var $max = 200;
|
||||
var $any = false;
|
||||
}
|
||||
|
||||
class SphinxSearch
|
||||
{
|
||||
/**
|
||||
* Effectue une recherche en interrogeant le moteur Sphinx
|
||||
*
|
||||
* @param string $index
|
||||
* @param SphinxCriteres $criteres Critères de recherche
|
||||
* @return array $return Tableau des résultats
|
||||
*/
|
||||
public function search($name, $criteres)
|
||||
{
|
||||
debugLog('I',"Search Sphinx dans $name de ".$criteres->findMe." (".$criteres->deb.", ".$criteres->nbRep.", ".$criteres->max.") avec ".implode(',',$criteres->tabFiltres),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
||||
$cl = new SphinxClient();
|
||||
switch (strtolower($name)) {
|
||||
case 'entrep':
|
||||
|
||||
|
||||
break;
|
||||
case 'dir':
|
||||
|
||||
|
||||
|
||||
break;
|
||||
case 'histo':
|
||||
$cl->SetServer (SPHINX_HISTO_HOST, SPHINX_HISTO_PORT);
|
||||
$cl->SetConnectTimeout ( 1 );
|
||||
$cl->SetLimits ($criteres->position, $criteres->nbRep, $criteres->max);
|
||||
$cl->SetMatchMode (SPH_MATCH_EXTENDED);
|
||||
foreach ($criteres->tabFiltres as $nomFiltre => $valFiltre) {
|
||||
$cl->SetFilter($nomFiltre, array(0=>$valFiltre));
|
||||
}
|
||||
$cl->SetRankingMode ( SPH_RANK_PROXIMITY_BM25 );
|
||||
$res = $cl->Query ( $criteres->findMe, 'histo' );
|
||||
if ($res===false) {
|
||||
//Erreur
|
||||
debugLog('I',"Search Sphinx : Pas de réponse pour ".$criteres->findMe." avec ".implode(',',$criteres->tabFiltres).' ('.$cl->GetLastError() .')',__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
||||
return array(
|
||||
'results' => false,
|
||||
'nbRet' => 0,
|
||||
'nbTot' => 0,
|
||||
'duration' => 0);
|
||||
} else {
|
||||
|
||||
if ( $cl->GetLastWarning() ) {
|
||||
debugLog('I',"Search Sphinx : Warning pour $criteres->findMe - ".$cl->GetLastWarning(),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
||||
print "WARNING: " . $cl->GetLastWarning() . "\n\n";
|
||||
}
|
||||
|
||||
debugLog('I',"'Search Sphinx dans $name de $criteres->findMe (Filtre=".implode(',',$criteres->tabFiltres)."), Deb=".$criteres->position.", nbRep=".$criteres->nbRep.", max=".$criteres->max.", any=".$criteres->any,__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
||||
$tabRet = array();
|
||||
if ( is_array($res['matches'])) {
|
||||
$iDb = new WDB('histobodacc');
|
||||
$iDb->query("SET NAMES 'latin1';");
|
||||
foreach ( $res['matches'] as $doc => $docinfo ) {
|
||||
$listeEtab = $iDb->select(
|
||||
'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__);
|
||||
return array(
|
||||
'results' => $tabRet,
|
||||
'nbRet' => $res[total],
|
||||
'nbTot' => $res[total_found],
|
||||
'duration' => $res[time],
|
||||
'words' => $res['words'],
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode magique __call() permettant d'appeller une méthode virtuelle
|
||||
* du type searchByEnt(), searchByDir() ou searchByHisto()...
|
||||
*
|
||||
* @param string $method Nom de la méthode virtuelle appelée
|
||||
* @param array $args Tableau des critères de recherche
|
||||
* @return array|null $return Tableau des résultats ou NULL
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
debugLog('I',"Appel de la méthode '$method' ". implode(', ', $args),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
||||
if(preg_match('#^searchBy#i',$method))
|
||||
{
|
||||
$name = str_replace('searchBy','',$method);
|
||||
$criteres = array(
|
||||
0 => 'findMe',
|
||||
1 => 'tabFiltres',
|
||||
2 => 'position',
|
||||
3 => 'nbRep',
|
||||
4 => 'max',
|
||||
5 => 'any',
|
||||
);
|
||||
$searchArgs = new stdClass();
|
||||
$i = 0;
|
||||
foreach($args as $argument) {
|
||||
$searchArgs->{$criteres[$i]} = $argument;
|
||||
$i++;
|
||||
}
|
||||
return $this->search($name, $searchArgs);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -2829,7 +2829,8 @@ class Interne extends WsScore
|
||||
if (empty($maxRep)) $maxRep = 200;
|
||||
if (empty($annee)) $pertinence = false;
|
||||
|
||||
require_once 'framework/sphinx/recherche2.php';
|
||||
require_once 'Metier/sphinx/sphinxsearch.php';
|
||||
|
||||
debugLog('I',"rechercheHisto de $recherche ($annee) (Max Rep=$nbRep)",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
|
||||
|
||||
$tabFiltresAnnee = array();
|
||||
@ -2837,7 +2838,9 @@ class Interne extends WsScore
|
||||
if ($annee<>'' && $annee*1>=1953 && $annee*1<=date('Y')*1)
|
||||
$tabFiltresAnnee = array('annee1'=>$annee);
|
||||
|
||||
$ret = search2('idx_histo', "$recherche", $tabFiltresAnnee, $deb, $nbRep, $maxRep, $pertinence);
|
||||
$sphinxsearch = new SphinxSearch();
|
||||
$ret = $sphinxsearch->searchByHisto($recherche, $tabFiltresAnnee, $deb, $nbRep, $maxRep, $pertinence);
|
||||
|
||||
$liste = $ret['results'];
|
||||
$nbTot = $ret['nbTot'];
|
||||
$duree = $ret['duration'];
|
||||
@ -2845,9 +2848,10 @@ class Interne extends WsScore
|
||||
|
||||
$tabRet = array();
|
||||
$k=0;
|
||||
if(count($liste)>0) {
|
||||
foreach ($liste as $n=>$etab)
|
||||
{
|
||||
$texte=/*preg_replace('/ +/', ' ', */$etab['Texte'];//);
|
||||
$texte = $etab['Texte'];
|
||||
$posMin=100000;
|
||||
$hitMin=1000000;
|
||||
foreach ($tabMots as $mot=>$tabMot){
|
||||
@ -2857,22 +2861,21 @@ class Interne extends WsScore
|
||||
}
|
||||
}
|
||||
$posMin = stripos($texte, ''.$motSignificatif);
|
||||
//@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "Debug", print_r($tabMots,true).EOL.$motSignificatif.' trouvé en position '.$posMin) ;
|
||||
|
||||
if ($posMin<150) $posMin=150;
|
||||
$texte2=substr($texte, $posMin-150, 250);
|
||||
|
||||
|
||||
$texte2 = substr($texte, $posMin-150, 250);
|
||||
$reponse = new RechercheHistoReponses();
|
||||
$reponse->id = $etab['id'];
|
||||
$reponse->Pertinence = $etab['Pertinence'];
|
||||
$reponse->Fichier = strtr($etab['Fichier'], array('.txt'=>'.pdf', '/mnt/bodacc/'=>'http://tville.scores-decisions.com/bodacc/'));
|
||||
$reponse->Fichier = strtr($etab['Fichier'],
|
||||
array( '.txt'=>'.pdf', '/mnt/bodacc/' => 'http://tville.scores-decisions.com/bodacc/')
|
||||
);
|
||||
$reponse->Annee = $etab['Annee'];
|
||||
$reponse->Code = $etab['Code'];
|
||||
$reponse->Texte = preg_replace('/^[A-Za-z0-9\sàáâãäåæçèéêëìíîïðñòóôõöùúûüýÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝŸ]/','',$texte2);
|
||||
$reponse->Texte = utf8_encode($texte2);
|
||||
$tabRet[] = $reponse;
|
||||
$k++;
|
||||
}
|
||||
}
|
||||
|
||||
$criteres = new RechercheHistoCriteres();
|
||||
$criteres->recherche = $recherche;
|
||||
|
Loading…
x
Reference in New Issue
Block a user