search + side effect
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Thu, 2 Dec 2004 01:43:36 +0000 (01:43 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:26:20 +0000 (23:26 +0200)
* 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

htdocs/search.php
include/search.classes.inc.php
include/xorg.page.inc.php

index f808747..4afb76b 100644 (file)
@@ -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;
index f735cde..d43620e 100644 (file)
@@ -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";
     }
 }
                
index a98b6b6..6e5b1fe 100644 (file)
@@ -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]) {