MySQL 8.3.0
Source Code Documentation
ftdefs.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2023, 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/**
26 @file storage/myisam/ftdefs.h
27 Some definitions for full-text indices.
28*/
29
30#include <math.h>
31#include <mysql/plugin.h>
32#include <cstdint>
33
34#include "my_tree.h"
38
39inline bool true_word_char(int c, uint8_t ch) {
40 return ((c & (MY_CHAR_U | MY_CHAR_L | MY_CHAR_NMR)) != 0) || ch == '_';
41}
42
43#define FT_MAX_WORD_LEN_FOR_SORT 31
44
45#define FTPARSER_MEMROOT_ALLOC_SIZE 65536
46
47/* Interested readers may consult SMART
48 (ftp://ftp.cs.cornell.edu/pub/smart/smart.11.0.tar.Z)
49 for an excellent implementation of vector space model we use.
50 It also demonstrate the usage of different weghting techniques.
51 This code, though, is completely original and is not based on the
52 SMART code but was in some cases inspired by it.
53
54 NORM_PIVOT was taken from the article
55 A.Singhal, C.Buckley, M.Mitra, "Pivoted Document Length Normalization",
56 ACM SIGIR'96, 21-29, 1996
57 */
58
59#define LWS_FOR_QUERY LWS_TF
60#define LWS_IN_USE LWS_LOG
61#define PRENORM_IN_USE PRENORM_AVG
62#define NORM_IN_USE NORM_PIVOT
63#define GWS_IN_USE GWS_PROB
64/*==============================================================*/
65#define LWS_TF (count)
66#define LWS_BINARY (count > 0)
67#define LWS_SQUARE (count * count)
68#define LWS_LOG (count ? (log((double)count) + 1) : 0)
69/*--------------------------------------------------------------*/
70#define PRENORM_NONE (p->weight)
71#define PRENORM_MAX (p->weight / docstat.max)
72#define PRENORM_AUG (0.4 + 0.6 * p->weight / docstat.max)
73#define PRENORM_AVG (p->weight / docstat.sum * docstat.uniq)
74#define PRENORM_AVGLOG \
75 ((1 + log(p->weight)) / (1 + log(docstat.sum / docstat.uniq)))
76/*--------------------------------------------------------------*/
77#define NORM_NONE (1)
78#define NORM_SUM (docstat.nsum)
79#define NORM_COS (sqrt(docstat.nsum2))
80
81#define PIVOT_VAL (0.0115)
82#define NORM_PIVOT (1 + PIVOT_VAL * docstat.uniq)
83/*---------------------------------------------------------------*/
84#define GWS_NORM (1 / sqrt(sum2))
85#define GWS_GFIDF (sum / doc_cnt)
86/* Mysterious, but w/o (double) GWS_IDF performs better :-o */
87#define GWS_IDF log(aio->info->state->records / doc_cnt)
88#define GWS_IDF1 log((double)aio->info->state->records / doc_cnt)
89#define GWS_PROB \
90 ((aio->info->state->records > doc_cnt) \
91 ? log(((double)(aio->info->state->records - doc_cnt)) / doc_cnt) \
92 : 0)
93#define GWS_FREQ (1.0 / doc_cnt)
94#define GWS_SQUARED pow(log((double)aio->info->state->records / doc_cnt), 2)
95#define GWS_CUBIC pow(log((double)aio->info->state->records / doc_cnt), 3)
96#define GWS_ENTROPY \
97 (1 - (suml / sum - log(sum)) / log(aio->info->state->records))
98/*=================================================================*/
99
100/* Boolean search operators */
101#define FTB_YES (ft_boolean_syntax[0])
102#define FTB_EGAL (ft_boolean_syntax[1])
103#define FTB_NO (ft_boolean_syntax[2])
104#define FTB_INC (ft_boolean_syntax[3])
105#define FTB_DEC (ft_boolean_syntax[4])
106#define FTB_LBR (ft_boolean_syntax[5])
107#define FTB_RBR (ft_boolean_syntax[6])
108#define FTB_NEG (ft_boolean_syntax[7])
109#define FTB_TRUNC (ft_boolean_syntax[8])
110#define FTB_LQUOT (ft_boolean_syntax[10])
111#define FTB_RQUOT (ft_boolean_syntax[11])
112
113#ifdef __cplusplus
114extern "C" {
115#endif
116
117struct FT_WORD {
118 uchar *pos;
119 uint len;
120 double weight;
121};
122
123int is_stopword(char *word, uint len);
124
125uint _ft_make_key(MI_INFO *, uint, uchar *, FT_WORD *, my_off_t);
126
129uchar ft_simple_get_word(const CHARSET_INFO *, uchar **, const uchar *,
130 FT_WORD *, bool);
131
132typedef struct _st_ft_seg_iterator {
133 uint num, len;
135 const uchar *rec, *pos;
137
138void _mi_ft_segiterator_init(MI_INFO *, uint, const uchar *, FT_SEG_ITERATOR *);
141
142void ft_parse_init(TREE *, const CHARSET_INFO *);
143int ft_parse(TREE *, uchar *, int, struct st_mysql_ftparser *parser,
146FT_WORD *_mi_ft_parserecord(MI_INFO *, uint, const uchar *, MEM_ROOT *);
147uint _mi_ft_parse(TREE *, MI_INFO *, uint, const uchar *,
149
150FT_INFO *ft_init_nlq_search(MI_INFO *, uint, uchar *, uint, uint, uchar *);
152 const CHARSET_INFO *);
153
154extern const struct _ft_vft _ft_vft_nlq;
155int ft_nlq_read_next(FT_INFO *, char *);
156float ft_nlq_find_relevance(FT_INFO *, uchar *, uint);
161
162extern const struct _ft_vft _ft_vft_boolean;
163
164int ft_boolean_read_next(FT_INFO *, char *);
165float ft_boolean_find_relevance(FT_INFO *, uchar *, uint);
170
173 uint keynr,
174 uint paramnr);
176
177#ifdef __cplusplus
178} // extern "C"
179#endif
FT_WORD * ft_linearize(TREE *, MEM_ROOT *)
Definition: ft_parser.cc:67
void ftparser_call_deinitializer(MI_INFO *info)
Definition: ft_parser.cc:363
void ft_parse_init(TREE *, const CHARSET_INFO *)
Definition: ft_parser.cc:244
FT_INFO * ft_init_nlq_search(MI_INFO *, uint, uchar *, uint, uint, uchar *)
Definition: ft_nlq_search.cc:219
int ft_nlq_read_next(FT_INFO *, char *)
Definition: ft_nlq_search.cc:308
const struct _ft_vft _ft_vft_boolean
Definition: ft_static.cc:61
const struct _ft_vft _ft_vft_nlq
Definition: ft_static.cc:58
int ft_parse(TREE *, uchar *, int, struct st_mysql_ftparser *parser, MYSQL_FTPARSER_PARAM *, MEM_ROOT *)
Definition: ft_parser.cc:290
float ft_nlq_find_relevance(FT_INFO *, uchar *, uint)
Definition: ft_nlq_search.cc:331
void ft_boolean_close_search(FT_INFO *)
Definition: ft_boolean_search.cc:941
bool true_word_char(int c, uint8_t ch)
Definition: ftdefs.h:39
void _mi_ft_segiterator_dummy_init(const uchar *, uint, FT_SEG_ITERATOR *)
Definition: ft_update.cc:49
void ft_nlq_close_search(FT_INFO *)
Definition: ft_nlq_search.cc:356
float ft_boolean_find_relevance(FT_INFO *, uchar *, uint)
Definition: ft_boolean_search.cc:884
uchar ft_get_word(const CHARSET_INFO *, uchar **, uchar *, FT_WORD *, MYSQL_FTPARSER_BOOLEAN_INFO *)
Definition: ft_parser.cc:120
void ft_nlq_reinit_search(FT_INFO *)
Definition: ft_nlq_search.cc:363
float ft_nlq_get_relevance(FT_INFO *)
Definition: ft_nlq_search.cc:358
my_off_t ft_nlq_get_docid(FT_INFO *)
MYSQL_FTPARSER_PARAM * ftparser_call_initializer(MI_INFO *info, uint keynr, uint paramnr)
Definition: ft_parser.cc:334
uint _mi_ft_parse(TREE *, MI_INFO *, uint, const uchar *, MYSQL_FTPARSER_PARAM *, MEM_ROOT *)
Definition: ft_update.cc:102
FT_WORD * _mi_ft_parserecord(MI_INFO *, uint, const uchar *, MEM_ROOT *)
Definition: ft_update.cc:121
struct _st_ft_seg_iterator FT_SEG_ITERATOR
FT_INFO * ft_init_boolean_search(MI_INFO *, uint, uchar *, uint, const CHARSET_INFO *)
Definition: ft_boolean_search.cc:516
int is_stopword(char *word, uint len)
Definition: ft_stopwords.cc:125
uint _mi_ft_segiterator(FT_SEG_ITERATOR *)
Definition: ft_update.cc:68
my_off_t ft_boolean_get_docid(FT_INFO *)
MYSQL_FTPARSER_PARAM * ftparser_alloc_param(MI_INFO *info)
Definition: ft_parser.cc:312
uchar ft_simple_get_word(const CHARSET_INFO *, uchar **, const uchar *, FT_WORD *, bool)
Definition: ft_parser.cc:210
void _mi_ft_segiterator_init(MI_INFO *, uint, const uchar *, FT_SEG_ITERATOR *)
Definition: ft_update.cc:40
int ft_boolean_read_next(FT_INFO *, char *)
Definition: ft_boolean_search.cc:743
uint _ft_make_key(MI_INFO *, uint, uchar *, FT_WORD *, my_off_t)
Definition: ft_update.cc:266
float ft_boolean_get_relevance(FT_INFO *)
Definition: ft_boolean_search.cc:950
void ft_boolean_reinit_search(FT_INFO *)
Definition: ft_boolean_search.cc:955
Some definitions for full-text indices.
A better implementation of the UNIX ctype(3) library.
static constexpr uint8_t MY_CHAR_L
Definition: m_ctype.h:541
static constexpr uint8_t MY_CHAR_NMR
Definition: m_ctype.h:542
static constexpr uint8_t MY_CHAR_U
Definition: m_ctype.h:540
ulonglong my_off_t
Definition: my_inttypes.h:71
unsigned char uchar
Definition: my_inttypes.h:51
struct Parser parser
Code for handling of priority queues.
Definition: m_ctype.h:422
Definition: ft_global.h:71
FTS query token.
Definition: fts0tokenize.h:61
uint len
word len
Definition: fts0tokenize.h:63
double weight
word weight, unused in innodb
Definition: fts0tokenize.h:64
uchar * pos
word start pointer
Definition: fts0tokenize.h:62
Definition: my_compare.h:59
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: myisamdef.h:252
Definition: plugin_ftparser.h:132
Definition: plugin_ftparser.h:194
Definition: my_tree.h:67
Definition: ft_global.h:47
Definition: ftdefs.h:132
uint len
Definition: ftdefs.h:133
HA_KEYSEG * seg
Definition: ftdefs.h:134
const uchar * rec
Definition: ftdefs.h:135
uint num
Definition: ftdefs.h:133
const uchar * pos
Definition: ftdefs.h:135
Definition: plugin_ftparser.h:215