Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id$
4
 *
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
 *
17
 * This software consists of voluntary contributions made by many individuals
18
 * and is licensed under the LGPL. For more information, see
19
 * <http://www.doctrine-project.org>.
20
 */
21
 
22
/**
23
 * Doctrine_Search_Analyzer_Standard
24
 *
25
 * @package     Doctrine
26
 * @subpackage  Search
27
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
28
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
29
 * @version     $Revision$
30
 * @link        www.doctrine-project.org
31
 * @since       1.0
32
 */
33
class Doctrine_Search_Analyzer_Standard extends Doctrine_Search_Analyzer implements Doctrine_Search_Analyzer_Interface
34
{
35
    protected static $_stopwords = array(
36
                            // Ticket #1787. Fixed searchable behavior numeric evaluation
37
                            // Removed the numeric 0-9 from here
38
                            'a',
39
                            'about',
40
                            'after',
41
                            'all',
42
                            'almost',
43
                            'along',
44
                            'also',
45
                            'although',
46
                            'amp',
47
                            'an',
48
                            'and',
49
                            'another',
50
                            'any',
51
                            'are',
52
                            'area',
53
                            'arent',
54
                            'around',
55
                            'as',
56
                            'at',
57
                            'available',
58
                            'back',
59
                            'be',
60
                            'because',
61
                            'been',
62
                            'before',
63
                            'being',
64
                            'best',
65
                            'better',
66
                            'big',
67
                            'bit',
68
                            'both',
69
                            'but',
70
                            'by',
71
                            'c',
72
                            'came',
73
                            'can',
74
                            'capable',
75
                            'control',
76
                            'could',
77
                            'course',
78
                            'd',
79
                            'dan',
80
                            'day',
81
                            'decided',
82
                            'did',
83
                            'didn',
84
                            'different',
85
                            'div',
86
                            'do',
87
                            'doesn',
88
                            'don',
89
                            'down',
90
                            'drive',
91
                            'e',
92
                            'each',
93
                            'easily',
94
                            'easy',
95
                            'edition',
96
                            'either',
97
                            'end',
98
                            'enough',
99
                            'even',
100
                            'every',
101
                            'example',
102
                            'few',
103
                            'find',
104
                            'first',
105
                            'for',
106
                            'found',
107
                            'from',
108
                            'get',
109
                            'go',
110
                            'going',
111
                            'good',
112
                            'got',
113
                            'gt',
114
                            'had',
115
                            'hard',
116
                            'has',
117
                            'have',
118
                            'he',
119
                            'her',
120
                            'here',
121
                            'how',
122
                            'i',
123
                            'if',
124
                            'in',
125
                            'into',
126
                            'is',
127
                            'isn',
128
                            'it',
129
                            'just',
130
                            'know',
131
                            'last',
132
                            'left',
133
                            'li',
134
                            'like',
135
                            'little',
136
                            'll',
137
                            'long',
138
                            'look',
139
                            'lot',
140
                            'lt',
141
                            'm',
142
                            'made',
143
                            'make',
144
                            'many',
145
                            'mb',
146
                            'me',
147
                            'menu',
148
                            'might',
149
                            'mm',
150
                            'more',
151
                            'most',
152
                            'much',
153
                            'my',
154
                            'name',
155
                            'nbsp',
156
                            'need',
157
                            'new',
158
                            'no',
159
                            'not',
160
                            'now',
161
                            'number',
162
                            'of',
163
                            'off',
164
                            'old',
165
                            'on',
166
                            'one',
167
                            'only',
168
                            'or',
169
                            'original',
170
                            'other',
171
                            'our',
172
                            'out',
173
                            'over',
174
                            'part',
175
                            'place',
176
                            'point',
177
                            'pretty',
178
                            'probably',
179
                            'problem',
180
                            'put',
181
                            'quite',
182
                            'quot',
183
                            'r',
184
                            're',
185
                            'really',
186
                            'results',
187
                            'right',
188
                            's',
189
                            'same',
190
                            'saw',
191
                            'see',
192
                            'set',
193
                            'several',
194
                            'she',
195
                            'sherree',
196
                            'should',
197
                            'since',
198
                            'size',
199
                            'small',
200
                            'so',
201
                            'some',
202
                            'something',
203
                            'special',
204
                            'still',
205
                            'stuff',
206
                            'such',
207
                            'sure',
208
                            'system',
209
                            't',
210
                            'take',
211
                            'than',
212
                            'that',
213
                            'the',
214
                            'their',
215
                            'them',
216
                            'then',
217
                            'there',
218
                            'these',
219
                            'they',
220
                            'thing',
221
                            'things',
222
                            'think',
223
                            'this',
224
                            'those',
225
                            'though',
226
                            'through',
227
                            'time',
228
                            'to',
229
                            'today',
230
                            'together',
231
                            'too',
232
                            'took',
233
                            'two',
234
                            'up',
235
                            'us',
236
                            'use',
237
                            'used',
238
                            'using',
239
                            've',
240
                            'very',
241
                            'want',
242
                            'was',
243
                            'way',
244
                            'we',
245
                            'well',
246
                            'went',
247
                            'were',
248
                            'what',
249
                            'when',
250
                            'where',
251
                            'which',
252
                            'while',
253
                            'white',
254
                            'who',
255
                            'will',
256
                            'with',
257
                            'would',
258
                            'yet',
259
                            'you',
260
                            'your',
261
                            'yours'
262
                            );
263
 
264
    public function analyze($text, $encoding = null)
265
    {
266
        $text = preg_replace('/[\'`´"]/', '', $text);
267
        $text = Doctrine_Inflector::unaccent($text);
268
        $text = preg_replace('/[^A-Za-z0-9]/', ' ', $text);
269
        $text = str_replace('  ', ' ', $text);
270
 
271
        $terms = explode(' ', $text);
272
 
273
        $ret = array();
274
        if ( ! empty($terms)) {
275
            foreach ($terms as $i => $term) {
276
                if (empty($term)) {
277
                    continue;
278
                }
279
                $lower = strtolower(trim($term));
280
 
281
                if (in_array($lower, self::$_stopwords)) {
282
                    continue;
283
                }
284
 
285
                $ret[$i] = $lower;
286
            }
287
        }
288
        return $ret;
289
    }
290
}