summaryrefslogtreecommitdiff
path: root/myisam
diff options
context:
space:
mode:
authorunknown <serg@serg.mysql.com>2003-01-23 20:36:48 +0100
committerunknown <serg@serg.mysql.com>2003-01-23 20:36:48 +0100
commit3229ddaaac84edf1706fda8cc3c35a4071aa51eb (patch)
treee1532f557f1030c80c54f9adc51c1ba3a3507139 /myisam
parente2d2c25407007df8ac2afa2511b2884cfd7d4f35 (diff)
parentfc09f13c5db5f6c8abab4817d81f6a2b0cb7666a (diff)
downloadmariadb-git-3229ddaaac84edf1706fda8cc3c35a4071aa51eb.tar.gz
Merge work:/home/bk/mysql-4.0
into serg.mysql.com:/usr/home/serg/Abk/mysql-4.0
Diffstat (limited to 'myisam')
-rw-r--r--myisam/ft_static.c1
-rw-r--r--myisam/ft_stopwords.c75
-rw-r--r--myisam/myisamchk.c2
3 files changed, 63 insertions, 15 deletions
diff --git a/myisam/ft_static.c b/myisam/ft_static.c
index e2a4fd8c0b1..7f78a11bb2f 100644
--- a/myisam/ft_static.c
+++ b/myisam/ft_static.c
@@ -67,6 +67,7 @@ FT_INFO *ft_init_search(uint mode, void *info, uint keynr,
query, query_len, presort);
}
+const char *ft_stopword_file = 0;
const char *ft_precompiled_stopwords[] = {
#ifdef COMPILE_STOPWORDS_IN
diff --git a/myisam/ft_stopwords.c b/myisam/ft_stopwords.c
index 9c2047c3b56..30a1f6e5dc8 100644
--- a/myisam/ft_stopwords.c
+++ b/myisam/ft_stopwords.c
@@ -33,27 +33,74 @@ static int FT_STOPWORD_cmp(void* cmp_arg __attribute__((unused)),
(uchar *)w2->pos,w2->len,0);
}
-int ft_init_stopwords(const char **sws)
+static void FT_STOPWORD_free(FT_STOPWORD *w, TREE_FREE action,
+ void *arg __attribute__((unused)))
{
- FT_STOPWORD sw;
+ if (action == free_free && ft_stopword_file)
+ my_free(w->pos, MYF(0));
+}
+static int ft_add_stopword(const char *w)
+{
+ FT_STOPWORD sw;
+ return !w ||
+ (((sw.len= (uint) strlen(sw.pos=w)) >= ft_min_word_len) &&
+ (tree_insert(stopwords3, &sw, 0)==NULL));
+}
- if(!stopwords3)
+int ft_init_stopwords()
+{
+ if (!stopwords3)
{
- if(!(stopwords3=(TREE *)my_malloc(sizeof(TREE),MYF(0)))) return -1;
- init_tree(stopwords3,0,0,sizeof(FT_STOPWORD),(qsort_cmp2)&FT_STOPWORD_cmp,0,
- NULL, NULL);
+ if (!(stopwords3=(TREE *)my_malloc(sizeof(TREE),MYF(0))))
+ return -1;
+ init_tree(stopwords3,0,0,sizeof(FT_STOPWORD),(qsort_cmp2)&FT_STOPWORD_cmp,
+ 0, (tree_element_free)&FT_STOPWORD_free, NULL);
}
- if(!sws) return 0;
-
- for(;*sws;sws++)
+ if (ft_stopword_file)
{
- if( (sw.len= (uint) strlen(sw.pos=*sws)) < ft_min_word_len) continue;
- if(!tree_insert(stopwords3, &sw, 0))
+ File fd;
+ my_off_t len;
+ byte *buffer, *start, *end;
+ FT_WORD w;
+ int err=-1;
+
+ if (!*ft_stopword_file)
+ return 0;
+
+ if ((fd=my_open(ft_stopword_file, O_RDONLY, MYF(MY_WME))) == -1)
+ return -1;
+ len=my_seek(fd, 0L, MY_SEEK_END, MYF(0));
+ my_seek(fd, 0L, MY_SEEK_SET, MYF(0));
+ if (!(start=buffer=my_malloc(len+1, MYF(MY_WME))))
+ {
+ my_close(fd, MYF(MY_WME));
+ return -1;
+ }
+ len=my_read(fd, buffer, len, MYF(MY_WME));
+ end=start+len;
+ while (ft_simple_get_word(&start, end, &w))
+ {
+ if (ft_add_stopword(my_strdup_with_length(w.pos, w.len, MYF(0))))
+ goto err1;
+ }
+ err=0;
+err1:
+ my_free(buffer, MYF(0));
+err0:
+ my_close(fd, MYF(MY_WME));
+ return err;
+ }
+ else
+ {
+ /* compatibility mode: to be removed */
+ char **sws=ft_precompiled_stopwords;
+
+ for (;*sws;sws++)
{
- delete_tree(stopwords3); /* purecov: inspected */
- return -1; /* purecov: inspected */
+ if (ft_add_stopword(*sws))
+ return -1;
}
}
return 0;
@@ -72,7 +119,7 @@ void ft_free_stopwords()
{
if (stopwords3)
{
- delete_tree(stopwords3); /* purecov: inspected */
+ delete_tree(stopwords3); /* purecov: inspected */
my_free((char*) stopwords3,MYF(0));
stopwords3=0;
}
diff --git a/myisam/myisamchk.c b/myisam/myisamchk.c
index 7fa91253850..f5bae72396a 100644
--- a/myisam/myisamchk.c
+++ b/myisam/myisamchk.c
@@ -860,7 +860,7 @@ static int myisamchk(MI_CHECK *param, my_string filename)
else
{
if (share->fulltext_index)
- ft_init_stopwords(ft_precompiled_stopwords); /* SerG */
+ ft_init_stopwords();
if (!(param->testflag & T_READONLY))
lock_type = F_WRLCK; /* table is changed */