Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 2122 → Rev 2123

/trunk/papyrus/applettes/moteur_recherche/moteur_recherche_sphinx.php
180,7 → 180,34
}
}
 
class MoteurRecherche_NVJFL {
public function get($ids, $q = NULL) {
if(!$ids) return array();
// DB access is dumb, let's use this one and pray
$db = $GLOBALS['_MOTEUR_RECHERCHE_']['bd']['papyrus'];
$req = $db->query(sprintf(<<<EOF
SELECT b.num_nom AS id, CONCAT(nom_sci, ' (nn: ', b.num_nom, ', nt: ', num_taxonomique, ')') AS titre, GROUP_CONCAT(n.nom_vernaculaire) AS description
FROM tb_eflore.bdtfx_v1_02 b
LEFT JOIN tb_eflore.nvjfl_v2007 n ON n.num_taxon = b.num_taxonomique
WHERE b.num_nom IN (%s)
GROUP BY n.num_taxon
EOF
,
implode(',', $ids)));
 
(DB::isError($req)) ? die($req->getMessage()) : '';
$content = array();
while($rec = $req->fetchRow(DB_FETCHMODE_ASSOC)) {
$rec['url_simple'] = $rec['url'] = sprintf("http://%s/bdtfx-nn-%d", _MRS_SPHINX_BASEHOST, $rec['id']);
$rec['description'] = substr($rec['description'], 0, 400 + 2 * MORE_RESULTAT_TAILLE_DESCRIPTION);
$content[$rec['id']] = $rec;
}
var_dump($content);
return $content;
}
}
 
 
// http://stackoverflow.com/questions/348410/sort-an-array-based-on-another-array
function _sortArrayByArray($array, $orderArray) {
$ordered = array();
204,7 → 231,7
if(!$q) return array();
 
$db = mysql_connect(SPHINX_DSN, NULL, NULL, TRUE);
$req = mysql_query(sprintf("SELECT group_id, main_id FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste WHERE MATCH('%s') LIMIT 50", $q), $db);
$req = mysql_query(sprintf("SELECT group_id, main_id FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste, i_nvjfl WHERE MATCH('%s') LIMIT 50", $q), $db);
 
$res = array('spip' => array(), 'bazar' => array(), 'projet' => array(), 'papyrus' => array(), 'coste' => array());
$ids_par_poids = array();
264,6 → 291,16
$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) {
unset($res['nvjfl'][$v['id']]['group_id'],
$res['nvjfl'][$v['id']]['main_id'],
$res['nvjfl'][$v['id']]['id']);
// left: weight
$docs['nvjfl-' . $v['id']] = array_merge($v, $res['nvjfl'][$v['id']]);
}
 
$sorted = _sortArrayByArray($docs, $ids_par_poids);
 
// sort
273,7 → 310,7
 
// then:
ddiff
<(mysql -h0 -P 9306 <<<"SELECT main_id FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste WHERE MATCH('test') LIMIT 50;"|awk '{print $3}'|sed 1d) \
<(mysql -h0 -P 9306 <<<"SELECT main_id FROM i_projet, i_spip, i_papyrus, i_bazar, i_coste, i_nvjfl WHERE MATCH('test') LIMIT 50;"|awk '{print $3}'|sed 1d) \
<(POST http://localhost/site:reseau<<<"more_motif=test&"|awk -F'=>' '{print $2}'|sed -e 's/ //g' -e '/^$/d')
 
// both should be equal.