Execution du ciblage

This commit is contained in:
Michael RICOIS 2015-06-09 15:54:31 +00:00
parent 3eabd646fc
commit d361a0feb0

View File

@ -35,7 +35,7 @@ class Scores_Ciblage_Engine
*/
public function __construct($structure = null, $filterRNCS = 0)
{
if ($filterRNCS==1) {
if ($filterRNCS == 1) {
$this->filterRNCS();
}
@ -168,44 +168,48 @@ class Scores_Ciblage_Engine
$siret[] = $element['attrs']['siren'].$element['attrs']['nic'];
}
return $siret;
} else
return array();
}
return array();
}
/**
*
* Execute le ciblage
* @param boolean $need
* Si true retourne les identifiants
* @param int $nbReturn
*
*/
public function execute($need = false, $nbReturn = 0)
{
if ($this->filterRNCS==1) {
// --- Active le filtre RNCS sur le profil du client
if ($this->filterRNCS==1) {
$this->sphinx->SetFilter('presentrcs', array(1));
}
if($need) {
// --- Retourne les identifiants
if( $need ) {
$return = array();
$limit = 1000;
$maxMatches = 50000;
// --- Set basic limit
if ( $nbReturn > 0 ) {
$limit = $nbReturn;
$maxMatches = $nbReturn;
$this->sphinx->SetSortMode( SPH_SORT_EXTENDED, '@random' );
}
// --- Replay the query
$this->sphinx->SetLimits(0, $limit, $maxMatches);
$resSphinx = $this->sphinx->Query($this->alpha, $this->index);
//Make an array with only the data needed
$total = $resSphinx['total_found'];
// --- Make an array with only the data needed
$return = $this->getSiret($resSphinx);
$total = $resSphinx['total_found'];
if ( $nbReturn == 0 && $limit<$total ) {
if ( $total > $limit ) {
$max = ceil($total/$limit);
//Get siret by $limit units for each request
for($i=1; $i<$max; $i++){
for($i=1; $i<$max; $i++) {
$offset = $i*$limit;
$this->sphinx->SetLimits($offset, $limit);
$resSphinx = $this->sphinx->Query($this->alpha, $this->index);
@ -215,8 +219,10 @@ class Scores_Ciblage_Engine
}
return $return;
} else {
}
// --- Retourne seulement le nombre total
else {
$this->sphinx->SetLimits(0, 1);
Zend_Registry::get('firebug')->info("Sphinx : ".$this->alpha);