2012-02-02 17:29:14 +00:00
|
|
|
<?php
|
2012-05-11 12:26:16 +00:00
|
|
|
/**
|
|
|
|
* Ciblage construct the request send to Sphinx
|
|
|
|
*/
|
|
|
|
class Ciblage
|
2012-02-02 17:29:14 +00:00
|
|
|
{
|
2012-05-11 12:26:16 +00:00
|
|
|
/**
|
|
|
|
* Name of the index store in Sphinx
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $index = 'ciblage';
|
2012-05-02 19:06:36 +00:00
|
|
|
|
2012-05-11 12:26:16 +00:00
|
|
|
/**
|
|
|
|
* Sphinx instantiation
|
|
|
|
* @var object
|
|
|
|
*/
|
|
|
|
protected $sphinx;
|
2012-05-02 19:06:36 +00:00
|
|
|
|
2012-05-11 12:26:16 +00:00
|
|
|
/**
|
|
|
|
* Construct request
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $alpha = '';
|
2012-05-02 19:06:36 +00:00
|
|
|
|
2012-05-11 12:26:16 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param array $structure
|
|
|
|
* @param boolean $need
|
|
|
|
*/
|
2012-02-02 17:29:14 +00:00
|
|
|
public function __construct($structure, $need = false)
|
|
|
|
{
|
2012-05-11 20:25:55 +00:00
|
|
|
Zend_Registry::get('firebug')->info($structure);
|
|
|
|
|
2012-05-11 12:26:16 +00:00
|
|
|
/*
|
|
|
|
* First of all we need to load the Sphinx API
|
|
|
|
* @todo : Make a test and load the right version of API
|
|
|
|
*/
|
|
|
|
require_once 'sphinxapi/sphinxapi-2.0.4.php';
|
|
|
|
|
2012-03-20 08:24:41 +00:00
|
|
|
$this->need = true;
|
2012-05-11 12:26:16 +00:00
|
|
|
|
|
|
|
//Load configuration from registry
|
2012-03-22 10:51:38 +00:00
|
|
|
$configuration = Zend_Registry::get('configuration');
|
2012-04-06 08:29:25 +00:00
|
|
|
|
2012-05-11 12:26:16 +00:00
|
|
|
//Sphinx init
|
2012-02-02 17:29:14 +00:00
|
|
|
$this->sphinx = new SphinxClient();
|
2012-05-11 20:25:55 +00:00
|
|
|
$this->sphinx->SetServer(
|
|
|
|
$configuration->sphinx->host,
|
|
|
|
intval($configuration->sphinx->port)
|
|
|
|
);
|
2012-02-02 17:29:14 +00:00
|
|
|
$this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
|
|
|
|
$this->sphinx->ResetFilters();
|
2012-05-11 12:26:16 +00:00
|
|
|
|
|
|
|
//
|
2012-05-11 20:25:55 +00:00
|
|
|
if ( count($structure)>0 ) {
|
|
|
|
foreach($structure as $key => $valeur) {
|
|
|
|
if ($key!= 'NB' && method_exists($this, $key)) {
|
|
|
|
$this->{$key}($valeur);
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-11 12:26:16 +00:00
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function setFilter($name, $valeur, $ex = false)
|
|
|
|
{
|
|
|
|
//All values must be integer
|
|
|
|
if ( is_array($valeur) ) {
|
|
|
|
$valeur = array_map('intval', $valeur);
|
|
|
|
} else {
|
|
|
|
$valeur = array(intval($valeur));
|
|
|
|
}
|
|
|
|
$this->sphinx->SetFilter($name, $valeur, $ex);
|
|
|
|
}
|
2012-05-11 12:26:16 +00:00
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function setFilterRange($name, $min, $max)
|
|
|
|
{
|
|
|
|
$this->sphinx->SetFilterRange($name, intval($min), intval($max));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function setAlpha($name, $valeur)
|
|
|
|
{
|
|
|
|
if ( $this->alpha!='' ) $this->alpha.= ' ';
|
|
|
|
$this->alpha.= '@'.$name.' '.$valeur;
|
2012-05-11 12:26:16 +00:00
|
|
|
}
|
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-22 09:29:53 +00:00
|
|
|
public function extract()
|
2012-02-21 13:39:02 +00:00
|
|
|
{
|
|
|
|
$resultats = $this->execute(true);
|
2012-02-22 09:29:53 +00:00
|
|
|
$siret = array();
|
|
|
|
foreach ($resutlats['matches'] as $element) {
|
2012-02-21 13:39:02 +00:00
|
|
|
$siret[] = $element['attrs']['siren'].$element['attrs']['nic'];
|
|
|
|
}
|
2012-02-22 09:29:53 +00:00
|
|
|
$total = array(
|
|
|
|
'total' => count($resultats),
|
|
|
|
'insee' => $this->calculRedevanceInsee(),
|
|
|
|
'result'=> $siret
|
2012-05-02 19:06:36 +00:00
|
|
|
);
|
2012-02-22 09:29:53 +00:00
|
|
|
return $total;
|
2012-02-21 13:39:02 +00:00
|
|
|
}
|
2012-05-11 12:26:16 +00:00
|
|
|
|
2012-02-02 17:29:14 +00:00
|
|
|
public function calculRedevanceInsee()
|
|
|
|
{
|
|
|
|
$this->sphinx->SetFilter('presentrcs', array(0));
|
|
|
|
$resSphinx = $this->sphinx->Query($this->alpha, $this->index);
|
|
|
|
return ($resSphinx['total_found']);
|
|
|
|
}
|
2012-05-11 12:26:16 +00:00
|
|
|
|
2012-03-15 15:44:10 +00:00
|
|
|
protected function getSiret($structure)
|
|
|
|
{
|
|
|
|
$siret = array();
|
2012-04-12 13:54:45 +00:00
|
|
|
if(count($structure['matches'])>0) {
|
|
|
|
foreach($structure['matches'] as $element){
|
|
|
|
$siret[] = $element['attrs']['siren'].$element['attrs']['nic'];
|
|
|
|
}
|
|
|
|
return ($siret);
|
2012-05-02 19:06:36 +00:00
|
|
|
} else
|
2012-04-12 13:54:45 +00:00
|
|
|
return (array());
|
2012-03-15 15:44:10 +00:00
|
|
|
}
|
2012-04-13 12:37:55 +00:00
|
|
|
public function execute($need = false, $limitD = false)
|
2012-02-02 17:29:14 +00:00
|
|
|
{
|
|
|
|
if($need) {
|
2012-03-15 15:44:10 +00:00
|
|
|
$return = array();
|
|
|
|
$limit = 0;
|
|
|
|
do {
|
2012-04-13 12:37:55 +00:00
|
|
|
$this->sphinx->SetLimits($limit, (($limitD!=false)?10:1000), 50000);
|
2012-03-15 15:44:10 +00:00
|
|
|
$resSphinx = $this->sphinx->Query($this->alpha, $this->index);
|
|
|
|
if(is_array($resSphinx))
|
|
|
|
$return = array_merge($return, $this->getSiret($resSphinx));
|
|
|
|
$limit = $limit + 1000;
|
2012-04-13 12:37:55 +00:00
|
|
|
}while($limit < (($limitD!=false)?10:$resSphinx['total_found']));
|
2012-03-15 15:44:10 +00:00
|
|
|
return ($return);
|
2012-05-10 09:24:05 +00:00
|
|
|
} else {
|
|
|
|
$this->sphinx->SetLimits(0, 1);
|
2012-03-15 15:44:10 +00:00
|
|
|
$resSphinx = $this->sphinx->Query($this->alpha, $this->index);
|
2012-05-10 09:24:05 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
Zend_Registry::get('firebug')->info("Sphinx : ".$this->alpha);
|
2012-05-10 09:24:05 +00:00
|
|
|
Zend_Registry::get('firebug')->info($resSphinx);
|
2012-05-11 12:26:16 +00:00
|
|
|
return $resSphinx['total_found'];
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-05-11 12:26:16 +00:00
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function siege($value)
|
2012-05-11 12:26:16 +00:00
|
|
|
{
|
2012-05-11 20:25:55 +00:00
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$this->setFilter('siege', $value);
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-11 12:26:16 +00:00
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
//Valeur NULL dans BDD
|
|
|
|
protected function groupe($value)
|
2012-04-10 13:20:08 +00:00
|
|
|
{
|
2012-05-11 20:25:55 +00:00
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
//$this->setFilter('sirenGrp', $value);
|
2012-04-10 13:20:08 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-02 19:06:36 +00:00
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function tel($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$this->setFilter('tel', $value);
|
|
|
|
}
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
|
|
|
|
protected function fax($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$this->setFilter('fax', $value);
|
|
|
|
}
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
|
|
|
|
protected function web($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$this->setFilter('web', $value);
|
|
|
|
}
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
|
|
|
|
protected function mail($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$this->setFilter('mail', $value);
|
|
|
|
}
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
|
|
|
|
protected function presentRcs($value)
|
2012-04-13 08:56:39 +00:00
|
|
|
{
|
2012-05-11 20:25:55 +00:00
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$this->setFilter('presentRcs', $value);
|
2012-04-13 08:56:39 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
|
|
|
|
protected function adrDom($value)
|
2012-04-13 08:56:39 +00:00
|
|
|
{
|
2012-05-11 20:25:55 +00:00
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$this->setFilter('adrDom', $value);
|
2012-04-13 08:56:39 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
|
|
|
|
protected function dirNom($value)
|
2012-04-13 08:56:39 +00:00
|
|
|
{
|
2012-05-11 20:25:55 +00:00
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$this->setFilter('dirNom', $value);
|
2012-04-13 08:56:39 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-02 19:06:36 +00:00
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function participation($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$this->setFilter('part', $value);
|
|
|
|
}
|
2012-04-13 15:33:59 +00:00
|
|
|
}
|
2012-02-20 14:07:14 +00:00
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function action($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$this->setFilter('actio', $value);
|
|
|
|
}
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
|
|
|
|
//Don't work
|
|
|
|
protected function dateCrea_etab($value)
|
|
|
|
{
|
|
|
|
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
|
|
|
|
//Don't work
|
|
|
|
protected function dateCrea_ent($value)
|
|
|
|
{
|
|
|
|
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
|
|
|
|
protected function nbActio($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$min = $value['in'][0];
|
|
|
|
$max = $value['in'][1];
|
|
|
|
$this->setFilterRange('nbActio', $min, $max);
|
|
|
|
}
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
|
|
|
|
protected function nbPart($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$min = $value['in'][0];
|
|
|
|
$max = $value['in'][1];
|
|
|
|
$this->setFilterRange('nbPart', $min, $max);
|
|
|
|
}
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-05-02 19:06:36 +00:00
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function nbMPubli($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$this->setFilter('nbMPubli', $value);
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-02 19:06:36 +00:00
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function capital($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$min = $value['in'][0];
|
|
|
|
$max = $value['in'][1];
|
|
|
|
$this->setFilterRange('capital', $min, $max);
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-02 19:06:36 +00:00
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function age_entrep($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$min = $value['in'][0];
|
|
|
|
$max = $value['in'][1];
|
|
|
|
$this->setFilterRange('age_entrep', $min, $max);
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-02 19:06:36 +00:00
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function age_etab($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$min = $value['in'][0];
|
|
|
|
$max = $value['in'][1];
|
|
|
|
$this->setFilterRange('age_etab', $min, $max);
|
|
|
|
}
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-05-02 19:06:36 +00:00
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function teff_entrep($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$this->setFilter('teff_entrep', $value);
|
2012-04-06 09:49:41 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
if ( array_key_exists('ex', $value) ) {
|
|
|
|
$this->setFilter('teff_entrep', $value, true);
|
2012-04-06 09:49:41 +00:00
|
|
|
}
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
|
|
|
|
protected function teff_etab($value)
|
|
|
|
{
|
|
|
|
if ( array_key_exists('in', $value) ) {
|
|
|
|
$this->setFilter('teff_etab', $value);
|
2012-04-05 15:50:33 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
if ( array_key_exists('ex', $value) ) {
|
|
|
|
$this->setFilter('teff_etab', $value, true);
|
|
|
|
}
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-05-02 19:06:36 +00:00
|
|
|
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function geo_domtom($value)
|
|
|
|
{
|
|
|
|
if( $value['in']==1 ) {
|
|
|
|
$this->setFilter('adr_dep', array(971, 972, 973, 974, 976), true);
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|
2012-04-05 15:50:33 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function geo_etranger($value)
|
|
|
|
{
|
|
|
|
if( $value['in']==1 ) {
|
|
|
|
$this->setFilter('adr_dep', array(986, 987, 988), true);
|
|
|
|
}
|
2012-04-05 15:50:33 +00:00
|
|
|
}
|
2012-05-11 20:25:55 +00:00
|
|
|
protected function geo_corse($value)
|
|
|
|
{
|
|
|
|
if( $value['in']==1 ) {
|
|
|
|
$this->setFilter('adr_dep', array(201, 202), true);
|
|
|
|
}
|
2012-04-05 15:50:33 +00:00
|
|
|
}
|
2012-02-02 17:29:14 +00:00
|
|
|
}
|