Ajout de l'option de recherche par proximité sonore
authorx2000bedo <x2000bedo>
Thu, 5 Aug 2004 23:17:17 +0000 (23:17 +0000)
committerx2000bedo <x2000bedo>
Thu, 5 Aug 2004 23:17:17 +0000 (23:17 +0000)
Sous forme d'extension des résultats si on n'est pas satisfait => on satisfait à la fois JMY et tous les utilisateurs qui sont gênés par la
quantité de résultats générés par la proximité sonore

htdocs/search.php
include/search.classes.inc.php
templates/search.tpl

index c3732f1..ed7b965 100644 (file)
@@ -12,8 +12,17 @@ $page->assign('public_directory',$public_directory);
 if (array_key_exists('rechercher', $_REQUEST)) {
     $page->assign('formulaire',0);
 
-    $nameField = new StringSField('name',array('u.nom','u.epouse','i.nom'),'i.nom');
-    $firstnameField = new StringSField('firstname',array('u.prenom','i.prenom'),'i.prenom');
+    $with_soundex = ((isset($_REQUEST['with_soundex']) && $_REQUEST['with_soundex']==1));
+
+    if ($with_soundex) {
+        $nameField = new StringWithSoundexSField('name',array('u.nom_soundex','u.epouse_soundex','i.nom_soundex'),'i.nom');
+        $firstnameField = new StringWithSoundexSField('firstname',array('u.prenom_soundex','i.prenom_soundex'),'i.prenom');
+    }
+    else {
+        $nameField = new StringSField('name',array('u.nom','u.epouse','i.nom'),'i.nom');
+        $firstnameField = new StringSField('firstname',array('u.prenom','i.prenom'),'i.prenom');
+        $with_soundex = ($nameField->length()==0 && $firstnameField->length()==0)?(-1):0;
+    }
     $promo1Field = new PromoSField('promo1','egal1',array('u.promo','i.promo'),'i.promo');
     $promo2Field = new PromoSField('promo2','egal2',array('u.promo','i.promo'),'i.promo');
     $fields = new SFieldGroup(true,array($nameField,$firstnameField,$promo1Field,$promo2Field));
@@ -52,6 +61,7 @@ if (array_key_exists('rechercher', $_REQUEST)) {
     $nbpages = ($page->get_template_vars('nb_resultats_total')-1)/$globals->search_results_per_page;
     $page->assign('offsets',range(0,$nbpages));
     $page->assign('url_args',$fields->get_url());
+    $page->assign('with_soundex',$with_soundex);
     $page->assign('offset',$offset->value);
     $page->assign('perpage',$globals->search_results_per_page);
     $page->assign('is_admin',has_perms());
index 49f188f..ee83b5a 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+require_once("xorg.misc.inc.php");
+
 /** classe qui gère les erreurs dans les requêtes des utilisateurs finaux
  * passe le message d'erreur au template de page et exécute le template
  */
@@ -130,6 +132,16 @@ class StringSField extends SField {
     }
 }
 
+/** classe de champ texte avec soundex (nom par exemple)
+ */
+class StringWithSoundexSField extends StringSField {
+    /** clause WHERE correspondant à un champ de la bdd et à ce champ de formulaire
+     * @param field nom de champ de la bdd concerné par la clause */
+    function get_single_where_statement($field) {
+        return $field.'="'.soundex_fr($this->value).'"';
+    }
+}
+
 /** classe de champ de promotion */
 class PromoSField extends SField {
     /** opérateur de comparaison (<,>,=) de la promo utilisé pour ce champ de formulaire */
index f92a06c..444fc05 100644 (file)
@@ -3,6 +3,11 @@
   <div class="rubrique">
     Résultats
   </div>
+  {if $with_soundex==0}
+    <a href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}&with_soundex=1&rechercher=1&{$url_args}">
+      Etendre à la recherche par proximité sonore
+    </a>
+  {/if}
   <div class="right">
     <a href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}">Nouvelle recherche</a>
   </div>
   {if $perpage<$nb_resultats_total}
   <p>
     {if $offset!=0}
-      <a href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}&rechercher=1&{$url_args}&offset={$offset-$perpage}">
+      <a href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}&with_soundex={$with_soundex}&rechercher=1&{$url_args}&offset={$offset-$perpage}">
         Précédent
       </a>
       &nbsp;
     {/if}
     {section name=offset loop=$offsets}
       {if $offset!=$smarty.section.offset.index*$perpage}
-        <a href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}&rechercher=1&{$url_args}&offset={$smarty.section.offset.index*$perpage}">
+        <a href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}&with_soundex={$with_soundex}&rechercher=1&{$url_args}&offset={$smarty.section.offset.index*$perpage}">
           {$smarty.section.offset.index+1}
         </a>
       {else}
@@ -38,7 +43,7 @@
       &nbsp;
     {/section}
     {if $offset<$nb_resultats_total-$perpage}
-      <a href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}&rechercher=1&{$url_args}&offset={$offset+$perpage}">
+      <a href="{$smarty.server.PHP_SELF}?public_directory={$public_directory}&with_soundex={$with_soundex}&rechercher=1&{$url_args}&offset={$offset+$perpage}">
         Suivant
       </a>
       &nbsp;