Subversion Repositories Applications.papyrus

Rev

Rev 846 | Rev 1034 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
217 jpm 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This file is part of Papyrus.                                                                        |
9
// |                                                                                                      |
10
// | Foobar is free software; you can redistribute it and/or modify                                       |
11
// | it under the terms of the GNU General Public License as published by                                 |
12
// | the Free Software Foundation; either version 2 of the License, or                                    |
13
// | (at your option) any later version.                                                                  |
14
// |                                                                                                      |
15
// | Foobar is distributed in the hope that it will be useful,                                            |
16
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
17
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
18
// | GNU General Public License for more details.                                                         |
19
// |                                                                                                      |
20
// | You should have received a copy of the GNU General Public License                                    |
21
// | along with Foobar; if not, write to the Free Software                                                |
22
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
23
// +------------------------------------------------------------------------------------------------------+
851 jp_milcent 24
// CVS : $Id: more_recherche.class.php,v 1.8 2006-05-23 14:18:19 jp_milcent Exp $
217 jpm 25
/**
26
* Classe permettant d'effectuer des recherches sur les métas informations des menus.
27
*
28
* Permet de rechercher et classer les menus en fonction d'une chaine.
29
*
30
*@package Applette
31
*@subpackage Moteur_Recherche
32
//Auteur original :
33
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
34
//Autres auteurs :
35
*@author        aucun
36
*@copyright     Tela-Botanica 2000-2004
851 jp_milcent 37
*@version       $Revision: 1.8 $ $Date: 2006-05-23 14:18:19 $
217 jpm 38
// +------------------------------------------------------------------------------------------------------+
39
*/
40
 
41
// +------------------------------------------------------------------------------------------------------+
42
// |                                            ENTETE du PROGRAMME                                       |
43
// +------------------------------------------------------------------------------------------------------+
44
 
45
 
46
// +------------------------------------------------------------------------------------------------------+
47
// |                                            CORPS du PROGRAMME                                        |
48
// +------------------------------------------------------------------------------------------------------+
49
 
50
class Recherche {
51
    var $motif = '';
52
    var $moteurs_recherches = array();
53
    var $resultats = array();
54
 
55
    // Constructeur
56
    function Recherche($motif) {
57
        $this->setMotif($motif);
58
    }
59
 
60
    // Accesseurs
61
    function getMotif() {
62
        return $this->motif;
63
    }
64
    function setMotif($motif) {
65
        $this->motif = $motif;
66
    }
67
    function getMoteurs() {
68
        return $this->moteurs_recherches;
69
    }
70
    function getMoteur($id) {
71
        return $this->moteurs_recherches[$id];
72
    }
73
    function setMoteur($val) {
74
        $id_nouveau = count($this->moteurs_recherches);
75
        $this->moteurs_recherches[$id_nouveau] = $val;
76
    }
77
    function getResultats() {
78
        return $this->resultats;
79
    }
80
    function setResultats($val) {
81
        $this->resultats = $val;
82
    }
83
    function setResultat($aso_page) {
84
        $id_nouveau = count($this->resultats);
85
        $this->resultats[$id_nouveau] = $aso_page;
86
    }
87
 
88
    // Méthodes
89
 
90
    function ajouterRecherche(&$objet_recherche) {
91
        return $this->setMoteur($objet_recherche);
92
    }
846 jp_milcent 93
 
217 jpm 94
    function rechercherMotif() {
95
        foreach ($this->getMoteurs() as $cle => $val) {
846 jp_milcent 96
            $this->setResultats(array_merge((array)$this->getResultats(),(array)$val->rechercherMotif($this->getMotif())));
217 jpm 97
        }
98
        $aso_resultats = $this->getResultats();
99
        function comparer($a, $b) {
100
            if ($a['poids'] > $b['poids']) {
101
                return -1;
102
            }
103
            if ($a['poids'] < $b['poids']) {
104
                return +1;
105
            }
106
            if ($a['poids'] = $b['poids']) {
107
                return 0;
108
            }
109
        }
110
        usort($aso_resultats, 'comparer');
373 jpm 111
        $pds_max = 0;
112
        if (isset($aso_resultats[0]['poids'])) {
113
            $pds_max = $aso_resultats[0]['poids'];
114
        }
339 jpm 115
        for ($i = 0 ; $i < count($aso_resultats) ; $i++) {
368 jpm 116
            $aso_resultats[$i]['score'] = round((100 / $pds_max) * $aso_resultats[$i]['poids'], 1);
339 jpm 117
        }
118
 
217 jpm 119
        return $aso_resultats;
120
    }
339 jpm 121
 
846 jp_milcent 122
    /** Renvoie le nombre d'occurences total de la présence de chaque mot.
123
	*
124
	* @param  string	le motif à rechercher.
125
	* @param  string	le texte dans lequel effectuer la recherche.
126
	* @return integer	le nombre de fois où les mots sont trouvés.
127
	*/
851 jp_milcent 128
	function retournerOccurenceMotif($motif, &$texte, $mode = MORE_MODE)
846 jp_milcent 129
	{
130
		$nbre_correspondance = 0;
851 jp_milcent 131
		if ($mode == 1) {
132
			// Découpage en mot
133
			$tab_motif = explode(' ', trim($motif));
134
		} else {
135
			// La chaine saisie par l'utilisateur est recherchée tel quel
136
			$tab_motif[] = trim($motif);
137
		}
846 jp_milcent 138
		// Nous recherchons chaque mot
139
		foreach ($tab_motif as $mot) {
851 jp_milcent 140
			$nbre_correspondance += substr_count(strtolower($texte), strtolower(stripslashes($mot)));
846 jp_milcent 141
			//$nbre_correspondance += preg_match_all('/'.$mot.'/i', $texte, $tab_morceaux);
142
		}
143
		return $nbre_correspondance;
144
	}
145
 
339 jpm 146
    function traduireMois($mois_numerique)
147
    {
148
        switch ($mois_numerique) {
149
            case '01' :
832 florian 150
                return 'janvier';
339 jpm 151
            case '02' :
832 florian 152
                return 'février';
339 jpm 153
            case '03' :
154
                return 'mars';
155
            case '04' :
156
                return 'avril';
157
            case '05' :
158
                return 'mai';
159
            case '06' :
160
                return 'juin';
161
            case '07' :
162
                return 'juillet';
163
            case '08' :
164
                return 'août';
165
            case '09' :
166
                return 'septembre';
167
            case '10' :
168
                return 'octobre';
169
            case '11' :
170
                return 'novembre';
171
            case '12' :
172
                return 'décembre';
173
            default:
174
                return '';
175
        }
176
    }
217 jpm 177
}
178
 
179
/* +--Fin du code ----------------------------------------------------------------------------------------+
180
*
181
* $Log: not supported by cvs2svn $
851 jp_milcent 182
* Revision 1.7  2006/05/19 10:04:55  jp_milcent
183
* Ajout d'un moteur de recherche analysant les articles des sites sous Spip.
184
*
846 jp_milcent 185
* Revision 1.6  2006/04/28 12:41:49  florian
186
* corrections erreurs chemin
187
*
832 florian 188
* Revision 1.5  2005/09/20 17:01:22  ddelon
189
* php5 et bugs divers
190
*
443 ddelon 191
* Revision 1.4  2005/05/25 13:49:22  jpm
192
* Corection erreur pour la recherche dans le contenu.
193
*
373 jpm 194
* Revision 1.3  2005/05/19 12:46:12  jpm
195
* Correction bogue accesskey.
196
* Ajout d'un id à la liste.
197
* Arrondissement des score.
198
*
368 jpm 199
* Revision 1.2  2005/04/14 17:39:34  jpm
200
* Amélioration du moteur de rechercher :
201
*  - pourcentage
202
*  - ajout d'info
203
*
339 jpm 204
* Revision 1.1  2004/12/07 10:24:06  jpm
205
* Moteur de recherche version de départ.
206
*
217 jpm 207
*
208
* +-- Fin du code ----------------------------------------------------------------------------------------+
209
*/
210
?>