Subversion Repositories Applications.papyrus

Rev

Rev 1087 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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