Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 2122 → Rev 2123

/trunk/papyrus/applettes/moteur_recherche/sphinx-min.conf
335,6 → 335,66
infix_fields = texte, titre
}
 
 
 
# NVJFL
source nvjfl : common {
sql_db = tb_eflore
 
# note: 66 taxons nvjfl n'ont pas de numéro nomenclatural
sql_query = \
SELECT b.num_nom, num_taxon, nom_sci, GROUP_CONCAT(nom_vernaculaire), \
"nvjfl" AS group_id, CONCAT("nvjfl-", b.num_nom) as main_id \
FROM nvjfl_v2007 n \
LEFT JOIN bdtfx_v1_02 b ON n.num_taxon = b.num_taxonomique \
WHERE b.num_nom IS NOT NULL \
GROUP by num_taxon
 
sql_field_string = group_id
sql_attr_string = main_id
sql_attr_uint = num_taxon
 
sql_query_info = SELECT * FROM nvjfl_v2007 WHERE num_taxon=$id
}
 
index i_nvjfl : i_common {
source = nvjfl
path = /var/lib/sphinx/nvjfl
 
infix_fields = texte, titre
}
 
 
 
# COSTE / NVJFL
# source costenvjfl : common {
# sql_db = tb_eflore
 
# sql_query = \
# SELECT c.flore_bdtfx_nn AS id, c.nom_sci AS titre, dsc.body AS texte, cle.body AS determination, \
# GROUP_CONCAT(n.nom_vernaculaire) AS nvjfl, n.num_taxon AS num_taxonomique, \
# "costenvjfl" AS group_id, CONCAT("costenvjfl-", c.flore_bdtfx_nn) as main_id \
# FROM tb_eflore.coste_v2_00 c \
# LEFT JOIN tela_prod_wikini.florecoste_pages dsc ON c.page_wiki_dsc = dsc.tag AND dsc.latest = 'Y' \
# LEFT JOIN tela_prod_wikini.florecoste_pages cle ON c.page_wiki_cle = cle.tag AND cle.latest = 'Y' \
# LEFT JOIN bdtfx_v1_02 b ON c.flore_bdtfx_nn = b.num_nom \
# LEFT JOIN nvjfl_v2007 n ON b.num_taxonomique = n.num_taxon \
# WHERE c.flore_bdtfx_nn != ''
 
# sql_field_string = group_id
# sql_attr_string = main_id
# sql_attr_uint = num_taxonomique
 
# sql_query_info = SELECT * FROM coste_v2_00 WHERE flore_bdtfx_nn=$id
# }
 
# index i_costenvjfl : i_common {
# source = costenvjfl
# path = /var/lib/sphinx/costenvjfl
 
# infix_fields = texte, titre
# }
 
# notes:
# une nouvelle source d'indexation *DOIT*, pour être utilisable par le moteur de recherche papyrus,
# définir les attributs *group_id* et *main_id*.
/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.