summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <serg@serg.mysql.com>2001-09-25 20:31:02 +0200
committerunknown <serg@serg.mysql.com>2001-09-25 20:31:02 +0200
commit734e2a8bcaa4a5d2de6059f4cdcac8e71bbb5d6d (patch)
treea70bc86b1e25c9dd79c1730e066609f2781b606d
parent51c261ff2393476110d2914bec5f8a1f057555be (diff)
downloadmariadb-git-734e2a8bcaa4a5d2de6059f4cdcac8e71bbb5d6d.tar.gz
get rid of ft_search. Now there're two sets of ft_ functions, ft_nlq_* and ft_boolean_*
BitKeeper/deleted/.del-ft_search.c~c011cb6e8041bb59: Delete: myisam/ft_search.c include/ft_global.h: ft_ --> ft_nlq_ myisam/Makefile.am: get rid of ft_search.c myisam/ft_dump.c: ft_ --> ft_nlq_ myisam/ft_eval.c: ft_ --> ft_nlq_ myisam/ft_nlq_search.c: get rid of ft_search.c myisam/ft_test1.c: ft_ --> ft_nlq_ sql/ha_myisam.cc: ft_ --> ft_nlq_ sql/ha_myisam.h: ft_ --> ft_nlq_ sql/handler.h: cleanup sql/item_func.cc: ft_ --> ft_nlq_ sql/item_func.h: ft_ --> ft_nlq_ sql/item_strfunc.h: cleanup
-rw-r--r--include/ft_global.h12
-rw-r--r--myisam/Makefile.am2
-rw-r--r--myisam/ft_dump.c4
-rw-r--r--myisam/ft_eval.c8
-rw-r--r--myisam/ft_nlq_search.c64
-rw-r--r--myisam/ft_search.c75
-rw-r--r--myisam/ft_test1.c8
-rw-r--r--sql/ha_myisam.cc2
-rw-r--r--sql/ha_myisam.h4
-rw-r--r--sql/handler.h2
-rw-r--r--sql/item_func.cc2
-rw-r--r--sql/item_func.h15
-rw-r--r--sql/item_strfunc.h6
13 files changed, 91 insertions, 113 deletions
diff --git a/include/ft_global.h b/include/ft_global.h
index aed5998f40a..b6f33ec801b 100644
--- a/include/ft_global.h
+++ b/include/ft_global.h
@@ -50,12 +50,12 @@ extern uint ft_max_word_len_for_sort;
int ft_init_stopwords(const char **);
void ft_free_stopwords(void);
-FT_DOCLIST * ft_init_search(void *, uint, byte *, uint, my_bool);
-int ft_read_next(FT_DOCLIST *, char *);
-#define ft_close_search(handler) my_free(((gptr)(handler)),MYF(0))
-#define ft_get_relevance(handler) (((FT_DOCLIST *)(handler))->doc[((FT_DOCLIST *)(handler))->curdoc].weight)
-#define ft_get_docid(handler) (((FT_DOCLIST *)(handler))->doc[((FT_DOCLIST *)(handler))->curdoc].dpos)
-#define ft_reinit_search(handler) (((FT_DOCLIST *)(handler))->curdoc=-1)
+FT_DOCLIST * ft_nlq_init_search(void *, uint, byte *, uint, my_bool);
+int ft_nlq_read_next(FT_DOCLIST *, char *);
+#define ft_nlq_close_search(handler) my_free(((gptr)(handler)),MYF(0))
+#define ft_nlq_get_relevance(handler) (((FT_DOCLIST *)(handler))->doc[((FT_DOCLIST *)(handler))->curdoc].weight)
+#define ft_nlq_get_docid(handler) (((FT_DOCLIST *)(handler))->doc[((FT_DOCLIST *)(handler))->curdoc].dpos)
+#define ft_nlq_reinit_search(handler) (((FT_DOCLIST *)(handler))->curdoc=-1)
#ifdef __cplusplus
}
diff --git a/myisam/Makefile.am b/myisam/Makefile.am
index 6781116043f..d86462e9b84 100644
--- a/myisam/Makefile.am
+++ b/myisam/Makefile.am
@@ -45,7 +45,7 @@ libmyisam_a_SOURCES = mi_open.c mi_extra.c mi_info.c mi_rkey.c \
mi_range.c mi_dbug.c mi_checksum.c mi_log.c \
mi_changed.c mi_static.c mi_delete_all.c \
mi_delete_table.c mi_rename.c mi_check.c \
- ft_parser.c ft_search.c ft_stopwords.c ft_static.c \
+ ft_parser.c ft_stopwords.c ft_static.c \
ft_update.c ft_boolean_search.c ft_nlq_search.c sort.c
CLEANFILES = test?.MY? FT?.MY? isam.log mi_test_all
DEFS = -DMAP_TO_USE_RAID
diff --git a/myisam/ft_dump.c b/myisam/ft_dump.c
index 42439085132..ee2c3be0710 100644
--- a/myisam/ft_dump.c
+++ b/myisam/ft_dump.c
@@ -77,7 +77,7 @@ int main(int argc,char *argv[])
ft_init_stopwords(ft_precompiled_stopwords);
- result=ft_init_search(info,inx,query,strlen(query),1);
+ result=ft_nlq_init_search(info,inx,query,strlen(query),1);
if(!result)
goto err;
@@ -87,7 +87,7 @@ int main(int argc,char *argv[])
for(i=0 ; i<result->ndocs ; i++)
printf("%9qx %20.7f\n",result->doc[i].dpos,result->doc[i].weight);
- ft_close_search(result);
+ ft_nlq_close_search(result);
}
else
{
diff --git a/myisam/ft_eval.c b/myisam/ft_eval.c
index 9466104100a..1f4b0cb4563 100644
--- a/myisam/ft_eval.c
+++ b/myisam/ft_eval.c
@@ -83,23 +83,23 @@ int main(int argc,char *argv[])
for(i=1;create_record(record,qf);i++) {
FT_DOCLIST *result; double w; int t,err;
- result=ft_init_search(file,0,blob_record,(uint) strlen(blob_record),1);
+ result=ft_nlq_init_search(file,0,blob_record,(uint) strlen(blob_record),1);
if(!result) {
printf("Query %d failed with errno %3d\n",i,my_errno);
goto err;
}
if (!silent)
printf("Query %d. Found: %d.\n",i,result->ndocs);
- for(j=0;(err=ft_read_next(result, read_record))==0;j++) {
+ for(j=0;(err=ft_nlq_read_next(result, read_record))==0;j++) {
t=uint2korr(read_record);
- w=ft_get_relevance(result);
+ w=ft_nlq_get_relevance(result);
printf("%d %.*s %f\n",i,t,read_record+2,w);
}
if(err != HA_ERR_END_OF_FILE) {
printf("ft_read_next %d failed with errno %3d\n",j,my_errno);
goto err;
}
- ft_close_search(result);
+ ft_nlq_close_search(result);
}
if (mi_close(file)) goto err;
diff --git a/myisam/ft_nlq_search.c b/myisam/ft_nlq_search.c
index 350a60708f6..be11c5a9c4c 100644
--- a/myisam/ft_nlq_search.c
+++ b/myisam/ft_nlq_search.c
@@ -147,15 +147,28 @@ static int walk_and_copy(FT_SUPERDOC *from,
return 0;
}
-FT_DOCLIST *ft_nlq_search(MI_INFO *info, uint keynr, byte *query,
- uint query_len)
+static int FT_DOC_cmp(FT_DOC *a, FT_DOC *b)
+{
+ return sgn(b->weight - a->weight);
+}
+
+FT_DOCLIST *ft_nlq_init_search(void *info, uint keynr, byte *query,
+ uint query_len, my_bool presort)
{
TREE *wtree, allocated_wtree;
- ALL_IN_ONE aio;
+ ALL_IN_ONE aio;
FT_DOC *dptr;
FT_DOCLIST *dlist=NULL;
+ my_off_t saved_lastpos=((MI_INFO *)info)->lastpos;
- aio.info=info;
+/* black magic ON */
+ if ((int) (keynr = _mi_check_index((MI_INFO *)info,keynr)) < 0)
+ return NULL;
+ if (_mi_readinfo((MI_INFO *)info,F_RDLCK,1))
+ return NULL;
+/* black magic OFF */
+
+ aio.info=(MI_INFO *)info;
aio.keynr=keynr;
aio.keybuff=aio.info->lastkey+aio.info->s->base.max_key_length;
aio.keyinfo=aio.info->s->keyinfo+keynr;
@@ -167,26 +180,55 @@ FT_DOCLIST *ft_nlq_search(MI_INFO *info, uint keynr, byte *query,
NULL, NULL);
if(!(wtree=ft_parse(&allocated_wtree,query,query_len)))
- return NULL;
+ goto err;
if(tree_walk(wtree, (tree_walk_action)&walk_and_match, &aio,
- left_root_right))
- goto err;
+ left_root_right))
+ goto err2;
- dlist=(FT_DOCLIST *)my_malloc(sizeof(FT_DOCLIST)+sizeof(FT_DOC)*(aio.dtree.elements_in_tree-1),MYF(0));
+ dlist=(FT_DOCLIST *)my_malloc(sizeof(FT_DOCLIST)+
+ sizeof(FT_DOC)*(aio.dtree.elements_in_tree-1),MYF(0));
if(!dlist)
- goto err;
+ goto err2;
dlist->ndocs=aio.dtree.elements_in_tree;
dlist->curdoc=-1;
dlist->info=aio.info;
dptr=dlist->doc;
- tree_walk(&aio.dtree, (tree_walk_action)&walk_and_copy, &dptr, left_root_right);
+ tree_walk(&aio.dtree, (tree_walk_action)&walk_and_copy, &dptr,
+ left_root_right);
-err:
+ if(presort)
+ qsort(dlist->doc, dlist->ndocs, sizeof(FT_DOC), (qsort_cmp)&FT_DOC_cmp);
+
+err2:
delete_tree(wtree);
delete_tree(&aio.dtree);
+
+err:
+ ((MI_INFO *)info)->lastpos=saved_lastpos;
return dlist;
}
+int ft_nlq_read_next(FT_DOCLIST *handler, char *record)
+{
+ MI_INFO *info= (MI_INFO *) handler->info;
+
+ if (++handler->curdoc >= handler->ndocs)
+ {
+ --handler->curdoc;
+ return HA_ERR_END_OF_FILE;
+ }
+
+ info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
+
+ info->lastpos=handler->doc[handler->curdoc].dpos;
+ if (!(*info->read_record)(info,info->lastpos,record))
+ {
+ info->update|= HA_STATE_AKTIV; /* Record is read */
+ return 0;
+ }
+ return my_errno;
+}
+
diff --git a/myisam/ft_search.c b/myisam/ft_search.c
deleted file mode 100644
index 61d169e1507..00000000000
--- a/myisam/ft_search.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-/* Written by Sergei A. Golubchik, who has a shared copyright to this code */
-
-#include "ftdefs.h"
-
-/* queries myisam and returns list of documents matched */
-
-static int FT_DOC_cmp(FT_DOC *a, FT_DOC *b)
-{
- return sgn(b->weight - a->weight);
-}
-
-FT_DOCLIST *ft_init_search(void *info, uint keynr, byte *query,
- uint query_len, my_bool presort)
-{
- FT_DOCLIST *dlist;
- my_off_t saved_lastpos=((MI_INFO *)info)->lastpos;
-
-/* black magic ON */
- if ((int) (keynr = _mi_check_index((MI_INFO *)info,keynr)) < 0)
- return NULL;
- if (_mi_readinfo((MI_INFO *)info,F_RDLCK,1))
- return NULL;
-/* black magic OFF */
-
-// if (is_boolean(query, query_len))
-// dlist=ft_boolean_search(info,keynr,query,query_len);
-// else
- dlist=ft_nlq_search(info,keynr,query,query_len);
-
- if(dlist && presort)
- {
- qsort(dlist->doc, dlist->ndocs, sizeof(FT_DOC), (qsort_cmp)&FT_DOC_cmp);
- }
-
- ((MI_INFO *)info)->lastpos=saved_lastpos;
- return dlist;
-}
-
-int ft_read_next(FT_DOCLIST *handler, char *record)
-{
- MI_INFO *info= (MI_INFO *) handler->info;
-
- if (++handler->curdoc >= handler->ndocs)
- {
- --handler->curdoc;
- return HA_ERR_END_OF_FILE;
- }
-
- info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
-
- info->lastpos=handler->doc[handler->curdoc].dpos;
- if (!(*info->read_record)(info,info->lastpos,record))
- {
- info->update|= HA_STATE_AKTIV; /* Record is read */
- return 0;
- }
- return my_errno;
-}
-
diff --git a/myisam/ft_test1.c b/myisam/ft_test1.c
index 5093b591fb2..61d9a50e9c3 100644
--- a/myisam/ft_test1.c
+++ b/myisam/ft_test1.c
@@ -137,7 +137,7 @@ static int run_test(const char *filename)
printf("- Reading rows with key\n");
for (i=0 ; i < NQUERIES ; i++)
{ FT_DOCLIST *result;
- result=ft_init_search(file,0,(char*) query[i],strlen(query[i]),1);
+ result=ft_nlq_init_search(file,0,(char*) query[i],strlen(query[i]),1);
if(!result) {
printf("Query %d: `%s' failed with errno %3d\n",i,query[i],my_errno);
continue;
@@ -145,7 +145,7 @@ static int run_test(const char *filename)
printf("Query %d: `%s'. Found: %d. Top five documents:\n",
i,query[i],result->ndocs);
for(j=0;j<5;j++) { double w; int err;
- err=ft_read_next(result, read_record);
+ err=ft_nlq_read_next(result, read_record);
if(err==HA_ERR_END_OF_FILE) {
printf("No more matches!\n");
break;
@@ -153,7 +153,7 @@ static int run_test(const char *filename)
printf("ft_read_next %d failed with errno %3d\n",j,my_errno);
break;
}
- w=ft_get_relevance(result);
+ w=ft_nlq_get_relevance(result);
if(key_field == FIELD_VARCHAR) {
uint l;
char *p;
@@ -164,7 +164,7 @@ static int run_test(const char *filename)
printf("%10.7f: %.*s\n",w,recinfo[1].length,
recinfo[0].length+read_record);
}
- ft_close_search(result);
+ ft_nlq_close_search(result);
}
if (mi_close(file)) goto err;
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc
index 812e0b77077..61452c3de3b 100644
--- a/sql/ha_myisam.cc
+++ b/sql/ha_myisam.cc
@@ -1197,7 +1197,7 @@ int ha_myisam::ft_read(byte * buf)
thread_safe_increment(ha_read_next_count,&LOCK_status); // why ?
- error=ft_read_next((FT_DOCLIST *) ft_handler,(char*) buf);
+ error=ft_nlq_read_next((FT_DOCLIST *) ft_handler,(char*) buf);
table->status=error ? STATUS_NOT_FOUND: 0;
return error;
diff --git a/sql/ha_myisam.h b/sql/ha_myisam.h
index d870331e750..a95f0ed71cb 100644
--- a/sql/ha_myisam.h
+++ b/sql/ha_myisam.h
@@ -76,9 +76,9 @@ class ha_myisam: public handler
int index_next_same(byte *buf, const byte *key, uint keylen);
int index_end() { ft_handler=NULL; return 0; }
int ft_init()
- { if(!ft_handler) return 1; ft_reinit_search(ft_handler); return 0; }
+ { if(!ft_handler) return 1; ft_nlq_reinit_search(ft_handler); return 0; }
void *ft_init_ext(uint inx,const byte *key, uint keylen, bool presort)
- { return ft_init_search(file,inx,(byte*) key,keylen,presort); }
+ { return ft_nlq_init_search(file,inx,(byte*) key,keylen,presort); }
int ft_read(byte *buf);
int rnd_init(bool scan=1);
int rnd_next(byte *buf);
diff --git a/sql/handler.h b/sql/handler.h
index 5cf39daeadf..16f7ba90eff 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -237,7 +237,7 @@ public:
virtual int update_row(const byte * old_data, byte * new_data)=0;
virtual int delete_row(const byte * buf)=0;
virtual int index_read(byte * buf, const byte * key,
- uint key_len, enum ha_rkey_function find_flag)=0;
+ uint key_len, enum ha_rkey_function find_flag)=0;
virtual int index_read_idx(byte * buf, uint index, const byte * key,
uint key_len, enum ha_rkey_function find_flag)=0;
virtual int index_next(byte * buf)=0;
diff --git a/sql/item_func.cc b/sql/item_func.cc
index ff793a4a214..076194e8b7b 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1914,7 +1914,7 @@ double Item_func_match_nl::val()
if (join_key)
{
if (table->file->ft_handler)
- return ft_get_relevance(ft_handler);
+ return ft_nlq_get_relevance(ft_handler);
join_key=0; // Magic here ! See ha_myisam::ft_read()
}
diff --git a/sql/item_func.h b/sql/item_func.h
index 293ef17b82d..19f15eaf9b3 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -893,10 +893,21 @@ class Item_func_match_nl :public Item_func_match
{
public:
Item_func_match_nl(List<Item> &a, Item *b): Item_func_match(a,b) {}
- const char *func_name() const { return "match_NL"; }
+ const char *func_name() const { return "match_nl"; }
+ double val();
+ int ft_handler_init(const byte *query, uint querylen, bool presort)
+ { ft_handler=table->file->ft_init_ext(key, query, querylen, presort); }
+ int ft_handler_close() { ft_nlq_close_search(ft_handler); ft_handler=0; }
+};
+#if 0
+class Item_func_match_bool :public Item_func_match
+{
+public:
+ Item_func_match_nl(List<Item> &a, Item *b): Item_func_match(a,b) {}
+ const char *func_name() const { return "match_bool"; }
double val();
int ft_handler_init(const byte *query, uint querylen, bool presort)
{ ft_handler=table->file->ft_init_ext(key, query, querylen, presort); }
int ft_handler_close() { ft_close_search(ft_handler); ft_handler=0; }
};
-
+#endif
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 1b829b19439..59bb815f0c3 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -1,15 +1,15 @@
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */