This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seenthissphinx_options.php
66 lines (48 loc) · 1.77 KB
/
seenthissphinx_options.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
if (in_array($_GET['page'], array('sphinx','recherche'))
AND isset($_REQUEST['recherche'])) {
$_GET['var_recherche'] = trim(preg_replace(',\W+,u',' ',$_REQUEST['recherche']));
}
// nom de l'index pour l'enregistrement des donnees
defined('_SPHINXQL_INDEX') || define('_SPHINXQL_INDEX', 'seenthis');
function seenthissphinx_indexer_me($t) {
if (is_array($t))
$id_me = intval( ($t['id_parent'] > 0)
? $t['id_parent'] : $t['id_me']
);
else
$id_me = $t;
spip_log('job_queue_add indexer'.$id_me, 'sphinx');
job_queue_add('indexer_sphinx', 'Indexer sphinx '.$id_me, array($id_me), 'indexer_sphinx', true);
}
function sphinx_retraiter_env($env, $quoi) {
static $e;
if (!isset($e)) {
$e = unserialize($env);
$e['recherche_initiale'] = $e['recherche'];
if (preg_match(',\bhttps?://\S+,iu', $e['recherche'], $r)) {
$e['recherche'] = str_replace($r[0], seenthissphinx_normaliser_url($r[0]), $e['recherche']);
}
if (preg_match(',\#\S+,iu', $e['recherche'], $r)) {
if (!isset($e['tag'])) {
$e['tag'] = mb_strtolower($r[0], 'utf8');
$e['recherche'] = str_replace($r[0], ' ', $e['recherche']);
}
}
if (preg_match(',\@(\w+),iu', $e['recherche'], $r)) {
if (!isset($e['login'])) $e['login'] = $r[1];
$e['recherche'] = str_replace($r[0], ' ', $e['recherche']);
}
$e['recherche'] = trim($e['recherche']);
}
return $e[$quoi];
}
// transforme une URL en httprezonet pour pouvoir l'indexer sans tuer
// les mots "rezo" ou "net" ; ˆ utiliser aussi sur la query utilisateur
// s'applique ˆ $u ou ˆ $r=[ match, É ] d'un preg_replace_callback
function seenthissphinx_normaliser_url($u) {
if (is_array($u)) $u = array_shift($u);
$u = preg_replace(',^(http|ftp)s?://(www\.)?(.*),i', '\\1-\\3', $u);
$u = preg_replace(',\W+,u', '', $u);
return "$u*";
}