94,7 → 94,7 |
// AFAICT, pas de réel risque de SQL-injection du côté de sphinx (au pire, $req = FALSE) |
// et il serait dommage de devoir limiter la puissante syntaxe offerte à l'utilisation |
//$requeteTpl = "SELECT group_id, main_id FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste, i_nvjfl WHERE MATCH('%s') LIMIT 50"; |
$requeteTpl = 'SELECT group_id, main_id, id '. |
$requeteTpl = 'SELECT group_id, main_id, id, WEIGHT() AS poids '. |
'FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste, i_nvjfl '. |
"WHERE MATCH('%s') ". |
'LIMIT 50 '; |
104,7 → 104,9 |
if ($requete) { |
$res = array('spip' => array(), 'bazar' => array(), 'projet' => array(), 'papyrus' => array(), 'coste' => array(), 'nvjfl' => array()); |
$ids_par_poids = array(); |
while($rec = mysql_fetch_array($requete, MYSQL_ASSOC)) { |
$poidsMax = 0; |
while ($rec = mysql_fetch_array($requete, MYSQL_ASSOC)) { |
$poidsMax = ($rec['poids'] > $poidsMax) ? $rec['poids'] : $poidsMax; |
$res[$rec['group_id']][$rec['id']] = $rec; |
$ids_par_poids[] = $rec['main_id']; |
} |
112,74 → 114,67 |
$docs = array(); |
// spip |
$spip = new MoteurRecherche_SPIP(); |
foreach($spip->get(array_filter(array_keys($res['spip']), 'intval'), $q) as $v) { |
foreach ($spip->get(array_filter(array_keys($res['spip']), 'intval'), $q) as $v) { |
unset($res['spip'][$v['id']]['group_id'], |
$res['spip'][$v['id']]['main_id'], |
$res['spip'][$v['id']]['id']); |
// left: weight |
$res['spip'][$v['id']]['main_id'], |
$res['spip'][$v['id']]['id']); |
$docs['spip-' . $v['id']] = array_merge($v, $res['spip'][$v['id']]); |
} |
|
// bazar |
$bazar = new MoteurRecherche_BAZAR(); |
foreach($bazar->get(array_filter(array_keys($res['bazar']), 'intval'), $q) as $v) { |
foreach ($bazar->get(array_filter(array_keys($res['bazar']), 'intval'), $q) as $v) { |
unset($res['bazar'][$v['id']]['group_id'], |
$res['bazar'][$v['id']]['main_id'], |
$res['bazar'][$v['id']]['id']); |
// left: weight |
$res['bazar'][$v['id']]['main_id'], |
$res['bazar'][$v['id']]['id']); |
$docs['bazar-' . $v['id']] = array_merge($v, $res['bazar'][$v['id']]); |
} |
|
// projet |
$projet = new MoteurRecherche_PROJET(); |
foreach($projet->get(array_filter(array_keys($res['projet']), 'intval'), $q) as $v) { |
foreach ($projet->get(array_filter(array_keys($res['projet']), 'intval'), $q) as $v) { |
unset($res['projet'][$v['id']]['group_id'], |
$res['projet'][$v['id']]['main_id'], |
$res['projet'][$v['id']]['id']); |
// left: weight |
$res['projet'][$v['id']]['main_id'], |
$res['projet'][$v['id']]['id']); |
$docs['projet-' . $v['id']] = array_merge($v, $res['projet'][$v['id']]); |
} |
|
// papyrus |
$papyrus = new MoteurRecherche_PAPYRUS(); |
foreach($papyrus->get(array_filter(array_keys($res['papyrus']), 'intval'), $q) as $v) { |
foreach ($papyrus->get(array_filter(array_keys($res['papyrus']), 'intval'), $q) as $v) { |
unset($res['papyrus'][$v['id']]['group_id'], |
$res['papyrus'][$v['id']]['main_id'], |
$res['papyrus'][$v['id']]['id']); |
// left: weight |
$res['papyrus'][$v['id']]['main_id'], |
$res['papyrus'][$v['id']]['id']); |
$docs['papyrus-' . $v['id']] = array_merge($v, $res['papyrus'][$v['id']]); |
} |
|
// coste |
$coste = new MoteurRecherche_COSTE(); |
foreach($coste->get(array_filter(array_keys($res['coste']), 'intval'), $q) as $v) { |
foreach ($coste->get(array_filter(array_keys($res['coste']), 'intval'), $q) as $v) { |
unset($res['coste'][$v['id']]['group_id'], |
$res['coste'][$v['id']]['main_id'], |
$res['coste'][$v['id']]['id']); |
// left: weight |
$res['coste'][$v['id']]['main_id'], |
$res['coste'][$v['id']]['id']); |
$docs['coste-' . $v['id']] = array_merge($v, $res['coste'][$v['id']]); |
} |
|
// nvjfl |
$nvjfl = new MoteurRecherche_NVJFL(); |
foreach($nvjfl->get(array_filter(array_keys($res['nvjfl']), 'intval'), $q) as $v) { |
foreach ($nvjfl->get(array_filter(array_keys($res['nvjfl']), 'intval'), $q) as $v) { |
unset($res['nvjfl'][$v['id']]['group_id'], |
$res['nvjfl'][$v['id']]['main_id'], |
$res['nvjfl'][$v['id']]['id']); |
// left: weight |
$res['nvjfl'][$v['id']]['main_id'], |
$res['nvjfl'][$v['id']]['id']); |
$docs['nvjfl-' . $v['id']] = array_merge($v, $res['nvjfl'][$v['id']]); |
} |
//die('<pre>'.print_r($docs, true).'</pre>'); |
|
// sort |
$sorted = _sortArrayByArray($docs, $ids_par_poids); |
$max = current($sorted); |
$max = $max['weight']; |
|
if (isset($_GET['tri']) && $_GET['tri'] == 'date') { |
usort($sorted, '_actuNewerFirst'); |
} |
// transforme les clefs pour s'adapter aux templates existants |
array_walk($sorted, '_weight2score', $max); |
array_walk($sorted, '_weight2score', $poidsMax); |
|
// var_dump($sorted);die; |
$retour = $sorted; |
366,11 → 361,11 |
return isset($a['date_creation']) && isset($b['date_creation']) ? strcmp($b['date_creation'], $a['date_creation']) : 0; |
} |
|
// adaption aux templates existants: [score] => [weight] |
// Transforme un score en pourcentage |
function _weight2score(&$item, $key, $max) { |
$item['score'] = intval($item['weight'] / $max * 100); |
$item['score'] = intval($item['poids'] / $max * 100); |
$item['date_creation'] = isset($item['date_creation']) ? strftime("%d %B %Y", strtotime($item['date_creation'])) : ''; |
unset($item['weight']); |
unset($item['poids']); |
} |
|
?> |