Adapts search to the new name management.
authorStéphane Jacob <jacou@melix.net>
Mon, 19 Jan 2009 21:51:03 +0000 (22:51 +0100)
committerStéphane Jacob <jacou@melix.net>
Mon, 19 Jan 2009 21:51:03 +0000 (22:51 +0100)
bin/search.rebuild_db.php
include/name.func.inc.php
include/user.func.inc.php
include/userset.inc.php
modules/search.php
modules/search/search.inc.php
templates/search/adv.form.tpl
upgrade/newdirectory-0.0.1/00_names.sql

index 81fa957..1b9917f 100755 (executable)
@@ -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";
index 900e411..d0c0f22 100644 (file)
@@ -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;
 }
 
index 58c41a8..890e95f 100644 (file)
@@ -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);
 }
 
 // }}}
index 9d31ff4..01bbcfb 100644 (file)
@@ -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)
index 49c7f5a..8a5710b 100644 (file)
@@ -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';
index e0ea3d5..ea82bde 100644 (file)
@@ -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,
index d996c69..cfe97f8 100644 (file)
       </th>
     </tr>
     <tr>
-      <td>Nom</td>
+      <td>Nom, prénom, surnom...</td>
       <td>
         <input type="hidden" name="rechercher" value="Chercher"/>
         <input type="submit" style="display:none"/>
-        <input type="text" class="autocomplete" name="name" size="32" value="{$smarty.request.name}" />
-      </td>
-    </tr>
-    <tr>
-      <td>Prénom</td>
-      <td>
-        <input class="autocomplete" type="text" name="firstname" size="32" value="{$smarty.request.firstname}" />
-      </td>
-    </tr>
-    <tr>
-      <td>Surnom</td>
-      <td>
-        <input class="autocomplete" type="text" name="nickname" size="32" value="{$smarty.request.nickname}" />
+        <input type="text" name="name" size="32" value="{$smarty.request.name}" />
       </td>
     </tr>
     <tr>
index 22b2c51..6260e32 100644 (file)
@@ -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: