diff --git a/library/Metier/sphinx/rechercheFonc.php b/library/Metier/sphinx/rechercheFonc.php index c005b583..9cd1e14a 100644 --- a/library/Metier/sphinx/rechercheFonc.php +++ b/library/Metier/sphinx/rechercheFonc.php @@ -703,8 +703,9 @@ function reponse(&$resSphinx, &$resDB, $criteres, $time, $formR, $form2crit, } $pertinence_generale *= $num / $tot; $pertinence_generale = intval($pertinence_generale); - print 'Pertinence generale: '.$pertinence_generale.'
'; + //print 'Pertinence generale: '.$pertinence_generale.'
'; } + $decalage = false; for ($i = 0, $k = 0; $k < $resDB->num_rows || $decalage == true; ++$i) { if ($decalage == false) { @@ -713,67 +714,43 @@ function reponse(&$resSphinx, &$resDB, $criteres, $time, $formR, $form2crit, } else { $decalage = false; } - if ($formR['type']=='dir') { - debugln($ligneDir[$i]['id'].' '.$ligne['id']); + + $ret['reponses'][$i]['id'] = $ligne['id']; + $pertinence = $pertinence_generale; + if ($formR['type'] == 'ent') { + if (empty($formR['raisonSociale']) == false) { + $pertinence *= compare($formR['raisonSociale'], $ligne['raisonSociale']); + } + if (empty($formR['voie']) == false) { + $pertinence *= compare($formR['voie'], $ligne['adr_typeVoie'].' '.$ligne['adr_libVoie']); + } + if (empty($formR['ville']) == false) { + $pertinence *= compare($formR['ville'], $ligne['adr_ville']); + } } - if ($formR['type']=='dir' && $ligneDir[$i]['id']!=$ligne['id']) { - for ($j = $i - 1; $j >= 0; --$j) { - if ($ret['reponses'][$j]['id'] == $ligneDir[$i]['id']) { - $ret['reponses'][$i] = $ret['reponses'][$j]; - $decalage = true; - break; - } - } - if ($decalage != true) { - debugln('erreur '.$ligneDir[$i]['id'].' != '.$ligne['id']); - } - } else { - $ret['reponses'][$i]['id'] = $ligne['id']; - //if ($formR['type'] == 'dir') { - // debugln("$i:$ligne[id]"); - //} - $pertinence = $pertinence_generale; - if ($formR['type'] == 'ent') { - if (empty($formR['raisonSociale']) == false) { - $pertinence *= compare($formR['raisonSociale'], - $ligne['raisonSociale']); - } - if (empty($formR['voie']) == false) { - $pertinence *= compare($formR['voie'], - $ligne['adr_typeVoie'].' '. - $ligne['adr_libVoie']); - } - if (empty($formR['ville']) == false) { - $pertinence *= compare($formR['ville'], - $ligne['adr_ville']); - } - } - $ret['reponses'][$i]['Pertinence'] = $pertinence; - $ret['reponses'][$i]['Siret'] = $ligne['siret']; - $ret['reponses'][$i]['Siren'] = $ligne['siren']; - $ret['reponses'][$i]['Nic'] = $ligne['nic']; - $ret['reponses'][$i]['Siege'] = $ligne['siege']; - $ret['reponses'][$i]['Nom'] = $ligne['raisonSociale']; - $ret['reponses'][$i]['Nom2'] = ''; - $ret['reponses'][$i]['Sigle'] = $ligne['sigle']; - $ret['reponses'][$i]['Enseigne'] = $ligne['enseigne']; - $ret['reponses'][$i]['Adresse'] = + $ret['reponses'][$i]['Pertinence'] = $pertinence; + $ret['reponses'][$i]['Siret'] = $ligne['siret']; + $ret['reponses'][$i]['Siren'] = $ligne['siren']; + $ret['reponses'][$i]['Nic'] = $ligne['nic']; + $ret['reponses'][$i]['Siege'] = $ligne['siege']; + $ret['reponses'][$i]['Nom'] = $ligne['raisonSociale']; + $ret['reponses'][$i]['Nom2'] = ''; + $ret['reponses'][$i]['Sigle'] = $ligne['sigle']; + $ret['reponses'][$i]['Enseigne'] = $ligne['enseigne']; + $ret['reponses'][$i]['Adresse'] = $ligne['adr_num'].' '. $ligne['adr_typeVoie'].' '. $ligne['adr_libVoie']; - $ret['reponses'][$i]['Adresse2'] = $ligne['adr_comp']; - $ret['reponses'][$i]['CP'] = $ligne['adr_cp']; - $ret['reponses'][$i]['Ville'] = $ligne['adr_ville']; - $ret['reponses'][$i]['Tel'] = $ligne['tel']; - $ret['reponses'][$i]['Fax'] = $ligne['fax']; - $ret['reponses'][$i]['FJ'] = $ligne['cj']; - //$ret['reponses'][$i]['FJLib'] = ; - $ret['reponses'][$i]['Actif'] = $ligne['actif']; - $ret['reponses'][$i]['NafEtab'] = $ligne['ape_etab']; - //$ret['reponses'][$i]['NafEtabLib'] = ; - $ret['reponses'][$i]['NafEnt'] = $ligne['ape_entrep']; - //$ret['reponses'][$i]['NafEntLib'] = ; - } + $ret['reponses'][$i]['Adresse2'] = $ligne['adr_comp']; + $ret['reponses'][$i]['CP'] = $ligne['adr_cp']; + $ret['reponses'][$i]['Ville'] = $ligne['adr_ville']; + $ret['reponses'][$i]['Tel'] = $ligne['tel']; + $ret['reponses'][$i]['Fax'] = $ligne['fax']; + $ret['reponses'][$i]['FJ'] = $ligne['cj']; + $ret['reponses'][$i]['Actif'] = $ligne['actif']; + $ret['reponses'][$i]['NafEtab'] = $ligne['ape_etab']; + $ret['reponses'][$i]['NafEnt'] = $ligne['ape_entrep']; + if ($formR['type']=='dir') { // Dirigeant $ret['reponses'][$i]['DirRs'] = ''; @@ -952,19 +929,19 @@ function rechercheDir(&$formR, $deb, $nbRep, $max) } $requeteDB = - 'select e.id, d.nom, d.prenom, d.naissance_nom, d.naissance_date, d.naissance_lieu, l.libelle AS fonction_lib '. - ' from dirigeants d, etablissements e, bodacc_fonctions l'. - ' where d.siren=e.siren and d.fonction_code=l.codeFct AND e.siege=1 and (d.id='. - $resSphinx['matches'][0]['id']; + "SELECT e.id, d.nom, d.prenom, d.naissance_nom, d.naissance_date, d.naissance_lieu, l.libelle AS fonction_lib". + " FROM dirigeants d, etablissements e, bodacc_fonctions l". + " WHERE d.fonction_code=l.codeFct AND d.id IN (".$resSphinx['matches'][0]['id']; for ($i = 1; $i + $deb < $resSphinx['total'] && $i < $nbRep; ++$i) { - $requeteDB .= ' or d.id='.$resSphinx['matches'][$i]['id']; + $requeteDB .= ",".$resSphinx['matches'][$i]['id']; } - $requeteDB .= ')'; - $requeteDB .= ' GROUP BY d.siren, d.id'; - $requeteDB .= ' ORDER BY e.actif DESC, e.siege DESC, e.id ASC'; + $requeteDB .= ") AND e.id = ("; + $requeteDB .= "SELECT tmp.id FROM etablissements tmp "; + $requeteDB .= "WHERE tmp.siren=d.siren ORDER by tmp.actif DESC, tmp.siege DESC LIMIT 1"; + $requeteDB .= ")"; + debugln(); debugln("requeteDB='$requeteDB'"); - //file_put_contents('test.log', $requeteDB); $resDB = $gDatabaseJO->query($requeteDB); // Reponse @@ -974,7 +951,7 @@ function rechercheDir(&$formR, $deb, $nbRep, $max) $requeteDB = 'select id, CONCAT(siren,nic) AS siret, siren, nic, siege, '. 'raisonSociale, sigle, enseigne, adr_num, adr_typeVoie, adr_libVoie, '. 'adr_comp, adr_cp, adr_ville, tel, fax, cj, actif, ape_etab, '. - 'ape_entrep from etablissements where id='.$ligne['id']; + 'ape_entrep from etablissements where id IN ('.$ligne['id']; $ligneDir[0] = array( 'id' => $ligne['id'], @@ -987,7 +964,7 @@ function rechercheDir(&$formR, $deb, $nbRep, $max) ); for ($i = 1; $i < $resDB->num_rows; ++$i) { $ligne = $resDB->fetch_assoc(); - $requeteDB .= ' or id='.$ligne['id']; + $requeteDB .= ','.$ligne['id']; $nom = $ligne['nom']; if ( $ligne['naissance_nom']!='' ) { @@ -1003,7 +980,7 @@ function rechercheDir(&$formR, $deb, $nbRep, $max) 'naissance_lieu'=> $ligne['naissance_lieu'] ); } - $requeteDB .= ' ORDER BY actif DESC, siege DESC, id ASC'; + $requeteDB .= ') ORDER BY actif DESC, siege DESC'; debugln(); debugln("requeteDB='$requeteDB'"); $resDB = $gDatabaseJO->query($requeteDB); @@ -1487,8 +1464,7 @@ function rechercheEnt(&$formR, $deb, $nbRep, $max, $sirenValide = false) for ($i = 1; $i + $deb < $resSphinx['total'] && $i < $nbRep; ++$i) { $requeteDB .= ' or id='.$resSphinx['matches'][$i]['id']; } - $requeteDB .= - ' ORDER BY sirenValide DESC, actif DESC, siege DESC, rang DESC'; + $requeteDB .= ' ORDER BY sirenValide DESC, actif DESC, siege DESC, rang DESC'; debugln(); debugln("requeteDB='$requeteDB'");