From: Pierre Habouzit (MadCoder Date: Thu, 2 Dec 2004 01:43:36 +0000 (+0000) Subject: search + side effect X-Git-Tag: xorg/old~730 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=634700d41dfb921482954db4fe96a5dcbc7f3892;p=platal.git search + side effect * Search (closes: #195). The heuristic is the following (and I'm quite proud of it, since it gives really good results) : compute a mark for each result following that : for each litteral token T we give : + 100 iff T is exactly the noun or the wife name of the person + 10 iff T is exactly his first name + 1 iff T is the begininng of the noun/wife name Then, we sort the results (better marks go first), and we cut 0 marks. * Core : a bug was introduced wrt auto validation of the pages (scripts->bin) I really should write this tiny piece of code into php ... git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-10 --- diff --git a/htdocs/search.php b/htdocs/search.php index f808747..4afb76b 100644 --- a/htdocs/search.php +++ b/htdocs/search.php @@ -46,8 +46,8 @@ if (array_key_exists('quick', $_REQUEST)) { $offset = new NumericSField('offset'); - $sql = 'SELECT SQL_CALC_FOUND_ROWS - DISTINCT r.matricule,u.matricule_ax,u.user_id, + $sql = 'SELECT SQL_CALC_FOUND_ROWS + DISTINCT '.$qSearch->get_mark_statement().',r.matricule,u.matricule_ax,u.user_id, UPPER(IF(u.nom!="",u.nom,u.nom_ini)) AS nom, IF(u.prenom!="",u.prenom,u.prenom_ini) AS prenom, u.promo AS promo, @@ -62,6 +62,7 @@ if (array_key_exists('quick', $_REQUEST)) { LEFT JOIN watch_nonins AS w ON (w.ni_id=u.user_id AND w.uid='.((array_key_exists('uid',$_SESSION))?$_SESSION['uid']:0).') '.$globals->search_result_where_statement.' WHERE '.$fields->get_where_statement().' + HAVING mark>0 ORDER BY '.(logged() && !empty($_REQUEST['mod_date_sort']) ? 'date DESC,' :'') .implode(',',array_filter(array($fields->get_order_statement(),'u.promo DESC,NomSortKey,prenom'))).' LIMIT '.$offset->value.','.$globals->search_results_per_page; diff --git a/include/search.classes.inc.php b/include/search.classes.inc.php index f735cde..d43620e 100644 --- a/include/search.classes.inc.php +++ b/include/search.classes.inc.php @@ -173,11 +173,7 @@ class QuickSearch extends SField { function get_where_statement() { $where = Array(); - if(count($this->strings) == 1) { - $t = '%'.str_replace('*', '%', $this->strings[0]).'%'; - $t = str_replace('%%', '%', $t); - $where[] = "(r.nom LIKE '$t' OR r.epouse LIKE '$t')"; - } else foreach($this->strings as $s) { + foreach($this->strings as $s) { $t = '%'.str_replace('*', '%', $s).'%'; $t = str_replace('%%', '%', $t); $where[] = "(r.nom LIKE '$t' OR r.epouse LIKE '$t' OR r.prenom LIKE '$t')"; @@ -201,15 +197,20 @@ class QuickSearch extends SField { return join(" AND ", $where); } - function get_order_statement() { - if(empty($this->strings)) return false; + function get_mark_statement() { + if(empty($this->strings)) return "1 AS mark"; $order = Array(); foreach($this->strings as $s) { - $order[] = "(r.nom='$s' OR r.prenom='$s' OR r.epouse='$s')*100 + " - . "(r.nom LIKE '$s%' OR r.prenom LIKE '$s%' OR r.epouse LIKE '$s%')"; + $order[] = "(r.nom='$s' OR r.epouse='$s')*100 + " + . "(r.prenom='$s') * 10 + " + . "(r.nom LIKE '$s%' OR r.epouse LIKE '$s%')"; } $res = join(' + ', $order); - if($res) return "$res DESC"; + if($res) return "$res AS mark"; + } + function get_order_statement() { + if(empty($this->strings)) return false; + return "mark DESC"; } } diff --git a/include/xorg.page.inc.php b/include/xorg.page.inc.php index a98b6b6..6e5b1fe 100644 --- a/include/xorg.page.inc.php +++ b/include/xorg.page.inc.php @@ -141,7 +141,7 @@ class XorgPage extends DiogenesCorePage fwrite($fd, $result); fclose($fd); - exec($globals->spoolroot."/scripts/xhtml/validate.pl ".$this->cache_dir."valid.html", $val); + exec($globals->spoolroot."/bin/xhtml/validate.pl ".$this->cache_dir."valid.html", $val); foreach ($val as $h) { if (preg_match("/^X-W3C-Validator-Errors: (\d+)$/", $h, $m)) { if ($m[1]) {