Suppression sphinx

This commit is contained in:
Michael RICOIS 2011-12-13 16:08:16 +00:00
parent 82b4456c44
commit d19d9bcbe3
11 changed files with 0 additions and 6325 deletions

View File

@ -1,215 +0,0 @@
<?
include_once(FWK_PATH.'common/strings.php');
include_once(FWK_PATH.'sphinx/sphinxapi2.php');
function search($index, $findMe, $tabFiltres=array(), $deb=0, $nbRep=20, $max=200, $any=false) {
$deb=$deb*1;
$nbRep=$nbRep*1;
$max=$max*1;
debugLog('I',"Search Sphinx dans $index de $findMe ($deb, $nbRep, $max) avec ".implode(',',$tabFiltres),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
$iDb=new WDB();
/*
$cl = new SphinxClient ();
$cl->SetServer ( $host, $port );
$cl->SetWeights ( array ( 100, 1 ) );
$cl->SetMatchMode ( $mode );
if ( count($filtervals) ) $cl->SetFilter ( $filter, $filtervals );
if ( $groupby ) $cl->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort );
if ( $sortby ) $cl->SetSortMode ( SPH_SORT_EXTENDED, $sortby );
if ( $sortexpr ) $cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr );
if ( $distinct ) $cl->SetGroupDistinct ( $distinct );
if ( $limit ) $cl->SetLimits ( 0, $limit, ( $limit>1000 ) ? $limit : 1000 );
$res = $cl->Query ( $q, $index );
*/
//$any = false; // si false $index='xxx'
$cl = new SphinxClient ();
$cl->SetServer (SPHINX_HOST, SPHINX_PORT);
$cl->SetConnectTimeout ( 1 );
$cl->SetLimits ($deb, $nbRep, $max);//0, $nbRep*10);
//$cl->SetSortMode(SPH_SORT_ATTR_DESC, 'actif');//siege');
if (substr($index,0,4)=='etab')
$cl->SetSortMode(SPH_SORT_EXTENDED, 'rang DESC, actif DESC, siege DESC');//, nic DESC
//$cl->SetWeights ( array ( 100, 1 ) );
//$cl->SetMatchMode ( $any ? SPH_MATCH_ANY : SPH_MATCH_ALL );
$cl->SetMatchMode (SPH_MATCH_EXTENDED);
foreach ($tabFiltres as $nomFiltre => $valFiltre)
$cl->SetFilter($nomFiltre, array(0=>$valFiltre));
$cl->SetRankingMode ( SPH_RANK_PROXIMITY_BM25 );
//$cl->SetArrayResult ( true );
$res = $cl->Query ( $findMe, $index );
if ($res===false) {
debugLog('I',"Search Sphinx : Pas de réponse pour $findMe avec ".implode(',',$tabFiltres).' ('.$cl->GetLastError() .')',__LINE__,__FILE__, __FUNCTION__, __CLASS__);
return array( 'results'=>false,
'nbRet'=>0,
'nbTot'=>0,
'duration'=>$res[time]);//return false;
} else { // Le moteur est opérationel
if ( $cl->GetLastWarning() ) {
debugLog('I',"Search Sphinx : Warning pour $findMe - ".$cl->GetLastWarning(),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
print "WARNING: " . $cl->GetLastWarning() . "\n\n";
}
/* print "Query '$findMe' retrieved $res[total] of $res[total_found] matches in $res[time] sec.\n";
print "Query stats :\n";
if ( is_array($res["words"]) )
foreach ( $res["words"] as $word => $info )
print " - '$word' found $info[hits] times in $info[docs] documents\n";
print "\n";*/
debugLog('I',"'Search Sphinx dans $index de $findMe (Filtre=".implode(',',$tabFiltres)."), Deb=$deb, nbRep=$nbRep, max=$max, any=$any",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
// debugLog('I',"Search Sphinx dans $index ". print_r($tabFiltres, true));
$tabRet=array();
if ( @is_array($res['matches'])) { // il y a des données à renvoyer
if (substr($index,0,4)=='etab') { // Recherche par étab
foreach ( $res['matches'] as $doc => $docinfo ) { // On balaye chaque ligne
$listeEtab=$iDb->select('etablissements e',
"'Etab' as Loc, e.id, e.source, e.source_id, e.triCode, e.autre_id, e.siren, e.nic, e.siege, ".
"e.raisonSociale, e.enseigne, e.sigle, e.adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, ".
"e.adr_comp, e.adr_cp, e.adr_ville, e.tel, e.fax, e.cj, e.ape_etab, e.ape_entrep, ".
"CONCAT(e.siren, e.nic) as siret, e.actif",
"id=$doc LIMIT 0,1", true);
$etab=$listeEtab[0];
$tabRet[]=array( 'Localisation'=>$etab['Loc'],
'id'=>$doc,
'Pertinence'=>$docinfo['weight'],
'Siret'=>$etab['siret'],
'Siege'=>$etab['siege'],
'Nom'=>$etab['raisonSociale'],
'Sigle'=>$etab['sigle'],
'Enseigne'=>$etab['enseigne'],
'Adresse'=>trim($etab['adr_num'] .' '.
$etab['adr_btq'] .' '.
$etab['adr_typeVoie'] .' '.
$etab['adr_libVoie'] .' '.
$etab['adr_comp']),
'CP'=>$etab['adr_cp'],
'Ville'=>$etab['adr_ville'],
'Tel'=>$etab['tel'],
'Fax'=>$etab['fax'],
'FJ'=>$etab['cj'],
'Siren'=>$etab['siren'],
'Nic'=>$etab['nic'],
'Actif'=>$etab['actif'],
'NafEtab'=>$etab['ape_etab'], // Etablissement
//'NafEtabLib'=>$etab['LibNafEt'],
'NafEnt'=>$etab['ape_entrep'], // Entreprise
//'NafEntLib'=>$etab['LibNafEt'],
);
}
} else { // Recherche par dirigeant
$findMe4=trim(substr($findMe,0,4));
foreach ( $res['matches'] as $doc => $docinfo ) { // On balaye chaque ligne dirigeant
/*$listeEtab=$iDb->select('bodacc_dirigeants d, bodacc_detail b, etablissements e',
"'Etab' as Loc, e.id, e.source, e.source_id, e.triCode, e.autre_id, e.siren, e.nic, e.siege, ".
"e.raisonSociale, e.enseigne, e.sigle, e.adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, ".
"e.adr_comp, e.adr_cp, e.adr_ville, e.tel, e.fax, e.cj, e.ape_etab, e.ape_entrep, ".
"CONCAT(e.siren, e.nic) as siret, d.rs, d.nom, d.prenom, d.nomUsage, ".
"d.dateEffet, d.fonction, d.depart, e.actif",
"d.id=$doc AND d.id=b.id AND b.siren=e.siren AND (d.nom LIKE '%$findMe4%' OR d.prenom LIKE '%$findMe4%' OR d.nomUsage LIKE '%$findMe4%' OR d.rs LIKE '%$findMe4%') LIMIT 0,1", true);
if (count($listeEtab)==0)
$listeEtab=$iDb->select('bodacc_dirigeants d, bodacc_detail b, etablissements e',
"'Etab' as Loc, e.id, e.source, e.source_id, e.triCode, e.autre_id, e.siren, e.nic, e.siege, ".
"e.raisonSociale, e.enseigne, e.sigle, e.adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, ".
"e.adr_comp, e.adr_cp, e.adr_ville, e.tel, e.fax, e.cj, e.ape_etab, e.ape_entrep, ".
"CONCAT(e.siren, e.nic) as siret, d.rs, d.nom, d.prenom, d.nomUsage, ".
"d.dateEffet, d.fonction, d.depart, e.actif",
"d.id=$doc AND d.id=b.id AND b.siren=e.siren LIMIT 0,1", true);
$etab=$listeEtab[0];
$tabRet[]=array( 'Localisation'=>$etab['Loc'],
'id'=>$doc,
'Pertinence'=>$docinfo['weight'],
'Siret'=>$etab['siret'],
'Siege'=>$etab['siege'],
'Nom'=>$etab['raisonSociale'],
'Sigle'=>$etab['sigle'],
'Enseigne'=>$etab['enseigne'],
'Adresse'=>trim($etab['adr_num'] .' '.
$etab['adr_btq'] .' '.
$etab['adr_typeVoie'] .' '.
$etab['adr_libVoie'] .' '.
$etab['adr_comp']),
'CP'=>$etab['adr_cp'],
'Ville'=>$etab['adr_ville'],
'Tel'=>$etab['tel'],
'Fax'=>$etab['fax'],
'FJ'=>$etab['cj'],
'Siren'=>$etab['siren'],
'Nic'=>$etab['nic'],
'Actif'=>$etab['actif'],
'NafEtab'=>$etab['ape_etab'], // Etablissement
'NafEnt'=>$etab['ape_entrep'], // Entreprise
'rs'=>$etab['rs'],
'nomD'=>$etab['nom'],
'prenom'=>$etab['prenom'],
'nomUsage'=>$etab['nomUsage'],
'dateEffet'=>$etab['dateEffet'],
'fonction'=>$etab['fonction'],
'depart'=>$etab['depart'],
);
}
*/
//print_r($tabRet);
//die();
$listeEtab=$iDb->select('rncs_dirigeants d, etablissements e',
"'Etab' as Loc, e.id, e.source, e.source_id, e.triCode, e.autre_id, e.siren, e.nic, e.siege, ".
"e.raisonSociale, e.enseigne, e.sigle, e.adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, ".
"e.adr_comp, e.adr_cp, e.adr_ville, e.tel, e.fax, e.cj, e.ape_etab, e.ape_entrep, ".
"CONCAT(e.siren, e.nic) as siret, /*d.rs,*/ d.nom, d.prenom, /*d.nomUsage,*/ d.naissance_date, d.naissance_lieu, ".
"d.fonction_lib, /*d.depart,*/ e.actif",
"d.id=$doc AND d.siren=e.siren AND e.siege=1 ORDER BY e.actif DESC LIMIT 0,1", true);
//die(print_r($listeEtab));
$etab=$listeEtab[0];
$tabRet[]=array( 'Localisation'=>$etab['Loc'],
'id'=>$doc,
'Pertinence'=>$docinfo['weight'],
'Siret'=>$etab['siret'],
'Siege'=>$etab['siege'],
'Nom'=>$etab['raisonSociale'],
'Sigle'=>$etab['sigle'],
'Enseigne'=>$etab['enseigne'],
'Adresse'=>trim($etab['adr_num'] .' '.
$etab['adr_btq'] .' '.
$etab['adr_typeVoie'] .' '.
$etab['adr_libVoie'] .' '.
$etab['adr_comp']),
'CP'=>$etab['adr_cp'],
'Ville'=>$etab['adr_ville'],
'Tel'=>$etab['tel'],
'Fax'=>$etab['fax'],
'FJ'=>$etab['cj'],
'Siren'=>$etab['siren'],
'Nic'=>$etab['nic'],
'Actif'=>$etab['actif'],
'NafEtab'=>$etab['ape_etab'], // Etablissement
'NafEnt'=>$etab['ape_entrep'], // Entreprise
'rs'=>'',//$etab['rs'],
'nomD'=>$etab['nom'],
'prenom'=>$etab['prenom'],
'nomUsage'=>'',//$etab['nomUsage'],
'dateEffet'=>'',//$etab['dateEffet'],
'fonction'=>$etab['fonction_lib'],
'depart'=>0,//$etab['depart'],
);
}
}
}
}
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],
);
}
?>

View File

@ -1,327 +0,0 @@
<?
include_once(FWK_PATH.'common/strings.php');
//include_once(FWK_PATH.'sphinx/sphinxapi2.php');
function search2($index, $findMe, $tabFiltres=array(), $deb=0, $nbRep=20, $max=200, $any=false) {
$deb=$deb*1;
$nbRep=$nbRep*1;
$max=$max*1;
debugLog('I',"Search Sphinx dans $index de $findMe ($deb, $nbRep, $max) avec ".implode(',',$tabFiltres),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
$iDb=new WDB();
/*
$cl = new SphinxClient ();
$cl->SetServer ( $host, $port );
$cl->SetWeights ( array ( 100, 1 ) );
$cl->SetMatchMode ( $mode );
if ( count($filtervals) ) $cl->SetFilter ( $filter, $filtervals );
if ( $groupby ) $cl->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort );
if ( $sortby ) $cl->SetSortMode ( SPH_SORT_EXTENDED, $sortby );
if ( $sortexpr ) $cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr );
if ( $distinct ) $cl->SetGroupDistinct ( $distinct );
if ( $limit ) $cl->SetLimits ( 0, $limit, ( $limit>1000 ) ? $limit : 1000 );
$res = $cl->Query ( $q, $index );
*/
//$any = false; // si false $index='xxx'
$cl = new SphinxClient();
if ($index == 'histo'){
$cl->SetServer (SPHINX_HISTO_HOST, SPHINX_HISTO_PORT);
} else {
$cl->SetServer (SPHINX_HOST, SPHINX_PORT);
}
$cl->SetConnectTimeout ( 1 );
$cl->SetLimits ($deb, $nbRep, $max);//0, $nbRep*10);
//$cl->SetSortMode(SPH_SORT_ATTR_DESC, 'actif');//siege');
if (substr($index,0,4)=='etab')
$cl->SetSortMode(SPH_SORT_EXTENDED, 'rang DESC, actif DESC, siege DESC');//, nic DESC
//$cl->SetWeights ( array ( 100, 1 ) );
//$cl->SetMatchMode ( $any ? SPH_MATCH_ANY : SPH_MATCH_ALL );
$cl->SetMatchMode (SPH_MATCH_EXTENDED);
foreach ($tabFiltres as $nomFiltre => $valFiltre)
$cl->SetFilter($nomFiltre, array(0=>$valFiltre));
$cl->SetRankingMode ( SPH_RANK_PROXIMITY_BM25 );
//$cl->SetArrayResult ( true );
$res = $cl->Query ( $findMe, $index );
//@sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "Debug", print_r($res,true)) ;
if ($res===false) {
debugLog('I',"Search Sphinx : Pas de réponse pour $findMe avec ".implode(',',$tabFiltres).' ('.$cl->GetLastError() .')',__LINE__,__FILE__, __FUNCTION__, __CLASS__);
return array( 'results'=>false,
'nbRet'=>0,
'nbTot'=>0,
'error'=>$cl->GetLastError(),
'warning'=>$cl->GetLastWarning(),
'duration'=>$res[time]);//return false;
} else { // Le moteur est opérationel
if ( $cl->GetLastWarning() ) {
debugLog('I',"Search Sphinx : Warning pour $findMe - ".$cl->GetLastWarning(),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
print "WARNING: " . $cl->GetLastWarning() . "\n\n";
}
/* print "Query '$findMe' retrieved $res[total] of $res[total_found] matches in $res[time] sec.\n";
print "Query stats :\n";
if ( is_array($res["words"]) )
foreach ( $res["words"] as $word => $info )
print " - '$word' found $info[hits] times in $info[docs] documents\n";
print "\n";*/
debugLog('I',"'Search Sphinx dans $index de $findMe (Filtre=".implode(',',$tabFiltres)."), Deb=$deb, nbRep=$nbRep, max=$max, any=$any",__LINE__,__FILE__, __FUNCTION__, __CLASS__);
// debugLog('I',"Search Sphinx dans $index ". print_r($tabFiltres, true));
$tabRet=array();
if ( @is_array($res['matches'])) { // il y a des données à renvoyer
if (substr($index,0,4)=='etab') { // Recherche par étab
foreach ( $res['matches'] as $doc => $docinfo ) { // On balaye chaque ligne
$listeEtab=$iDb->select('etablissements e',
"'Etab' as Loc, e.id, e.source, e.source_id, e.triCode, e.autre_id, e.siren, e.nic, e.siege, ".
"e.raisonSociale, e.enseigne, e.sigle, e.adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, ".
"e.adr_comp, e.adr_cp, e.adr_ville, e.tel, e.fax, e.cj, e.ape_etab, e.ape_entrep, ".
"CONCAT(e.siren, e.nic) as siret, e.actif",
"id=$doc LIMIT 0,1", true);
$etab=$listeEtab[0];
$tabRet[]=array( 'Localisation'=>$etab['Loc'],
'id'=>$doc,
'Pertinence'=>$docinfo['weight'],
'Siret'=>$etab['siret'],
'Siege'=>$etab['siege'],
'Nom'=>$etab['raisonSociale'],
'Sigle'=>$etab['sigle'],
'Enseigne'=>$etab['enseigne'],
'Adresse'=>trim($etab['adr_num'] .' '.
$etab['adr_btq'] .' '.
$etab['adr_typeVoie'] .' '.
$etab['adr_libVoie'] .' '.
$etab['adr_comp']),
'CP'=>$etab['adr_cp'],
'Ville'=>$etab['adr_ville'],
'Tel'=>$etab['tel'],
'Fax'=>$etab['fax'],
'FJ'=>$etab['cj'],
'Siren'=>$etab['siren'],
'Nic'=>$etab['nic'],
'Actif'=>$etab['actif'],
'NafEtab'=>$etab['ape_etab'], // Etablissement
//'NafEtabLib'=>$etab['LibNafEt'],
'NafEnt'=>$etab['ape_entrep'], // Entreprise
//'NafEntLib'=>$etab['LibNafEt'],
);
}
} elseif ($index=='histo') {
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'],
);
}
} else { // Recherche par dirigeant
$findMe4=trim(substr($findMe,0,4));
foreach ( $res['matches'] as $doc => $docinfo ) { // On balaye chaque ligne dirigeant
/*$listeEtab=$iDb->select('bodacc_dirigeants d, bodacc_detail b, etablissements e',
"'Etab' as Loc, e.id, e.source, e.source_id, e.triCode, e.autre_id, e.siren, e.nic, e.siege, ".
"e.raisonSociale, e.enseigne, e.sigle, e.adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, ".
"e.adr_comp, e.adr_cp, e.adr_ville, e.tel, e.fax, e.cj, e.ape_etab, e.ape_entrep, ".
"CONCAT(e.siren, e.nic) as siret, d.rs, d.nom, d.prenom, d.nomUsage, ".
"d.dateEffet, d.fonction, d.depart, e.actif",
"d.id=$doc AND d.id=b.id AND b.siren=e.siren AND (d.nom LIKE '%$findMe4%' OR d.prenom LIKE '%$findMe4%' OR d.nomUsage LIKE '%$findMe4%' OR d.rs LIKE '%$findMe4%') LIMIT 0,1", true);
if (count($listeEtab)==0)
$listeEtab=$iDb->select('bodacc_dirigeants d, bodacc_detail b, etablissements e',
"'Etab' as Loc, e.id, e.source, e.source_id, e.triCode, e.autre_id, e.siren, e.nic, e.siege, ".
"e.raisonSociale, e.enseigne, e.sigle, e.adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, ".
"e.adr_comp, e.adr_cp, e.adr_ville, e.tel, e.fax, e.cj, e.ape_etab, e.ape_entrep, ".
"CONCAT(e.siren, e.nic) as siret, d.rs, d.nom, d.prenom, d.nomUsage, ".
"d.dateEffet, d.fonction, d.depart, e.actif",
"d.id=$doc AND d.id=b.id AND b.siren=e.siren LIMIT 0,1", true);
$etab=$listeEtab[0];
$tabRet[]=array( 'Localisation'=>$etab['Loc'],
'id'=>$doc,
'Pertinence'=>$docinfo['weight'],
'Siret'=>$etab['siret'],
'Siege'=>$etab['siege'],
'Nom'=>$etab['raisonSociale'],
'Sigle'=>$etab['sigle'],
'Enseigne'=>$etab['enseigne'],
'Adresse'=>trim($etab['adr_num'] .' '.
$etab['adr_btq'] .' '.
$etab['adr_typeVoie'] .' '.
$etab['adr_libVoie'] .' '.
$etab['adr_comp']),
'CP'=>$etab['adr_cp'],
'Ville'=>$etab['adr_ville'],
'Tel'=>$etab['tel'],
'Fax'=>$etab['fax'],
'FJ'=>$etab['cj'],
'Siren'=>$etab['siren'],
'Nic'=>$etab['nic'],
'Actif'=>$etab['actif'],
'NafEtab'=>$etab['ape_etab'], // Etablissement
'NafEnt'=>$etab['ape_entrep'], // Entreprise
'rs'=>$etab['rs'],
'nomD'=>$etab['nom'],
'prenom'=>$etab['prenom'],
'nomUsage'=>$etab['nomUsage'],
'dateEffet'=>$etab['dateEffet'],
'fonction'=>$etab['fonction'],
'depart'=>$etab['depart'],
);
}
*/
//print_r($tabRet);
//die();
$listeEtab=$iDb->select('rncs_dirigeants d, etablissements e',
"'Etab' as Loc, e.id, e.source, e.source_id, e.triCode, e.autre_id, e.siren, e.nic, e.siege, ".
"e.raisonSociale, e.enseigne, e.sigle, e.adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, ".
"e.adr_comp, e.adr_cp, e.adr_ville, e.tel, e.fax, e.cj, e.ape_etab, e.ape_entrep, ".
"CONCAT(e.siren, e.nic) as siret, /*d.rs,*/ d.nom, d.prenom, /*d.nomUsage,*/ d.naissance_date, d.naissance_lieu, ".
"d.fonction_lib, /*d.depart,*/ e.actif",
"d.id=$doc AND d.siren=e.siren AND e.siege=1 ORDER BY e.actif DESC LIMIT 0,1", true);
//die(print_r($listeEtab));
$etab=$listeEtab[0];
$tabRet[]=array( 'Localisation'=>$etab['Loc'],
'id'=>$doc,
'Pertinence'=>$docinfo['weight'],
'Siret'=>$etab['siret'],
'Siege'=>$etab['siege'],
'Nom'=>$etab['raisonSociale'],
'Sigle'=>$etab['sigle'],
'Enseigne'=>$etab['enseigne'],
'Adresse'=>trim($etab['adr_num'] .' '.
$etab['adr_btq'] .' '.
$etab['adr_typeVoie'] .' '.
$etab['adr_libVoie'] .' '.
$etab['adr_comp']),
'CP'=>$etab['adr_cp'],
'Ville'=>$etab['adr_ville'],
'Tel'=>$etab['tel'],
'Fax'=>$etab['fax'],
'FJ'=>$etab['cj'],
'Siren'=>$etab['siren'],
'Nic'=>$etab['nic'],
'Actif'=>$etab['actif'],
'NafEtab'=>$etab['ape_etab'], // Etablissement
'NafEnt'=>$etab['ape_entrep'], // Entreprise
'rs'=>'',//$etab['rs'],
'nomD'=>$etab['nom'],
'prenom'=>$etab['prenom'],
'nomUsage'=>'',//$etab['nomUsage'],
'dateEffet'=>'',//$etab['dateEffet'],
'fonction'=>$etab['fonction_lib'],
'depart'=>0,//$etab['depart'],
);
}
}
}
}
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'],
);
}
/*
<nafen>7020z<
*/
function comptage($findMe, $tabFiltres=array(), $deb=0, $nbRep=20, $max=1000, $any=false, $fichierCsv=false) {
$deb=$deb*1;
$nbRep=$nbRep*1;
$max=$max*1;
$index='comptage';
$iDb=new WDB();
/*
$cl = new SphinxClient ();
$cl->SetServer ( $host, $port );
$cl->SetWeights ( array ( 100, 1 ) );
$cl->SetMatchMode ( $mode );
if ( count($filtervals) ) $cl->SetFilter ( $filter, $filtervals );
if ( $groupby ) $cl->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort );
if ( $sortby ) $cl->SetSortMode ( SPH_SORT_EXTENDED, $sortby );
if ( $sortexpr ) $cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr );
if ( $distinct ) $cl->SetGroupDistinct ( $distinct );
if ( $limit ) $cl->SetLimits ( 0, $limit, ( $limit>1000 ) ? $limit : 1000 );
$res = $cl->Query ( $q, $index );
*/
$cl = new SphinxClient ();
$cl->SetServer ('192.168.3.24', 3312);
$cl->SetConnectTimeout(1);
$cl->SetLimits ($deb, $nbRep, $max);
// if (substr($index,0,4)=='etab')
// $cl->SetSortMode(SPH_SORT_EXTENDED, 'rang DESC, actif DESC, siege DESC');//, nic DESC
//$cl->SetWeights ( array ( 100, 1 ) );
//$cl->SetMatchMode ( $any ? SPH_MATCH_ANY : SPH_MATCH_ALL );
$cl->SetMatchMode (SPH_MATCH_EXTENDED);
foreach ($tabFiltres as $nomFiltre => $valFiltre)
$cl->SetFilter($nomFiltre, $valFiltre);
/*8.4.3. SetFilterRange
Prototype: function SetFilterRange ( $attribute, $min, $max, $exclude=false )
Adds new integer range filter. */
$cl->SetRankingMode ( SPH_RANK_PROXIMITY_BM25 );
//$cl->SetArrayResult ( true );
$res = $cl->Query ( $findMe, $index );
if ($res===false) {
// debugLog('I',"Search Sphinx : Pas de réponse pour $findMe avec ".implode(',',$tabFiltres).' ('.$cl->GetLastError() .')',__LINE__,__FILE__, __FUNCTION__, __CLASS__);
return array( 'results'=>false,
'nbRet'=>0,
'nbTot'=>0,
'error'=>$cl->GetLastError(),
'warning'=>$cl->GetLastWarning(),
'durationCpt'=>$res[time],
'durationExp'=>0);//return false;);//return false;
} else { // Le moteur est opérationel
$tdeb=microtime(1);
if ( $cl->GetLastWarning() ) {
//debugLog('I',"Search Sphinx : Warning pour $findMe - ".$cl->GetLastWarning(),__LINE__,__FILE__, __FUNCTION__, __CLASS__);
print "WARNING: " . $cl->GetLastWarning() . "\n\n";
}
$tabRet=array();
if ( @is_array($res['matches'])) { // il y a des données à renvoyer
$tabIdDoc=array();
foreach ( $res['matches'] as $doc => $docinfo ) //{ // On balaye chaque ligne
$tabIdDoc[]=$doc;
$strDoc='('.implode(',',$tabIdDoc).')';
$tabTmp=$iDb->select( 'etablissements_act',
'id,ape_etab,ape_entrep,source,siren,nic,actif,siege,adr_cp,adr_dep,adr_com,tel,fax,cj,capital,age_entrep,age_etab,tca,tcaexp,teff_entrep,teff_etab,rang,dateCrea_etab,eff_entrep,eff_etab,nbEtab,bilType,bilAnnee,bilTca,bilCA,bilCAexp,bilRN',
"id IN $strDoc", false, MYSQL_ASSOC);
if ($fichierCsv) {
$fp=fopen($fichierCsv, 'w');
foreach ($tabTmp as $iTmp=>$tmp) {
$tabRet[]=$tmp;
fwrite($fp, implode("\t", $tmp).EOL);
}
fclose($fp);
}
}
}
return array( 'results'=>$tabRet,
'nbRet'=>$res[total],
'nbTot'=>$res[total_found],
'durationCpt'=>$res[time],
'durationExp'=>round(microtime(1)-$tdeb,3),
'error'=>$cl->GetLastError(),
'warning'=>$cl->GetLastWarning(),
'words'=>$res['words'],
);
}
?>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,187 +0,0 @@
<?
if (!isset($_REQUEST['typeRecherche']) || ( $_REQUEST['typeRecherche']<>'exacte' &&
$_REQUEST['typeRecherche']<>'approx') )
$_REQUEST['typeRecherche']='exacte';
if (!isset($_REQUEST['nbRep']) || $_REQUEST['nbRep']<25 || $_REQUEST['nbRep']>200 )
$_REQUEST['nbRep']=25;
if (!isset($_REQUEST['nom'])) $_REQUEST['nom']='';
if (!isset($_REQUEST['prenom'])) $_REQUEST['prenom']='';
if (!isset($_REQUEST['codePostal'])) $_REQUEST['codePostal']='';
?>
<form action="./?action=rechercher" method="POST">
<input type="hidden" name="submitted" value="1">
<table>
<tr><td><i>Informations sur la personne</i></td><td>&nbsp;</td></tr>
<tr><td><b>NOM *</b></td><td><input type="text" name="nom" value="<?=$_REQUEST['nom']?>"></td></tr>
<tr><td>Pr&eacute;nom *</td><td><input type="text" name="prenom" value="<?=$_REQUEST['prenom']?>"></td></tr>
<tr><td>D&eacute;partement ou Code Postal de r&eacute;sidence *</td><td><input type="text" name="codePostal" value="<?=$_REQUEST['codePostal']?>"></td></tr>
<tr><td>Civilit&eacute;</td><td><input type="radio" name="civilite" value="Mlle"> Mlle
<input type="radio" name="civilite" value="Mme"> Mme
<input type="radio" name="civilite" value="M"> M</td></tr>
<tr><td>Date de Naissance *</td><td><input type="text" name="naissJJ" size="3" maxlength="2">&nbsp;/&nbsp;<input type="text" name="naissMM" size="3" maxlength="2">&nbsp;/&nbsp;<input type="text" name="naissAA" size="5" maxlength="4"></td></tr>
<tr><td>Ville de Naissance</td><td><input type="text" name="naissVille"></td></tr>
<tr><td>D&eacute;partement de Naissance</td><td><input type="text" name="naissDept"></td></tr>
<tr><td>Pays de Naissance</td><td><input type="text" name="naissPays"></td></tr>
<tr><td>Adresse de r&eacute;sidence *</td><td><input type="text" name="adresse"></td></tr>
<tr><td>Ville de r&eacute;sidence *</td><td><input type="text" name="adresseVille"></td></tr>
<tr><td>Montant du cr&eacute;dit demand&eacute; *</td><td><input type="text" name="creditDemande"></td></tr>
<tr><td>SIREN si entrepreneur individuel</td><td><input type="text" name="siren"></td></tr>
<tr><td>RIB</td><td><input type="text" name="siren"></td></tr>
<tr><td>T&eacute;l&eacute;phone Domicile</td><td><input type="text" name="telephoneMaison">&nbsp;<i>Liste rouge <input type="radio" name="listeRouge" value="Oui"> Oui&nbsp;&nbsp;&nbsp;<input type="radio" name="listeRouge" value="Non"> Non</td></tr>
<tr><td>T&eacute;l&eacute;phone Professionel</td><td><input type="text" name="telephonePro"></td></tr>
<tr><td>T&eacute;l&eacute;phone Portable</td><td><input type="text" name="telephonePort"></td></tr>
<tr><td><i>Informations compl&eacute;mentaires</i></td><td>&nbsp;</td></tr>
<tr><td>Nom de l'employeur</td><td><input type="text" name="employeurNom"></td></tr>
<tr><td>Adresse de l'employeur</td><td><input type="text" name="employeurAdresse"></td></tr>
<tr><td>Code Postal de l'employeur</td><td><input type="text" name="employeurCP"></td></tr>
<tr><td>Ville de l'employeur</td><td><input type="text" name="employeurVille"></td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>Type de recherche</td><td><input type="radio" <?if ($_REQUEST['typeRecherche']=='exacte') echo 'CHECKED';?> name="typeRecherche" value="exacte">Exacte&nbsp;&nbsp;<input type="radio" <?if ($_REQUEST['typeRecherche']=='approx') echo 'CHECKED';?> name="typeRecherche" value="approx">Approchante</td></tr>
<tr><td>Nombre de r&eacute;sultats</td><td><select name="nbRep"><option value="25">25</option><option value="50">50</option><option value="100">100</option><option value="200">200</option></select></td></tr>
</table>
<input type="submit" value="Valider">&nbsp;&nbsp;&nbsp;<input type="reset" value="RAZ">
</form>
<?php
include_once('/var/www/includes/mysql.php');
$con = mysql_pconnect('localhost', 'root', 'bzh4231*');
if (!($con === false)) {
if (mysql_select_db('npaipp', $con) === false)
die('Could not select database: ' . mysql_error());
}
require ( "sphinxapi.php" );
//die ( "usage: php -f test.php [--any] <word [word [word [...]]]> [--group <group>] [-p <port>] [-i <index>]\n" );
$q = $_REQUEST['nom'].' '.$_REQUEST['prenom'];
$any = false; // si false $index='xxx'
$port = 3312;
if ($_REQUEST['typeRecherche']=='exacte')
$index="annuaire_pp";
else
$index="annuaire_pp_shx";
$nbRep=$_REQUEST['nbRep'];
////////////
// do query
////////////
$cl = new SphinxClient ();
$cl->SetServer ( "localhost", $port );
$cl->SetLimits (0, $nbRep);
$cl->SetWeights ( array ( 100, 1 ) );
$cl->SetMatchMode ( $any ? SPH_MATCH_ANY : SPH_MATCH_ALL );
if ( isset($_REQUEST['codePostal']) && $_REQUEST['codePostal']<>'' ) {
$tailleCP=strlen($_REQUEST['codePostal']);
if ($tailleCP>1 && $tailleCP<4) $cl->SetFilter("departement", array(0=>$_REQUEST['codePostal']));
elseif ($tailleCP==5) $cl->SetFilter("codepostal", array(0=>$_REQUEST['codePostal']));
}
if ( isset($_REQUEST['telephoneMaison']) && $_REQUEST['telephoneMaison']<>'' ) {
$cl->SetFilter("tel", array(0=>$_REQUEST['telephoneMaison']));
}
$res = $cl->Query ( $q, $index );
////////////////
// print me out
////////////////
if ( $res===false )
{
print "Query failed: " . $cl->GetLastError() . ".\n";
} else
{
if ( $cl->GetLastWarning() )
print "WARNING: " . $cl->GetLastWarning() . "\n\n";
print "Query '$q' retrieved $res[total] of $res[total_found] matches in $res[time] sec.<br/>";
print "<h3>Query stats</h3><ul>";
if ( is_array($res["words"]) )
foreach ( $res["words"] as $word => $info )
print "<li>'$word' found $info[hits] times in $info[docs] documents</li>";
print "</ul>";
if ( is_array($res["matches"]) )
{
$n = 1;
print "<h3>Reponses :</h3><ul>";
foreach ( $res["matches"] as $doc => $docinfo )
{
// print "<li>$n. doc_id=$doc, weight=$docinfo[weight]<br/>";
// foreach ( $res["attrs"] as $attrname => $attrtype )
// {
$info=mysql_select('particuliers', 'Nom, Adresse, CodePostal, Ville, Tel, Fax', "id=$doc");
$personne=$info[0];
echo '<li><i>'. $n .'.</i> '. $personne['Nom'] .' ('. $docinfo[weight] .' %)<br/>';
echo $personne['Adresse'] .'<br/>';
echo $personne['CodePostal'] .' '. $personne['Ville'] .'<br/>';
if ($personne['Tel']<>'') echo 'T&eacute;l : '.$personne['Tel'].'<br/>';
if ($personne['Fax']<>'') echo 'Fax : '.$personne['Fax'].'<br/>';
echo "</li>\n";
$n++;
/* $value = $docinfo["attrs"][$attrname];
if ( $attrtype==SPH_ATTR_TIMESTAMP )
$value = date ( "Y-m-d H:i:s", $value );
print ", $attrname=$value";
}
print "</li>";*/
//$n++;
}
print "</ul>";
}
echo '<!--';
print_r($res);
echo '-->';
if ($_POST['submitted']) {
print_r($_POST);
/* Actions à effectuer :
// 1. Vérification de l'existance du NOM, Prénom et Adresse dans Annuaire (/30 points)
1.1. Si NOM+Prénom à l'adresse ==> OK 30 points
1.2. Si NOM sans prénom à l'adresse ==> OK 25 points
1.3. Si quelqu'un dans annuaire à l'adresse 10 points
1.4. Si pas d'adresse 0 point
// Si 1.2 ==> 2
// Si 1.3 ==> 2 + 3
// Si 1.4 ==> 2 + 3 + 4
// 2. Vérifier si le prénom existe dans la table des prénoms (/ 3 points)
2.1. Si le prénom existe OK 2 points
2.2. Sinon valeur approchante 1 point
2.3. Sinon ?????????? 0 point
// 3. Vérifier si le nom existe dans la table des noms (/ 3 points)
1.1. Si le nom existe OK 2 points
1.2. Sinon valeur approchante 1 point
1.3. Sinon 0 point
// 4. Recherche de l'existance de l'adresse / ville (/ 5 points)
2.1. Si adresse complète existe 5 points
2.2. Si adresse sans 3 points
2.3. Si approchant 2 points
2.4. Si ville sans l'adresse 0 point
//10. Vérifier si le prénom est logique avec les l'age moyen des personnes portant ce prénom (/ 3 points)
2.4.1. Si logique OK 2 points
2.4.2. Si approchant 1 point
2.4.3. Sinon 0 point
3.3.1 Vérification dans le pages blanches
// 3. Si un téléphone est communiqué et qu'absence de liste rouge : (30 points)
3.1. Vérifier la concordance NOM, Prénom, Adresse, Téléphonesi OK 30 point
Enregistrer chaque requête
et les informations communqiuées par le client
*/
}
}
?>

View File

@ -1,157 +0,0 @@
<?php
//
// $Id: test.php 1103 2008-01-24 18:42:57Z shodan $
//
require ( "sphinxapi.php" );
//////////////////////
// parse command line
//////////////////////
// for very old PHP versions, like at my home test server
if ( is_array($argv) && !isset($_SERVER["argv"]) )
$_SERVER["argv"] = $argv;
unset ( $_SERVER["argv"][0] );
// build query
if ( !is_array($_SERVER["argv"]) || empty($_SERVER["argv"]) )
{
print ( "Usage: php -f test.php [OPTIONS] query words\n\n" );
print ( "Options are:\n" );
print ( "-h, --host <HOST>\tconnect to searchd at host HOST\n" );
print ( "-p, --port\t\tconnect to searchd at port PORT\n" );
print ( "-i, --index <IDX>\tsearch through index(es) specified by IDX\n" );
print ( "-s, --sortby <CLAUSE>\tsort matches by 'CLAUSE' in sort_extended mode\n" );
print ( "-S, --sortexpr <EXPR>\tsort matches by 'EXPR' DESC in sort_expr mode\n" );
print ( "-a, --any\t\tuse 'match any word' matching mode\n" );
print ( "-b, --boolean\t\tuse 'boolean query' matching mode\n" );
print ( "-e, --extended\t\tuse 'extended query' matching mode\n" );
print ( "-ph,--phrase\t\tuse 'exact phrase' matching mode\n" );
print ( "-f, --filter <ATTR>\tfilter by attribute 'ATTR' (default is 'group_id')\n" );
print ( "-v, --value <VAL>\tadd VAL to allowed 'group_id' values list\n" );
print ( "-g, --groupby <EXPR>\tgroup matches by 'EXPR'\n" );
print ( "-gs,--groupsort <EXPR>\tsort groups by 'EXPR'\n" );
print ( "-d, --distinct <ATTR>\tcount distinct values of 'ATTR''\n" );
print ( "-l, --limit <COUNT>\tretrieve COUNT matches (default: 20)\n" );
exit;
}
$args = array();
foreach ( $_SERVER["argv"] as $arg )
$args[] = $arg;
$q = "";
$mode = SPH_MATCH_ALL;
$host = "localhost";
$port = 3312;
$index = "*";
$groupby = "";
$groupsort = "@group desc";
$filter = "group_id";
$filtervals = array();
$distinct = "";
$sortby = "";
$limit = 20;
$ranker = SPH_RANK_PROXIMITY_BM25;
for ( $i=0; $i<count($args); $i++ )
{
$arg = $args[$i];
if ( $arg=="-h" || $arg=="--host" ) $host = $args[++$i];
else if ( $arg=="-p" || $arg=="--port" ) $port = (int)$args[++$i];
else if ( $arg=="-i" || $arg=="--index" ) $index = $args[++$i];
else if ( $arg=="-s" || $arg=="--sortby" ) { $sortby = $args[++$i]; $sortexpr = ""; }
else if ( $arg=="-S" || $arg=="--sortexpr" ) { $sortexpr = $args[++$i]; $sortby = ""; }
else if ( $arg=="-a" || $arg=="--any" ) $mode = SPH_MATCH_ANY;
else if ( $arg=="-b" || $arg=="--boolean" ) $mode = SPH_MATCH_BOOLEAN;
else if ( $arg=="-e" || $arg=="--extended" ) $mode = SPH_MATCH_EXTENDED;
else if ( $arg=="-e2" ) $mode = SPH_MATCH_EXTENDED2;
else if ( $arg=="-ph"|| $arg=="--phrase" ) $mode = SPH_MATCH_PHRASE;
else if ( $arg=="-f" || $arg=="--filter" ) $filter = $args[++$i];
else if ( $arg=="-v" || $arg=="--value" ) $filtervals[] = $args[++$i];
else if ( $arg=="-g" || $arg=="--groupby" ) $groupby = $args[++$i];
else if ( $arg=="-gs"|| $arg=="--groupsort" ) $groupsort = $args[++$i];
else if ( $arg=="-d" || $arg=="--distinct" ) $distinct = $args[++$i];
else if ( $arg=="-l" || $arg=="--limit" ) $limit = (int)$args[++$i];
else if ( $arg=="-r" )
{
$arg = strtolower($args[++$i]);
if ( $arg=="bm25" ) $ranker = SPH_RANK_BM25;
if ( $arg=="none" ) $ranker = SPH_RANK_NONE;
if ( $arg=="wordcount" )$ranker = SPH_RANK_WORDCOUNT;
}
else
$q .= $args[$i] . " ";
}
////////////
// do query
////////////
$cl = new SphinxClient ();
$cl->SetServer ( $host, $port );
$cl->SetWeights ( array ( 100, 1 ) );
$cl->SetMatchMode ( $mode );
if ( count($filtervals) ) $cl->SetFilter ( $filter, $filtervals );
if ( $groupby ) $cl->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort );
if ( $sortby ) $cl->SetSortMode ( SPH_SORT_EXTENDED, $sortby );
if ( $sortexpr ) $cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr );
if ( $distinct ) $cl->SetGroupDistinct ( $distinct );
if ( $limit ) $cl->SetLimits ( 0, $limit, ( $limit>1000 ) ? $limit : 1000 );
$cl->SetRankingMode ( $ranker );
$cl->SetArrayResult ( true );
$res = $cl->Query ( $q, $index );
////////////////
// print me out
////////////////
if ( $res===false )
{
print "Query failed: " . $cl->GetLastError() . ".\n";
} else
{
if ( $cl->GetLastWarning() )
print "WARNING: " . $cl->GetLastWarning() . "\n\n";
print "Query '$q' retrieved $res[total] of $res[total_found] matches in $res[time] sec.\n";
print "Query stats:\n";
if ( is_array($res["words"]) )
foreach ( $res["words"] as $word => $info )
print " '$word' found $info[hits] times in $info[docs] documents\n";
print "\n";
if ( is_array($res["matches"]) )
{
$n = 1;
print "Matches:\n";
foreach ( $res["matches"] as $docinfo )
{
print "$n. doc_id=$docinfo[id], weight=$docinfo[weight]";
foreach ( $res["attrs"] as $attrname => $attrtype )
{
$value = $docinfo["attrs"][$attrname];
if ( $attrtype & SPH_ATTR_MULTI )
{
$value = "(" . join ( ",", $value ) .")";
} else
{
if ( $attrtype==SPH_ATTR_TIMESTAMP )
$value = date ( "Y-m-d H:i:s", $value );
}
print ", $attrname=$value";
}
print "\n";
$n++;
}
}
}
//
// $Id: test.php 1103 2008-01-24 18:42:57Z shodan $
//
?>

View File

@ -1,53 +0,0 @@
<?php
//
// $Id: test2.php 910 2007-11-16 11:43:46Z shodan $
//
require ( "sphinxapi.php" );
$docs = array
(
"this is my test text to be highlighted, and for the sake of the testing we need to pump its length somewhat",
"another test text to be highlighted, below limit",
"test number three, without phrase match",
"final test, not only without phrase match, but also above limit and with swapped phrase text test as well",
);
$words = "test text";
$index = "test1";
$opts = array
(
"before_match" => "<b>",
"after_match" => "</b>",
"chunk_separator" => " ... ",
"limit" => 60,
"around" => 3,
);
foreach ( array(0,1) as $exact )
{
$opts["exact_phrase"] = $exact;
print "exact_phrase=$exact\n";
$cl = new SphinxClient ();
$res = $cl->BuildExcerpts ( $docs, $index, $words, $opts );
if ( !$res )
{
die ( "ERROR: " . $cl->GetLastError() . ".\n" );
} else
{
$n = 0;
foreach ( $res as $entry )
{
$n++;
print "n=$n, res=$entry\n";
}
print "\n";
}
}
//
// $Id: test2.php 910 2007-11-16 11:43:46Z shodan $
//
?>

View File

@ -1,44 +0,0 @@
<?php
//
// $Id: test2.php,v 1.4 2006/11/26 12:24:21 shodan Exp $
//
require ( "sphinxapi.php" );
$docs = array
(
"this is my test text to be highlighted",
"this is another test text to be highlighted",
);
$words = "test text";
$index = "test1";
$opts = array
(
"before_match" => "<b>",
"after_match" => "</b>",
"chunk_separator" => " ... ",
"limit" => 400,
"around" => 15
);
$cl = new SphinxClient ();
$res = $cl->BuildExcerpts ( $docs, $index, $words, $opts );
if ( !$res )
{
die ( "ERROR: " . $cl->GetLastError() . ".\n" );
} else
{
foreach ( $res as $entry )
{
$n++;
print "n=$n, res=$entry\n";
}
}
//
// $Id: test2.php,v 1.4 2006/11/26 12:24:21 shodan Exp $
//
?>

View File

@ -1,108 +0,0 @@
#!/usr/bin/php -q
<?php
//
// $Id: test.php,v 1.12 2006/11/26 12:24:21 shodan Exp $
//
require ( "sphinxapi.php" );
//////////////////////
// parse command line
//////////////////////
// for very old PHP versions, like at my home test server
if ( is_array($argv) && !isset($_SERVER["argv"]) )
$_SERVER["argv"] = $argv;
unset ( $_SERVER["argv"][0] );
// build query
if ( !is_array($_SERVER["argv"]) || empty($_SERVER["argv"]) )
die ( "usage: php -f test.php [--any] <word [word [word [...]]]> [--group <group>] [-p <port>] [-i <index>]\n" );
$args = array();
foreach ( $_SERVER["argv"] as $arg )
$args[] = $arg;
$q = "";
$any = false;
$groups = array();
$port = 3312;
$index = "*";
for ( $i=0; $i<count($args); $i++ )
{
if ( $args[$i]=="--any" )
{
$any = true;
} else if ( $args[$i]=="--group" )
{
$groups[] = (int)$args[++$i];
} else if ( $args[$i]=="-p" )
{
$port = (int)$args[++$i];
} else if ( $args[$i]=="-i" )
{
$index = $args[++$i];
} else
{
$q .= $args[$i] . " ";
}
}
////////////
// do query
////////////
$cl = new SphinxClient ();
$cl->SetServer ( "localhost", $port );
$cl->SetWeights ( array ( 100, 1 ) );
$cl->SetMatchMode ( $any ? SPH_MATCH_ANY : SPH_MATCH_ALL );
if ( count($groups) )
$cl->SetFilter ( "group_id", $groups );
$res = $cl->Query ( $q, $index );
////////////////
// print me out
////////////////
if ( $res===false )
{
print "Query failed: " . $cl->GetLastError() . ".\n";
} else
{
if ( $cl->GetLastWarning() )
print "WARNING: " . $cl->GetLastWarning() . "\n\n";
print "Query '$q' retrieved $res[total] of $res[total_found] matches in $res[time] sec.\n";
print "Query stats:\n";
if ( is_array($res["words"]) )
foreach ( $res["words"] as $word => $info )
print " '$word' found $info[hits] times in $info[docs] documents\n";
print "\n";
if ( is_array($res["matches"]) )
{
$n = 1;
print "Matches:\n";
foreach ( $res["matches"] as $doc => $docinfo )
{
print "$n. doc_id=$doc, weight=$docinfo[weight]";
foreach ( $res["attrs"] as $attrname => $attrtype )
{
$value = $docinfo["attrs"][$attrname];
if ( $attrtype==SPH_ATTR_TIMESTAMP )
$value = date ( "Y-m-d H:i:s", $value );
print ", $attrname=$value";
}
print "\n";
$n++;
}
}
}
//
// $Id: test.php,v 1.12 2006/11/26 12:24:21 shodan Exp $
//
?>

File diff suppressed because it is too large Load Diff