19 #include "my_compare.h"
31 static TREE *stopwords3=NULL;
33 static int FT_STOPWORD_cmp(
void* cmp_arg __attribute__((unused)),
36 return ha_compare_text(ft_stopword_cs,
37 (uchar *)w1->pos,w1->len,
38 (uchar *)w2->pos,w2->len,0,0);
41 static void FT_STOPWORD_free(
FT_STOPWORD *w, TREE_FREE action,
42 void *arg __attribute__((unused)))
44 if (action == free_free)
45 my_free((
void*)w->pos);
48 static int ft_add_stopword(
const char *w)
52 (((sw.len= (uint) strlen(sw.pos=w)) >= ft_min_word_len) &&
53 (tree_insert(stopwords3, &sw, 0, stopwords3->custom_arg)==NULL));
56 int ft_init_stopwords()
60 if (!(stopwords3=(
TREE *)my_malloc(
sizeof(
TREE),MYF(0))))
62 init_tree(stopwords3,0,0,
sizeof(
FT_STOPWORD),(qsort_cmp2)&FT_STOPWORD_cmp,
64 (ft_stopword_file ? (tree_element_free)&FT_STOPWORD_free : 0),
72 ft_stopword_cs= default_charset_info->mbminlen == 1 ?
73 default_charset_info : &my_charset_latin1;
80 uchar *buffer, *start, *end;
84 if (!*ft_stopword_file)
87 if ((fd=my_open(ft_stopword_file, O_RDONLY, MYF(MY_WME))) == -1)
89 len=(uint)my_seek(fd, 0L, MY_SEEK_END, MYF(0));
90 my_seek(fd, 0L, MY_SEEK_SET, MYF(0));
91 if (!(start=buffer=my_malloc(len+1, MYF(MY_WME))))
93 len=my_read(fd, buffer, len, MYF(MY_WME));
95 while (ft_simple_get_word(ft_stopword_cs, &start, end, &w, TRUE))
97 if (ft_add_stopword(my_strndup((
char*) w.pos, w.len, MYF(0))))
104 my_close(fd, MYF(MY_WME));
110 char **sws=(
char **)ft_precompiled_stopwords;
114 if (ft_add_stopword(*sws))
117 ft_stopword_file=
"(built-in)";
122 int is_stopword(
char *
word, uint len)
127 return tree_search(stopwords3,&sw, stopwords3->custom_arg) != NULL;
131 void ft_free_stopwords()
135 delete_tree(stopwords3);