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