From 6443c93dcff35f5fc9b0882a501d383279c755dc Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Mon, 19 Jan 2009 22:51:03 +0100 Subject: [PATCH] Adapts search to the new name management. --- bin/search.rebuild_db.php | 16 +++++------ include/name.func.inc.php | 4 +-- include/user.func.inc.php | 47 +++++++++++---------------------- include/userset.inc.php | 1 + modules/search.php | 14 ---------- modules/search/search.inc.php | 10 +++---- templates/search/adv.form.tpl | 16 ++--------- upgrade/newdirectory-0.0.1/00_names.sql | 29 +++++++++++--------- 8 files changed, 47 insertions(+), 90 deletions(-) diff --git a/bin/search.rebuild_db.php b/bin/search.rebuild_db.php index 81fa957..1b9917f 100755 --- a/bin/search.rebuild_db.php +++ b/bin/search.rebuild_db.php @@ -26,17 +26,13 @@ require('user.func.inc.php'); ini_set('memory_limit', "16M"); $globals->debug = 0; // Do not store backtraces -XDB::execute('DELETE FROM search_name'); -$res = XDB::iterRow('SELECT auth_user_md5.user_id, nom, prenom, nom_usage, profile_nick - FROM auth_user_md5 - LEFT JOIN auth_user_quick USING(user_id)'); +$res = XDB::iterRow("SELECT user_id + FROM auth_user_md5"); $i = 0; -$muls = array(1, 1, 1, 0.2); -$pub = array(true, true, true, false); -while ($tmp = $res->next()) { - $uid = array_shift($tmp); - _user_reindex($uid, $tmp, $muls, $pub); - printf("\r%u / %u", ++$i, $res->total()); +$n = $res->total(); +while ($uid = $res->next()->fetchOneCell()) { + user_reindex($uid); + printf("\r%u / %u", ++$i, $n); } print "done\n"; diff --git a/include/name.func.inc.php b/include/name.func.inc.php index 900e411..d0c0f22 100644 --- a/include/name.func.inc.php +++ b/include/name.func.inc.php @@ -282,8 +282,8 @@ function set_alias_names(&$sn_new, $sn_old, $update_new = false, $new_alias = nu VALUES ({?}, 'alias', 'usage', {?})", $new_alias, S::i('uid')); } - /*require_once('user.func.inc.php'); - user_reindex($uid);*/ + require_once('user.func.inc.php'); + user_reindex($uid); return $has_new; } diff --git a/include/user.func.inc.php b/include/user.func.inc.php index 58c41a8..890e95f 100644 --- a/include/user.func.inc.php +++ b/include/user.func.inc.php @@ -684,57 +684,40 @@ function set_user_details($uid, $details) { // }}} // {{{ function _user_reindex -function _user_reindex($uid, $keys, $muls, $pubs) +function _user_reindex($uid, $keys) { foreach ($keys as $i => $key) { - if ($key == '') { + if ($key['name'] == '') { continue; } - $toks = preg_split('/[ \'\-]+/', $key); + $toks = preg_split('/[ \'\-]+/', $key['name']); $token = ""; $first = 5; while ($toks) { $token = strtolower(replace_accent(array_pop($toks) . $token)); - $score = ($toks ? 0 : 10 + $first) * $muls[$i]; + $score = ($toks ? 0 : 10 + $first) * ($key['score'] / 10); XDB::execute("REPLACE INTO search_name (token, uid, soundex, score, flags) VALUES ({?}, {?}, {?}, {?}, {?})", - $token, $uid, soundex_fr($token), $score, $pubs[$i] ? 'public' : ''); + $token, $uid, soundex_fr($token), $score, $key['public']); $first = 0; } } - $res = XDB::query("SELECT nom_ini, nom, nom_usage, prenom_ini, prenom, promo, matricule - FROM auth_user_md5 - WHERE user_id = {?}", $uid); - if (!$res->numRows()) { - unset($res); - return; - } - $array = $res->fetchOneRow(); - $promo = intval(array_pop($array)); - $mat = array_shift($array); - array_walk($array, 'soundex_fr'); - XDB::execute("REPLACE INTO recherche_soundex - SET matricule = {?}, nom1_soundex = {?}, nom2_soundex= {?}, nom3_soundex = {?}, - prenom1_soundex = {?}, prenom2_soundex= {?}, promo = {?}", - $mat, $array[0], $array[1], $array[2], $array[3], $array[4], $promo); - unset($res); - unset($array); } // }}} // {{{ function user_reindex function user_reindex($uid) { - XDB::execute("DELETE FROM search_name WHERE uid={?}", $uid); - $res = XDB::query("SELECT prenom, nom, nom_usage, profile_nick FROM auth_user_md5 INNER JOIN auth_user_quick USING(user_id) WHERE auth_user_md5.user_id = {?}", $uid); - if ($res->numRows()) { - _user_reindex($uid, $res->fetchOneRow(), array(1,1,1,0.2), array(true, true, true, false)); - } else { // not in auth_user_quick => still "pending" - $res = XDB::query("SELECT prenom, nom, nom_usage FROM auth_user_md5 WHERE auth_user_md5.user_id = {?}", $uid); - if ($res->numRows()) { - _user_reindex($uid, $res->fetchOneRow(), array(1,1,1), array(true, true, true)); - } - } + XDB::execute("DELETE FROM search_name + WHERE uid = {?}", + $uid); + $res = XDB::iterator("SELECT CONCAT(n.particle, n.name) AS name, e.score, + FIND_IN_SET('public', e.flags) AS public + FROM profile_name AS n + INNER JOIN profile_name_enum AS e ON (n.typeid = e.id) + WHERE n.pid = {?}", + $uid); + _user_reindex($uid, $res); } // }}} diff --git a/include/userset.inc.php b/include/userset.inc.php index 9d31ff4..01bbcfb 100644 --- a/include/userset.inc.php +++ b/include/userset.inc.php @@ -203,6 +203,7 @@ class MinificheView extends MultipageView public function joins() { return "LEFT JOIN aliases AS a ON (u.user_id = a.id AND FIND_IN_SET('bestalias', a.flags)) + LEFT JOIN search_name AS n ON (u.user_id = n.uid) LEFT JOIN profile_job AS j ON (j.uid = u.user_id".(S::logged() ? "" : " AND j.pub = 'public'").") LEFT JOIN profile_job_enum AS je ON (je.id = j.jobid) LEFT JOIN profile_job_sector_enum AS es ON (j.sectorid = es.id) diff --git a/modules/search.php b/modules/search.php index 49c7f5a..8a5710b 100644 --- a/modules/search.php +++ b/modules/search.php @@ -289,10 +289,6 @@ class SearchModule extends PLModule $field = 'profile_job_enum.name'; $unique = 'profile_job.uid'; break; - case 'firstname': - $field = '`prenom`'; - $beginwith = false; - break; case 'fonctionTxt': $db = 'fonctions_def INNER JOIN profile_job ON (profile_job.fonctionid = fonctions_def.id)'; @@ -313,11 +309,6 @@ class SearchModule extends PLModule $realid = 'a.id'; $unique = 'm.uid'; break; - case 'name': - $field = '`nom`'; - $field2 = '`nom_usage`'; - $beginwith = false; - break; case 'nationaliteTxt': $db = '`geoloc_pays` INNER JOIN `auth_user_md5` ON (`geoloc_pays`.`a2` = `auth_user_md5`.`nationalite` OR @@ -328,11 +319,6 @@ class SearchModule extends PLModule `geoloc_pays`.`nat`)'; $realid = '`geoloc_pays`.`a2`'; break; - case 'nickname': - $field = '`profile_nick`'; - $db = '`auth_user_quick`'; - $beginwith = false; - break; case 'description': $db = 'profile_job'; $field = 'description'; diff --git a/modules/search/search.inc.php b/modules/search/search.inc.php index e0ea3d5..ea82bde 100644 --- a/modules/search/search.inc.php +++ b/modules/search/search.inc.php @@ -28,13 +28,11 @@ function getadr_join($table) { function advancedSearchFromInput() { if ($with_soundex = Env::has('with_soundex')) { - $nameField = new RefWithSoundexSField('name',array('rn.nom1_soundex','rn.nom2_soundex','rn.nom3_soundex'),'recherche_soundex','rn','u.matricule = rn.matricule'); - $firstnameField = new RefWithSoundexSField('firstname',array('rp.prenom1_soundex','rp.prenom2_soundex'),'recherche_soundex','rp','u.matricule = rp.matricule'); + $nameField = new RefWithSoundexSField('name', array('n.soundex'), 'search_name', + 'n', 'u.user_id = n.uid'); } else { - $nameField = new NameSField('name', array('u.nom','u.nom_usage'), ''); - $firstnameField = new StringSField('firstname', array('u.prenom'), ''); + $nameField = new NameSField('name', array('n.token'), 'search_name', 'n', 'u.user_id = n.uid'); } - $nicknameField = new StringSField('nickname', array('q.profile_nick'), ''); $promo1Field = new PromoSField('promo1', 'egal1', array('u.promo'), ''); $promo2Field = new PromoSField('promo2', 'egal2', array('u.promo'), ''); @@ -85,7 +83,7 @@ function advancedSearchFromInput() } $nwPhoneField = new PhoneSField('phone_number', array('t.search_tel'), 'profile_phones', 't', 't.uid = u.user_id'); return array( - $nameField, $firstnameField, $nicknameField, $promo1Field, + $nameField, $promo1Field, $promo2Field, $womanField, $subscriberField, $aliveField, $townField, $countryField, $regionField, $mapField, $entrepriseField, $posteField, $secteurField, $cvField, $natField, $binetField, diff --git a/templates/search/adv.form.tpl b/templates/search/adv.form.tpl index d996c69..cfe97f8 100644 --- a/templates/search/adv.form.tpl +++ b/templates/search/adv.form.tpl @@ -177,23 +177,11 @@ - Nom + Nom, prénom, surnom... - - - - - Prénom - - - - - - Surnom - - + diff --git a/upgrade/newdirectory-0.0.1/00_names.sql b/upgrade/newdirectory-0.0.1/00_names.sql index 22b2c51..6260e32 100644 --- a/upgrade/newdirectory-0.0.1/00_names.sql +++ b/upgrade/newdirectory-0.0.1/00_names.sql @@ -32,30 +32,31 @@ CREATE TABLE IF NOT EXISTS profile_name_enum ( explanations VARCHAR(255) NOT NULL, type VARCHAR(255) NOT NULL, flags SET('has_particle', 'not_displayed', 'always_displayed', 'public') NOT NULL, + score TINYINT(2) UNSIGNED NOT NULL DEFAULT 10, PRIMARY KEY (id), UNIQUE (name) ) CHARSET=utf8; -INSERT INTO profile_name_enum (name, flags, explanations, type) +INSERT INTO profile_name_enum (name, flags, explanations, type, score) VALUES ('Nom patronymique', 'has_particle,always_displayed,public', - 'Le nom de famille avec lequel tu es né', 'lastname'), + 'Le nom de famille avec lequel tu es né', 'lastname', 10), ('Nom marital', 'has_particle,always_displayed,public', - 'Ton nom d\'épouse ou d\'époux', 'lastname_marital'), + 'Ton nom d\'épouse ou d\'époux', 'lastname_marital', 10), ('Nom usuel', 'has_particle,always_displayed,public', 'Le nom de famille que tu utilises usuellement s\'il est différent du nom patronymique, ce peut-être une version racourcie de celui-ci, ton nom marital, une combinaison de ces deux noms...', - 'lastname_ordinary'), - ('Prénom', 'always_displayed,public', 'Ton prénom', 'firstname'), + 'lastname_ordinary', 10), + ('Prénom', 'always_displayed,public', 'Ton prénom', 'firstname', 10), ('Pseudonyme (nom de plume)', 'always_displayed,public', - 'Pseudonyme pour les artistes, gens de lettres', 'pseudonym'), - ('Surnom', '', 'Surnom à l\'École ou ailleurs', 'nickname'), + 'Pseudonyme pour les artistes, gens de lettres', 'pseudonym', 10), + ('Surnom', '', 'Surnom à l\'École ou ailleurs', 'nickname', 2), ('Prénom usuel', 'public', 'Si tu utilises une version raccourcie, francisée... de ton prénom', - 'firstname_ordinary'), + 'firstname_ordinary', 10), ('Autre prénom', '', 'Si tu as d\'autres prénoms et que tu souhaites les faire apparaître', - 'firstname_other'), + 'firstname_other', 1), ('Autre nom', '', 'Si tu as d\'autres noms et que tu souhaites les faire apparaître', - 'name_other'), - ('Nom initial', 'has_particle,not_displayed,public', '', 'name_ini'), - ('Prénom initial', 'has_particle,not_displayed,public', '', 'firstname_ini'); + 'name_other', 1), + ('Nom initial', 'has_particle,not_displayed,public', '', 'name_ini', 10), + ('Prénom initial', 'has_particle,not_displayed,public', '', 'firstname_ini', 10); DROP TABLE IF EXISTS profile_name; @@ -106,4 +107,8 @@ INSERT INTO profile_name (pid, name, typeid) INNER JOIN profile_name_enum AS e ON (e.name = 'Surnom') WHERE profile_nick != ''; +DROP TABLE IF EXISTS recherche_soundex; + +DELETE FROM search_autocomplete + WHERE name = 'name' OR name = 'firstname' OR name = 'nickname'; -- vim:set syntax=mysql: -- 2.1.4