Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 2116 → Rev 2117

/trunk/papyrus/applettes/moteur_recherche/moteur_recherche_sphinx.php
28,6 → 28,7
*/
 
define('SPHINX_DSN', '127.0.0.1:9306');
define('_MRS_SPHINX_BASEHOST', $_SERVER['HTTP_HOST']);
 
// pour strftime()
date_default_timezone_set('Europe/Paris');
97,7 → 98,7
if(!$ids) return array();
$db = $GLOBALS['_MOTEUR_RECHERCHE_']['bd']['papyrus'];
$req = $db->query(sprintf(<<<EOF
SELECT p_id AS id, p_titre, p_description, p_date_creation AS date_creation
SELECT p_id AS id, p_titre AS titre, p_description, p_date_creation AS date_creation
FROM projet WHERE p_id IN (%s)
EOF
,
153,7 → 154,33
}
}
 
class MoteurRecherche_COSTE {
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 c.flore_bdtfx_nn AS id, c.nom_sci AS titre, dsc.body AS description
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'
WHERE c.flore_bdtfx_nn IN (%s)
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']);
// TODO: interpret wikini
$rec['description'] = substr($rec['description'], 0, 400 + 2 * MORE_RESULTAT_TAILLE_DESCRIPTION);
$content[$rec['id']] = $rec;
}
return $content;
}
}
 
 
// http://stackoverflow.com/questions/348410/sort-an-array-based-on-another-array
function _sortArrayByArray($array, $orderArray) {
$ordered = array();
169,7 → 196,7
// adaption aux templates existants: [score] => [weight]
function _weight2score(&$item, $key, $max) {
$item['score'] = intval($item['weight'] / $max * 100);
$item['date_creation'] = strftime("%d %B %Y", strtotime($item['date_creation']));
$item['date_creation'] = isset($item['date_creation']) ? strftime("%d %B %Y", strtotime($item['date_creation'])) : '';
unset($item['weight']);
}
 
177,15 → 204,14
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 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 WHERE MATCH('%s') LIMIT 50", $q), $db);
 
$res = array('spip' => array(), 'bazar' => array(), 'projet' => array(), 'papyrus' => array());
$res = array('spip' => array(), 'bazar' => array(), 'projet' => array(), 'papyrus' => array(), 'coste' => array());
$ids_par_poids = array();
while($rec = mysql_fetch_array($req, MYSQL_ASSOC)) {
$res[$rec['group_id']][$rec['id']] = $rec;
$ids_par_poids[] = $rec['main_id'];
}
 
$docs = array();
 
// spip
228,6 → 254,16
$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) {
unset($res['coste'][$v['id']]['group_id'],
$res['coste'][$v['id']]['main_id'],
$res['coste'][$v['id']]['id']);
// left: weight
$docs['coste-' . $v['id']] = array_merge($v, $res['coste'][$v['id']]);
}
 
$sorted = _sortArrayByArray($docs, $ids_par_poids);
 
// sort
237,7 → 273,7
 
// then:
ddiff
<(mysql -h0 -P 9306 <<<"SELECT main_id FROM i_projet, i_spip, i_papyrus, i_bazar 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 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.
248,7 → 284,7
$max = $max['weight'];
array_walk($sorted, '_weight2score', $max);
 
//var_dump($sorted);die;
// var_dump($sorted);die;
return $sorted;
}
 
267,4 → 303,3
Note: conversion côté client SQL:
mysql -h0 -P 9306 < <(iconv -f utf8 -t latin1 <<<"SELECT * FROM i_projet, i_spip, i_papyrus, i_bazar WHERE MATCH('journée');")
*/
 
/trunk/papyrus/applettes/moteur_recherche/sphinx-min.conf
314,14 → 314,17
sql_db = tb_eflore
 
sql_query = \
SELECT c.num_nom AS id, CONCAT("bdtfx", ":", c.num_nom) AS group_id, CONCAT(c.nom_sci, dsc.body) AS texte, CONCAT(c.nom_sci, cle.body) AS determination, c.nom_sci AS nom_sci \
SELECT c.flore_bdtfx_nn AS id, c.nom_sci AS titre, dsc.body AS texte, cle.body AS determination, \
"coste" AS group_id, CONCAT("coste-", 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 tela_prod_wikini.florecoste_pages cle ON c.page_wiki_cle = cle.tag AND cle.latest = 'Y' \
WHERE c.flore_bdtfx_nn != ''
 
sql_field_string = group_id
sql_attr_string = main_id
 
sql_query_info = SELECT * FROM coste_v2_00 WHERE num_nom=$id
sql_query_info = SELECT * FROM coste_v2_00 WHERE flore_bdtfx_nn=$id
}
 
index i_coste : i_common {
328,10 → 331,16
source = coste
path = /var/lib/sphinx/coste
 
infix_fields = texte, nom_sci
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*.
# cf: sphinx_search dans moteur_recherche_sphinx.php
 
 
 
# misc...
# index testrt
# {