| 1 | /* Copyright (c) 2000-2007 MySQL AB, 2009 Sun Microsystems, Inc. |
| 2 | Use is subject to license terms. |
| 3 | |
| 4 | This program is free software; you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by |
| 6 | the Free Software Foundation; version 2 of the License. |
| 7 | |
| 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program; if not, write to the Free Software |
| 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ |
| 16 | |
| 17 | /* Written by Sergei A. Golubchik, who has a shared copyright to this code */ |
| 18 | |
| 19 | /* some definitions for full-text indices */ |
| 20 | |
| 21 | /* ftdefs.h is always included first when used, so we have to include my_global.h here */ |
| 22 | #include <my_global.h>cxx . . $ `<file>/include/my_global.h`/ |
| 23 | #include "fulltext.h"cxx . . $ `<file>/storage/myisam/fulltext.h`/ |
| 24 | #include <m_ctype.h>cxx . . $ `<file>/include/m_ctype.h`/ |
| 25 | #include <my_tree.h>cxx . . $ `<file>/include/my_tree.h`/ |
| 26 | #include <queues.h>cxx . . $ `<file>/include/queues.h`/ |
| 27 | #include <mysql/plugin.h>cxx . . $ `<file>/include/mysql/plugin.h`/ |
| 28 | |
| 29 | #define true_word_charcxx . . $ `storage/myisam/ftdefs.h:29:9`!(ctype, character) \ |
| 30 | ((ctype) & (_MY_Ucxx . . $ `include/m_ctype.h:1869:9`! | _MY_Lcxx . . $ `include/m_ctype.h:1870:9`! | _MY_NMRcxx . . $ `include/m_ctype.h:1871:9`!) || \ |
| 31 | (character) == '_') |
| 32 | #define misc_word_charcxx . . $ `storage/myisam/ftdefs.h:32:9`!(X) 0 |
| 33 | |
| 34 | #define FT_MAX_WORD_LEN_FOR_SORTcxx . . $ `storage/myisam/ftdefs.h:34:9`! 31 |
| 35 | |
| 36 | #define FTPARSER_MEMROOT_ALLOC_SIZEcxx . . $ `storage/myisam/ftdefs.h:36:9`! 65536 |
| 37 | |
| 38 | #define COMPILE_STOPWORDS_INcxx . . $ `storage/myisam/ftdefs.h:38:9`! |
| 39 | |
| 40 | /* Interested readers may consult SMART |
| 41 | (ftp://ftp.cs.cornell.edu/pub/smart/smart.11.0.tar.Z) |
| 42 | for an excellent implementation of vector space model we use. |
| 43 | It also demonstrate the usage of different weghting techniques. |
| 44 | This code, though, is completely original and is not based on the |
| 45 | SMART code but was in some cases inspired by it. |
| 46 | |
| 47 | NORM_PIVOT was taken from the article |
| 48 | A.Singhal, C.Buckley, M.Mitra, "Pivoted Document Length Normalization", |
| 49 | ACM SIGIR'96, 21-29, 1996 |
| 50 | */ |
| 51 | |
| 52 | #define LWS_FOR_QUERYcxx . . $ `storage/myisam/ftdefs.h:52:9`! LWS_TF |
| 53 | #define LWS_IN_USEcxx . . $ `storage/myisam/ftdefs.h:53:9`! LWS_LOGcxx . . $ `storage/myisam/ftdefs.h:61:9`! |
| 54 | #define PRENORM_IN_USEcxx . . $ `storage/myisam/ftdefs.h:54:9`! PRENORM_AVGcxx . . $ `storage/myisam/ftdefs.h:66:9`! |
| 55 | #define NORM_IN_USEcxx . . $ `storage/myisam/ftdefs.h:55:9`! NORM_PIVOTcxx . . $ `storage/myisam/ftdefs.h:74:9`! |
| 56 | #define GWS_IN_USEcxx . . $ `storage/myisam/ftdefs.h:56:9`! GWS_PROB |
| 57 | /*==============================================================*/ |
| 58 | #define LWS_TFcxx . . $ `storage/myisam/ftdefs.h:58:9`! (count) |
| 59 | #define LWS_BINARYcxx . . $ `storage/myisam/ftdefs.h:59:9`! (count>0) |
| 60 | #define LWS_SQUAREcxx . . $ `storage/myisam/ftdefs.h:60:9`! (count*count) |
| 61 | #define LWS_LOGcxx . . $ `storage/myisam/ftdefs.h:61:9`! (count?(log( (double) count)+1):0) |
| 62 | /*--------------------------------------------------------------*/ |
| 63 | #define PRENORM_NONEcxx . . $ `storage/myisam/ftdefs.h:63:9`! (p->weight) |
| 64 | #define PRENORM_MAXcxx . . $ `storage/myisam/ftdefs.h:64:9`! (p->weight/docstat.max) |
| 65 | #define PRENORM_AUGcxx . . $ `storage/myisam/ftdefs.h:65:9`! (0.4+0.6*p->weight/docstat.max) |
| 66 | #define PRENORM_AVGcxx . . $ `storage/myisam/ftdefs.h:66:9`! (p->weight/docstat.sum*docstat.uniq) |
| 67 | #define PRENORM_AVGLOGcxx . . $ `storage/myisam/ftdefs.h:67:9`! ((1+log(p->weight))/(1+log(docstat.sum/docstat.uniq))) |
| 68 | /*--------------------------------------------------------------*/ |
| 69 | #define NORM_NONEcxx . . $ `storage/myisam/ftdefs.h:69:9`! (1) |
| 70 | #define NORM_SUMcxx . . $ `storage/myisam/ftdefs.h:70:9`! (docstat.nsum) |
| 71 | #define NORM_COScxx . . $ `storage/myisam/ftdefs.h:71:9`! (sqrt(docstat.nsum2)) |
| 72 | |
| 73 | #define PIVOT_VALcxx . . $ `storage/myisam/ftdefs.h:73:9`! (0.0115) |
| 74 | #define NORM_PIVOTcxx . . $ `storage/myisam/ftdefs.h:74:9`! (1+PIVOT_VALcxx . . $ `storage/myisam/ftdefs.h:73:9`!*docstat.uniq) |
| 75 | /*---------------------------------------------------------------*/ |
| 76 | #define GWS_NORMcxx . . $ `storage/myisam/ftdefs.h:76:9`! (1/sqrt(sum2)) |
| 77 | #define GWS_GFIDFcxx . . $ `storage/myisam/ftdefs.h:77:9`! (sum/doc_cnt) |
| 78 | /* Mysterious, but w/o (double) GWS_IDF performs better :-o */ |
| 79 | #define GWS_IDFcxx . . $ `storage/myisam/ftdefs.h:79:9`! log(aio->info->state->records/doc_cnt) |
| 80 | #define GWS_IDF1cxx . . $ `storage/myisam/ftdefs.h:80:9`! log((double)aio->info->state->records/doc_cnt) |
| 81 | #define GWS_PROBcxx . . $ `storage/myisam/ftdefs.h:81:9`! ((aio->info->state->records > doc_cnt) ? log(((double)(aio->info->state->records-doc_cnt))/doc_cnt) : 0 ) |
| 82 | #define GWS_FREQcxx . . $ `storage/myisam/ftdefs.h:82:9`! (1.0/doc_cnt) |
| 83 | #define GWS_SQUAREDcxx . . $ `storage/myisam/ftdefs.h:83:9`! pow(log((double)aio->info->state->records/doc_cnt),2) |
| 84 | #define GWS_CUBICcxx . . $ `storage/myisam/ftdefs.h:84:9`! pow(log((double)aio->info->state->records/doc_cnt),3) |
| 85 | #define GWS_ENTROPYcxx . . $ `storage/myisam/ftdefs.h:85:9`! (1-(suml/sum-log(sum))/log(aio->info->state->records)) |
| 86 | /*=================================================================*/ |
| 87 | |
| 88 | /* Boolean search operators */ |
| 89 | #define FTB_YEScxx . . $ `storage/myisam/ftdefs.h:89:9`! (ft_boolean_syntax[0]) |
| 90 | #define FTB_EGALcxx . . $ `storage/myisam/ftdefs.h:90:9`! (ft_boolean_syntax[1]) |
| 91 | #define FTB_NOcxx . . $ `storage/myisam/ftdefs.h:91:9`! (ft_boolean_syntax[2]) |
| 92 | #define FTB_INCcxx . . $ `storage/myisam/ftdefs.h:92:9`! (ft_boolean_syntax[3]) |
| 93 | #define FTB_DECcxx . . $ `storage/myisam/ftdefs.h:93:9`! (ft_boolean_syntax[4]) |
| 94 | #define FTB_LBRcxx . . $ `storage/myisam/ftdefs.h:94:9`! (ft_boolean_syntax[5]) |
| 95 | #define FTB_RBRcxx . . $ `storage/myisam/ftdefs.h:95:9`! (ft_boolean_syntax[6]) |
| 96 | #define FTB_NEGcxx . . $ `storage/myisam/ftdefs.h:96:9`! (ft_boolean_syntax[7]) |
| 97 | #define FTB_TRUNCcxx . . $ `storage/myisam/ftdefs.h:97:9`! (ft_boolean_syntax[8]) |
| 98 | #define FTB_LQUOTcxx . . $ `storage/myisam/ftdefs.h:98:9`! (ft_boolean_syntax[10]) |
| 99 | #define FTB_RQUOTcxx . . $ `storage/myisam/ftdefs.h:99:9`! (ft_boolean_syntax[11]) |
| 100 | |
| 101 | typedef struct st_ft_wordcxx . . $ st_ft_word# { |
| 102 | const ucharcxx . . $ uchar# *poscxx . . $ st_ft_word#pos.; |
| 103 | double weightcxx . . $ st_ft_word#weight.; |
| 104 | size_t lencxx . . $ st_ft_word#len.; |
| 105 | } FT_WORDcxx . . $ FT_WORD#; |
| 106 | |
| 107 | int is_stopwordcxx . . $ is_stopword(54dd70b47e85a2fc).(const char *word, size_t len); |
| 108 | |
| 109 | uintcxx . . $ uint# _ft_make_keycxx . . $ _ft_make_key(4ab9d8b51abfca53).(MI_INFOcxx . . $ MI_INFO# *, uintcxx . . $ uint# , ucharcxx . . $ uchar# *, FT_WORDcxx . . $ FT_WORD# *, my_off_tcxx . . $ my_off_t#); |
| 110 | |
| 111 | ucharcxx . . $ uchar# ft_get_wordcxx . . $ ft_get_word(5771e66947ebd7bc).(CHARSET_INFOcxx . . $ CHARSET_INFO# *, const ucharcxx . . $ uchar# **, const ucharcxx . . $ uchar# *, FT_WORDcxx . . $ FT_WORD# *, |
| 112 | MYSQL_FTPARSER_BOOLEAN_INFOcxx . . $ MYSQL_FTPARSER_BOOLEAN_INFO# *); |
| 113 | ucharcxx . . $ uchar# ft_simple_get_wordcxx . . $ ft_simple_get_word(c1c0ee06c4fdfd96).(CHARSET_INFOcxx . . $ CHARSET_INFO# *, ucharcxx . . $ uchar# **, const ucharcxx . . $ uchar# *, |
| 114 | FT_WORDcxx . . $ FT_WORD# *, my_boolcxx . . $ my_bool#); |
| 115 | |
| 116 | typedef struct _st_ft_seg_iteratorcxx . . $ _st_ft_seg_iterator# { |
| 117 | uintcxx . . $ uint# numcxx . . $ _st_ft_seg_iterator#num., lencxx . . $ _st_ft_seg_iterator#len.; |
| 118 | HA_KEYSEGcxx . . $ HA_KEYSEG# *segcxx . . $ _st_ft_seg_iterator#seg.; |
| 119 | const ucharcxx . . $ uchar# *reccxx . . $ _st_ft_seg_iterator#rec., *poscxx . . $ _st_ft_seg_iterator#pos.; |
| 120 | } FT_SEG_ITERATORcxx . . $ FT_SEG_ITERATOR#; |
| 121 | |
| 122 | void _mi_ft_segiterator_initcxx . . $ _mi_ft_segiterator_init(3b0100588b6ef5cb).(MI_INFOcxx . . $ MI_INFO# *, uintcxx . . $ uint#, const ucharcxx . . $ uchar# *, FT_SEG_ITERATORcxx . . $ FT_SEG_ITERATOR# *); |
| 123 | void _mi_ft_segiterator_dummy_initcxx . . $ _mi_ft_segiterator_dummy_init(d1a1b813f9ff9566).(const ucharcxx . . $ uchar# *, uintcxx . . $ uint#, FT_SEG_ITERATORcxx . . $ FT_SEG_ITERATOR# *); |
| 124 | uintcxx . . $ uint# _mi_ft_segiteratorcxx . . $ _mi_ft_segiterator(1dc502ae8b31a611).(FT_SEG_ITERATORcxx . . $ FT_SEG_ITERATOR# *); |
| 125 | |
| 126 | void ft_parse_initcxx . . $ ft_parse_init(9367f67720418092).(TREEcxx . . $ TREE# *, CHARSET_INFOcxx . . $ CHARSET_INFO# *); |
| 127 | int ft_parsecxx . . $ ft_parse(3564f3f25aa2d3ec).(TREEcxx . . $ TREE# *, ucharcxx . . $ uchar# *, int, struct st_mysql_ftparsercxx . . $ st_mysql_ftparser# *parser, |
| 128 | MYSQL_FTPARSER_PARAMcxx . . $ MYSQL_FTPARSER_PARAM# *, MEM_ROOTcxx . . $ MEM_ROOT# *); |
| 129 | FT_WORDcxx . . $ FT_WORD# * ft_linearizecxx . . $ ft_linearize(4a2873bf0799feca).(TREEcxx . . $ TREE# *, MEM_ROOTcxx . . $ MEM_ROOT# *); |
| 130 | FT_WORDcxx . . $ FT_WORD# * _mi_ft_parserecordcxx . . $ _mi_ft_parserecord(ea4b8b862eed1683).(MI_INFOcxx . . $ MI_INFO# *, uintcxx . . $ uint#, const ucharcxx . . $ uchar# *, MEM_ROOTcxx . . $ MEM_ROOT# *); |
| 131 | uintcxx . . $ uint# _mi_ft_parsecxx . . $ _mi_ft_parse(4f7e739e222d0862).(TREEcxx . . $ TREE# *, MI_INFOcxx . . $ MI_INFO# *, uintcxx . . $ uint#, const ucharcxx . . $ uchar# *, |
| 132 | MYSQL_FTPARSER_PARAMcxx . . $ MYSQL_FTPARSER_PARAM# *, MEM_ROOTcxx . . $ MEM_ROOT# *); |
| 133 | |
| 134 | FT_INFOcxx . . $ FT_INFO# *ft_init_nlq_searchcxx . . $ ft_init_nlq_search(98509ab4e1ab9d01).(MI_INFOcxx . . $ MI_INFO# *, uintcxx . . $ uint#, ucharcxx . . $ uchar# *, uintcxx . . $ uint#, uintcxx . . $ uint#, ucharcxx . . $ uchar# *); |
| 135 | FT_INFOcxx . . $ FT_INFO# *ft_init_boolean_searchcxx . . $ ft_init_boolean_search(246e44a8d168255a).(MI_INFOcxx . . $ MI_INFO# *, uintcxx . . $ uint#, ucharcxx . . $ uchar# *, uintcxx . . $ uint#, CHARSET_INFOcxx . . $ CHARSET_INFO# *); |
| 136 | |
| 137 | extern const struct _ft_vftcxx . . $ _ft_vft# _ft_vft_nlqcxx . . $ _ft_vft_nlq.; |
| 138 | int ft_nlq_read_nextcxx . . $ ft_nlq_read_next(87e99b18837fe387).(FT_INFOcxx . . $ FT_INFO# *, char *); |
| 139 | float ft_nlq_find_relevancecxx . . $ ft_nlq_find_relevance(7449771d60404249).(FT_INFOcxx . . $ FT_INFO# *, ucharcxx . . $ uchar# *, uintcxx . . $ uint#); |
| 140 | void ft_nlq_close_searchcxx . . $ ft_nlq_close_search(bb1b7940d4ba8068).(FT_INFOcxx . . $ FT_INFO# *); |
| 141 | float ft_nlq_get_relevancecxx . . $ ft_nlq_get_relevance(ca36cf81b4b9c870).(FT_INFOcxx . . $ FT_INFO# *); |
| 142 | my_off_tcxx . . $ my_off_t# ft_nlq_get_docidcxx . . $ ft_nlq_get_docid(b1fb8a25939bfcf9).(FT_INFOcxx . . $ FT_INFO# *); |
| 143 | void ft_nlq_reinit_searchcxx . . $ ft_nlq_reinit_search(bb1b7940d4ba8068).(FT_INFOcxx . . $ FT_INFO# *); |
| 144 | |
| 145 | extern const struct _ft_vftcxx . . $ _ft_vft# _ft_vft_booleancxx . . $ _ft_vft_boolean.; |
| 146 | int ft_boolean_read_nextcxx . . $ ft_boolean_read_next(87e99b18837fe387).(FT_INFOcxx . . $ FT_INFO# *, char *); |
| 147 | float ft_boolean_find_relevancecxx . . $ ft_boolean_find_relevance(7449771d60404249).(FT_INFOcxx . . $ FT_INFO# *, ucharcxx . . $ uchar# *, uintcxx . . $ uint#); |
| 148 | void ft_boolean_close_searchcxx . . $ ft_boolean_close_search(bb1b7940d4ba8068).(FT_INFOcxx . . $ FT_INFO# *); |
| 149 | float ft_boolean_get_relevancecxx . . $ ft_boolean_get_relevance(ca36cf81b4b9c870).(FT_INFOcxx . . $ FT_INFO# *); |
| 150 | my_off_tcxx . . $ my_off_t# ft_boolean_get_docidcxx . . $ ft_boolean_get_docid(b1fb8a25939bfcf9).(FT_INFOcxx . . $ FT_INFO# *); |
| 151 | void ft_boolean_reinit_searchcxx . . $ ft_boolean_reinit_search(bb1b7940d4ba8068).(FT_INFOcxx . . $ FT_INFO# *); |
| 152 | MYSQL_FTPARSER_PARAMcxx . . $ MYSQL_FTPARSER_PARAM#* ftparser_alloc_paramcxx . . $ ftparser_alloc_param(d7d0e4599ed5a875).(MI_INFOcxx . . $ MI_INFO# *info); |
| 153 | extern MYSQL_FTPARSER_PARAMcxx . . $ MYSQL_FTPARSER_PARAM# *ftparser_call_initializercxx . . $ ftparser_call_initializer(430cba5e45eab294).(MI_INFOcxx . . $ MI_INFO# *info, |
| 154 | uintcxx . . $ uint# keynr, |
| 155 | uintcxx . . $ uint# paramnr); |
| 156 | extern void ftparser_call_deinitializercxx . . $ ftparser_call_deinitializer(250303d75f5c3b2f).(MI_INFOcxx . . $ MI_INFO# *info); |