1 /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 /* Written by Sergei A. Golubchik, who has a shared copyright to this code */
24 
25 #include "ftdefs.h"
26 
27 ulong ft_min_word_len= 4;
28 ulong ft_max_word_len= HA_FT_MAXCHARLEN;
29 ulong ft_query_expansion_limit= 5;
30 const char *ft_boolean_syntax= DEFAULT_FTB_SYNTAX;
31 
32 const HA_KEYSEG ft_keysegs[FT_SEGS]= {
33 {
34   0,                                            /* charset  */
35   HA_FT_WLEN,                                   /* start */
36   0,                                            /* null_pos */
37   0,                                            /* Bit pos */
38   HA_VAR_LENGTH_PART | HA_PACK_KEY,             /* flag */
39   HA_FT_MAXBYTELEN,                             /* length */
40   63,                                           /* language (will be overwritten) */
41   HA_KEYTYPE_VARTEXT2,                          /* type */
42   0,                                            /* null_bit */
43   2, 0, 0                                       /* bit_start, bit_end, bit_length */
44 },
45 {
46   /*
47       Note, this (and the last HA_KEYTYPE_END) segment should NOT
48       be packed in any way, otherwise w_search() won't be able to
49       update key entry 'in vivo'
50     */
51   0, 0, 0, 0, HA_NO_SORT, HA_FT_WLEN, 63, HA_FT_WTYPE, 0, 0, 0, 0
52 }
53 };
54 
55 const struct _ft_vft _ft_vft_nlq= {
56   ft_nlq_read_next, ft_nlq_find_relevance, ft_nlq_close_search,
57   ft_nlq_get_relevance,  ft_nlq_reinit_search
58 };
59 const struct _ft_vft _ft_vft_boolean= {
60   ft_boolean_read_next, ft_boolean_find_relevance, ft_boolean_close_search,
61   ft_boolean_get_relevance,  ft_boolean_reinit_search
62 };
63 
64 
ft_init_search(uint flags,void * info,uint keynr,uchar * query,uint query_len,const CHARSET_INFO * cs,uchar * record)65 FT_INFO *ft_init_search(uint flags, void *info, uint keynr,
66                         uchar *query, uint query_len, const CHARSET_INFO *cs,
67                         uchar *record)
68 {
69   FT_INFO *res;
70   if (flags & FT_BOOL)
71     res= ft_init_boolean_search((MI_INFO *)info, keynr, query, query_len,cs);
72   else
73     res= ft_init_nlq_search((MI_INFO *)info, keynr, query, query_len, flags,
74 			    record);
75   return res;
76 }
77 
78 const char *ft_stopword_file= 0;
79 const char *ft_precompiled_stopwords[]= {
80 
81 #ifdef COMPILE_STOPWORDS_IN
82 
83 /* This particular stopword list was taken from SMART distribution
84    ftp://ftp.cs.cornell.edu/pub/smart/smart.11.0.tar.Z
85    it was slightly modified to my taste, though
86  */
87 
88   "a's",
89   "able",
90   "about",
91   "above",
92   "according",
93   "accordingly",
94   "across",
95   "actually",
96   "after",
97   "afterwards",
98   "again",
99   "against",
100   "ain't",
101   "all",
102   "allow",
103   "allows",
104   "almost",
105   "alone",
106   "along",
107   "already",
108   "also",
109   "although",
110   "always",
111   "am",
112   "among",
113   "amongst",
114   "an",
115   "and",
116   "another",
117   "any",
118   "anybody",
119   "anyhow",
120   "anyone",
121   "anything",
122   "anyway",
123   "anyways",
124   "anywhere",
125   "apart",
126   "appear",
127   "appreciate",
128   "appropriate",
129   "are",
130   "aren't",
131   "around",
132   "as",
133   "aside",
134   "ask",
135   "asking",
136   "associated",
137   "at",
138   "available",
139   "away",
140   "awfully",
141   "be",
142   "became",
143   "because",
144   "become",
145   "becomes",
146   "becoming",
147   "been",
148   "before",
149   "beforehand",
150   "behind",
151   "being",
152   "believe",
153   "below",
154   "beside",
155   "besides",
156   "best",
157   "better",
158   "between",
159   "beyond",
160   "both",
161   "brief",
162   "but",
163   "by",
164   "c'mon",
165   "c's",
166   "came",
167   "can",
168   "can't",
169   "cannot",
170   "cant",
171   "cause",
172   "causes",
173   "certain",
174   "certainly",
175   "changes",
176   "clearly",
177   "co",
178   "com",
179   "come",
180   "comes",
181   "concerning",
182   "consequently",
183   "consider",
184   "considering",
185   "contain",
186   "containing",
187   "contains",
188   "corresponding",
189   "could",
190   "couldn't",
191   "course",
192   "currently",
193   "definitely",
194   "described",
195   "despite",
196   "did",
197   "didn't",
198   "different",
199   "do",
200   "does",
201   "doesn't",
202   "doing",
203   "don't",
204   "done",
205   "down",
206   "downwards",
207   "during",
208   "each",
209   "edu",
210   "eg",
211   "eight",
212   "either",
213   "else",
214   "elsewhere",
215   "enough",
216   "entirely",
217   "especially",
218   "et",
219   "etc",
220   "even",
221   "ever",
222   "every",
223   "everybody",
224   "everyone",
225   "everything",
226   "everywhere",
227   "ex",
228   "exactly",
229   "example",
230   "except",
231   "far",
232   "few",
233   "fifth",
234   "first",
235   "five",
236   "followed",
237   "following",
238   "follows",
239   "for",
240   "former",
241   "formerly",
242   "forth",
243   "four",
244   "from",
245   "further",
246   "furthermore",
247   "get",
248   "gets",
249   "getting",
250   "given",
251   "gives",
252   "go",
253   "goes",
254   "going",
255   "gone",
256   "got",
257   "gotten",
258   "greetings",
259   "had",
260   "hadn't",
261   "happens",
262   "hardly",
263   "has",
264   "hasn't",
265   "have",
266   "haven't",
267   "having",
268   "he",
269   "he's",
270   "hello",
271   "help",
272   "hence",
273   "her",
274   "here",
275   "here's",
276   "hereafter",
277   "hereby",
278   "herein",
279   "hereupon",
280   "hers",
281   "herself",
282   "hi",
283   "him",
284   "himself",
285   "his",
286   "hither",
287   "hopefully",
288   "how",
289   "howbeit",
290   "however",
291   "i'd",
292   "i'll",
293   "i'm",
294   "i've",
295   "ie",
296   "if",
297   "ignored",
298   "immediate",
299   "in",
300   "inasmuch",
301   "inc",
302   "indeed",
303   "indicate",
304   "indicated",
305   "indicates",
306   "inner",
307   "insofar",
308   "instead",
309   "into",
310   "inward",
311   "is",
312   "isn't",
313   "it",
314   "it'd",
315   "it'll",
316   "it's",
317   "its",
318   "itself",
319   "just",
320   "keep",
321   "keeps",
322   "kept",
323   "know",
324   "knows",
325   "known",
326   "last",
327   "lately",
328   "later",
329   "latter",
330   "latterly",
331   "least",
332   "less",
333   "lest",
334   "let",
335   "let's",
336   "like",
337   "liked",
338   "likely",
339   "little",
340   "look",
341   "looking",
342   "looks",
343   "ltd",
344   "mainly",
345   "many",
346   "may",
347   "maybe",
348   "me",
349   "mean",
350   "meanwhile",
351   "merely",
352   "might",
353   "more",
354   "moreover",
355   "most",
356   "mostly",
357   "much",
358   "must",
359   "my",
360   "myself",
361   "name",
362   "namely",
363   "nd",
364   "near",
365   "nearly",
366   "necessary",
367   "need",
368   "needs",
369   "neither",
370   "never",
371   "nevertheless",
372   "new",
373   "next",
374   "nine",
375   "no",
376   "nobody",
377   "non",
378   "none",
379   "noone",
380   "nor",
381   "normally",
382   "not",
383   "nothing",
384   "novel",
385   "now",
386   "nowhere",
387   "obviously",
388   "of",
389   "off",
390   "often",
391   "oh",
392   "ok",
393   "okay",
394   "old",
395   "on",
396   "once",
397   "one",
398   "ones",
399   "only",
400   "onto",
401   "or",
402   "other",
403   "others",
404   "otherwise",
405   "ought",
406   "our",
407   "ours",
408   "ourselves",
409   "out",
410   "outside",
411   "over",
412   "overall",
413   "own",
414   "particular",
415   "particularly",
416   "per",
417   "perhaps",
418   "placed",
419   "please",
420   "plus",
421   "possible",
422   "presumably",
423   "probably",
424   "provides",
425   "que",
426   "quite",
427   "qv",
428   "rather",
429   "rd",
430   "re",
431   "really",
432   "reasonably",
433   "regarding",
434   "regardless",
435   "regards",
436   "relatively",
437   "respectively",
438   "right",
439   "said",
440   "same",
441   "saw",
442   "say",
443   "saying",
444   "says",
445   "second",
446   "secondly",
447   "see",
448   "seeing",
449   "seem",
450   "seemed",
451   "seeming",
452   "seems",
453   "seen",
454   "self",
455   "selves",
456   "sensible",
457   "sent",
458   "serious",
459   "seriously",
460   "seven",
461   "several",
462   "shall",
463   "she",
464   "should",
465   "shouldn't",
466   "since",
467   "six",
468   "so",
469   "some",
470   "somebody",
471   "somehow",
472   "someone",
473   "something",
474   "sometime",
475   "sometimes",
476   "somewhat",
477   "somewhere",
478   "soon",
479   "sorry",
480   "specified",
481   "specify",
482   "specifying",
483   "still",
484   "sub",
485   "such",
486   "sup",
487   "sure",
488   "t's",
489   "take",
490   "taken",
491   "tell",
492   "tends",
493   "th",
494   "than",
495   "thank",
496   "thanks",
497   "thanx",
498   "that",
499   "that's",
500   "thats",
501   "the",
502   "their",
503   "theirs",
504   "them",
505   "themselves",
506   "then",
507   "thence",
508   "there",
509   "there's",
510   "thereafter",
511   "thereby",
512   "therefore",
513   "therein",
514   "theres",
515   "thereupon",
516   "these",
517   "they",
518   "they'd",
519   "they'll",
520   "they're",
521   "they've",
522   "think",
523   "third",
524   "this",
525   "thorough",
526   "thoroughly",
527   "those",
528   "though",
529   "three",
530   "through",
531   "throughout",
532   "thru",
533   "thus",
534   "to",
535   "together",
536   "too",
537   "took",
538   "toward",
539   "towards",
540   "tried",
541   "tries",
542   "truly",
543   "try",
544   "trying",
545   "twice",
546   "two",
547   "un",
548   "under",
549   "unfortunately",
550   "unless",
551   "unlikely",
552   "until",
553   "unto",
554   "up",
555   "upon",
556   "us",
557   "use",
558   "used",
559   "useful",
560   "uses",
561   "using",
562   "usually",
563   "value",
564   "various",
565   "very",
566   "via",
567   "viz",
568   "vs",
569   "want",
570   "wants",
571   "was",
572   "wasn't",
573   "way",
574   "we",
575   "we'd",
576   "we'll",
577   "we're",
578   "we've",
579   "welcome",
580   "well",
581   "went",
582   "were",
583   "weren't",
584   "what",
585   "what's",
586   "whatever",
587   "when",
588   "whence",
589   "whenever",
590   "where",
591   "where's",
592   "whereafter",
593   "whereas",
594   "whereby",
595   "wherein",
596   "whereupon",
597   "wherever",
598   "whether",
599   "which",
600   "while",
601   "whither",
602   "who",
603   "who's",
604   "whoever",
605   "whole",
606   "whom",
607   "whose",
608   "why",
609   "will",
610   "willing",
611   "wish",
612   "with",
613   "within",
614   "without",
615   "won't",
616   "wonder",
617   "would",
618   "wouldn't",
619   "yes",
620   "yet",
621   "you",
622   "you'd",
623   "you'll",
624   "you're",
625   "you've",
626   "your",
627   "yours",
628   "yourself",
629   "yourselves",
630   "zero",
631 #endif
632 
633   NULL };
634 
ft_default_parser_parse(MYSQL_FTPARSER_PARAM * param)635 static int ft_default_parser_parse(MYSQL_FTPARSER_PARAM *param)
636 {
637   return param->mysql_parse(param, param->doc, param->length);
638 }
639 
640 struct st_mysql_ftparser ft_default_parser=
641 {
642   MYSQL_FTPARSER_INTERFACE_VERSION, ft_default_parser_parse, 0, 0
643 };
644 
645