From 5ed1cce8c4b38941d65e578ed3c3bf593a3cc576 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Thu, 14 Apr 2011 20:44:12 +0200 Subject: [PATCH] Fix the search for names containing ' or - . MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- classes/profile.php | 4 ++-- include/name.func.inc.php | 8 ++++++++ include/ufbuilder.inc.php | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/classes/profile.php b/classes/profile.php index d9b55b0..73a9fff 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -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. diff --git a/include/name.func.inc.php b/include/name.func.inc.php index 8ac831d..d2cbe65 100644 --- a/include/name.func.inc.php +++ b/include/name.func.inc.php @@ -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). diff --git a/include/ufbuilder.inc.php b/include/ufbuilder.inc.php index d46d0af..fecc077 100644 --- a/include/ufbuilder.inc.php +++ b/include/ufbuilder.inc.php @@ -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; } -- 2.1.4