Fix the search for names containing ' or - .
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Thu, 14 Apr 2011 18:44:12 +0000 (20:44 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Thu, 14 Apr 2011 18:44:12 +0000 (20:44 +0200)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/profile.php
include/name.func.inc.php
include/ufbuilder.inc.php

index d9b55b0..73a9fff 100644 (file)
@@ -1087,8 +1087,8 @@ class Profile implements PlExportable
                 continue;
             }
             $pid   = $key['pid'];
-            $toks  = preg_split('/[ \'\-]+/', strtolower(replace_accent($key['name'])),
-                                -1, PREG_SPLIT_NO_EMPTY);
+            require_once 'name.func.inc.php';
+            $toks = split_name_for_search($key['name']);
             $toks = array_reverse($toks);
 
             /* Split the score between the tokens to avoid the user to be over-rated.
index 8ac831d..d2cbe65 100644 (file)
@@ -228,6 +228,14 @@ function build_sn_pub($pid)
     return $sn_old;
 }
 
+/** Splits a name into tokens, as used in search_name.
+ * Used for search_name rebuilding and for queries.
+ */
+function split_name_for_search($name) {
+    return preg_split('/[[:space:]\'\-]+/', strtolower(replace_accent($name)),
+                      -1, PREG_SPLIT_NO_EMPTY);
+}
+
 /** Transform a name to its canonical value so it can be compared
  * to another form (different case, with accents or with - instead
  * of blanks).
index d46d0af..fecc077 100644 (file)
@@ -831,7 +831,9 @@ class UFBF_Name extends UFBF_Text
             return false;
         }
 
-        $this->val = preg_split('/[[:space:]]/', $this->val);
+        require_once 'name.func.inc.php';
+
+        $this->val = split_name_for_search($this->val);
         if (count($this->val) == 0) {
             $this->empty = true;
         }