Commit 734e2a8b authored by unknown's avatar unknown

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
parent 51c261ff
...@@ -50,12 +50,12 @@ extern uint ft_max_word_len_for_sort; ...@@ -50,12 +50,12 @@ extern uint ft_max_word_len_for_sort;
int ft_init_stopwords(const char **); int ft_init_stopwords(const char **);
void ft_free_stopwords(void); void ft_free_stopwords(void);
FT_DOCLIST * ft_init_search(void *, uint, byte *, uint, my_bool); FT_DOCLIST * ft_nlq_init_search(void *, uint, byte *, uint, my_bool);
int ft_read_next(FT_DOCLIST *, char *); int ft_nlq_read_next(FT_DOCLIST *, char *);
#define ft_close_search(handler) my_free(((gptr)(handler)),MYF(0)) #define ft_nlq_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_nlq_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_nlq_get_docid(handler) (((FT_DOCLIST *)(handler))->doc[((FT_DOCLIST *)(handler))->curdoc].dpos)
#define ft_reinit_search(handler) (((FT_DOCLIST *)(handler))->curdoc=-1) #define ft_nlq_reinit_search(handler) (((FT_DOCLIST *)(handler))->curdoc=-1)
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -45,7 +45,7 @@ libmyisam_a_SOURCES = mi_open.c mi_extra.c mi_info.c mi_rkey.c \ ...@@ -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_range.c mi_dbug.c mi_checksum.c mi_log.c \
mi_changed.c mi_static.c mi_delete_all.c \ mi_changed.c mi_static.c mi_delete_all.c \
mi_delete_table.c mi_rename.c mi_check.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 ft_update.c ft_boolean_search.c ft_nlq_search.c sort.c
CLEANFILES = test?.MY? FT?.MY? isam.log mi_test_all CLEANFILES = test?.MY? FT?.MY? isam.log mi_test_all
DEFS = -DMAP_TO_USE_RAID DEFS = -DMAP_TO_USE_RAID
......
...@@ -77,7 +77,7 @@ int main(int argc,char *argv[]) ...@@ -77,7 +77,7 @@ int main(int argc,char *argv[])
ft_init_stopwords(ft_precompiled_stopwords); 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) if(!result)
goto err; goto err;
...@@ -87,7 +87,7 @@ int main(int argc,char *argv[]) ...@@ -87,7 +87,7 @@ int main(int argc,char *argv[])
for(i=0 ; i<result->ndocs ; i++) for(i=0 ; i<result->ndocs ; i++)
printf("%9qx %20.7f\n",result->doc[i].dpos,result->doc[i].weight); printf("%9qx %20.7f\n",result->doc[i].dpos,result->doc[i].weight);
ft_close_search(result); ft_nlq_close_search(result);
} }
else else
{ {
......
...@@ -83,23 +83,23 @@ int main(int argc,char *argv[]) ...@@ -83,23 +83,23 @@ int main(int argc,char *argv[])
for(i=1;create_record(record,qf);i++) { for(i=1;create_record(record,qf);i++) {
FT_DOCLIST *result; double w; int t,err; 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) { if(!result) {
printf("Query %d failed with errno %3d\n",i,my_errno); printf("Query %d failed with errno %3d\n",i,my_errno);
goto err; goto err;
} }
if (!silent) if (!silent)
printf("Query %d. Found: %d.\n",i,result->ndocs); 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); 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); printf("%d %.*s %f\n",i,t,read_record+2,w);
} }
if(err != HA_ERR_END_OF_FILE) { if(err != HA_ERR_END_OF_FILE) {
printf("ft_read_next %d failed with errno %3d\n",j,my_errno); printf("ft_read_next %d failed with errno %3d\n",j,my_errno);
goto err; goto err;
} }
ft_close_search(result); ft_nlq_close_search(result);
} }
if (mi_close(file)) goto err; if (mi_close(file)) goto err;
......
...@@ -147,15 +147,28 @@ static int walk_and_copy(FT_SUPERDOC *from, ...@@ -147,15 +147,28 @@ static int walk_and_copy(FT_SUPERDOC *from,
return 0; return 0;
} }
FT_DOCLIST *ft_nlq_search(MI_INFO *info, uint keynr, byte *query, static int FT_DOC_cmp(FT_DOC *a, FT_DOC *b)
uint query_len) {
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; TREE *wtree, allocated_wtree;
ALL_IN_ONE aio; ALL_IN_ONE aio;
FT_DOC *dptr; FT_DOC *dptr;
FT_DOCLIST *dlist=NULL; 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.keynr=keynr;
aio.keybuff=aio.info->lastkey+aio.info->s->base.max_key_length; aio.keybuff=aio.info->lastkey+aio.info->s->base.max_key_length;
aio.keyinfo=aio.info->s->keyinfo+keynr; aio.keyinfo=aio.info->s->keyinfo+keynr;
...@@ -167,26 +180,55 @@ FT_DOCLIST *ft_nlq_search(MI_INFO *info, uint keynr, byte *query, ...@@ -167,26 +180,55 @@ FT_DOCLIST *ft_nlq_search(MI_INFO *info, uint keynr, byte *query,
NULL, NULL); NULL, NULL);
if(!(wtree=ft_parse(&allocated_wtree,query,query_len))) if(!(wtree=ft_parse(&allocated_wtree,query,query_len)))
return NULL; goto err;
if(tree_walk(wtree, (tree_walk_action)&walk_and_match, &aio, if(tree_walk(wtree, (tree_walk_action)&walk_and_match, &aio,
left_root_right)) left_root_right))
goto err; 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) if(!dlist)
goto err; goto err2;
dlist->ndocs=aio.dtree.elements_in_tree; dlist->ndocs=aio.dtree.elements_in_tree;
dlist->curdoc=-1; dlist->curdoc=-1;
dlist->info=aio.info; dlist->info=aio.info;
dptr=dlist->doc; 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(wtree);
delete_tree(&aio.dtree); delete_tree(&aio.dtree);
err:
((MI_INFO *)info)->lastpos=saved_lastpos;
return dlist; 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;
}
/* 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;
}
...@@ -137,7 +137,7 @@ static int run_test(const char *filename) ...@@ -137,7 +137,7 @@ static int run_test(const char *filename)
printf("- Reading rows with key\n"); printf("- Reading rows with key\n");
for (i=0 ; i < NQUERIES ; i++) for (i=0 ; i < NQUERIES ; i++)
{ FT_DOCLIST *result; { 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) { if(!result) {
printf("Query %d: `%s' failed with errno %3d\n",i,query[i],my_errno); printf("Query %d: `%s' failed with errno %3d\n",i,query[i],my_errno);
continue; continue;
...@@ -145,7 +145,7 @@ static int run_test(const char *filename) ...@@ -145,7 +145,7 @@ static int run_test(const char *filename)
printf("Query %d: `%s'. Found: %d. Top five documents:\n", printf("Query %d: `%s'. Found: %d. Top five documents:\n",
i,query[i],result->ndocs); i,query[i],result->ndocs);
for(j=0;j<5;j++) { double w; int err; 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) { if(err==HA_ERR_END_OF_FILE) {
printf("No more matches!\n"); printf("No more matches!\n");
break; break;
...@@ -153,7 +153,7 @@ static int run_test(const char *filename) ...@@ -153,7 +153,7 @@ static int run_test(const char *filename)
printf("ft_read_next %d failed with errno %3d\n",j,my_errno); printf("ft_read_next %d failed with errno %3d\n",j,my_errno);
break; break;
} }
w=ft_get_relevance(result); w=ft_nlq_get_relevance(result);
if(key_field == FIELD_VARCHAR) { if(key_field == FIELD_VARCHAR) {
uint l; uint l;
char *p; char *p;
...@@ -164,7 +164,7 @@ static int run_test(const char *filename) ...@@ -164,7 +164,7 @@ static int run_test(const char *filename)
printf("%10.7f: %.*s\n",w,recinfo[1].length, printf("%10.7f: %.*s\n",w,recinfo[1].length,
recinfo[0].length+read_record); recinfo[0].length+read_record);
} }
ft_close_search(result); ft_nlq_close_search(result);
} }
if (mi_close(file)) goto err; if (mi_close(file)) goto err;
......
...@@ -1197,7 +1197,7 @@ int ha_myisam::ft_read(byte * buf) ...@@ -1197,7 +1197,7 @@ int ha_myisam::ft_read(byte * buf)
thread_safe_increment(ha_read_next_count,&LOCK_status); // why ? 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; table->status=error ? STATUS_NOT_FOUND: 0;
return error; return error;
......
...@@ -76,9 +76,9 @@ class ha_myisam: public handler ...@@ -76,9 +76,9 @@ class ha_myisam: public handler
int index_next_same(byte *buf, const byte *key, uint keylen); int index_next_same(byte *buf, const byte *key, uint keylen);
int index_end() { ft_handler=NULL; return 0; } int index_end() { ft_handler=NULL; return 0; }
int ft_init() 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) 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 ft_read(byte *buf);
int rnd_init(bool scan=1); int rnd_init(bool scan=1);
int rnd_next(byte *buf); int rnd_next(byte *buf);
......
...@@ -237,7 +237,7 @@ class handler :public Sql_alloc ...@@ -237,7 +237,7 @@ class handler :public Sql_alloc
virtual int update_row(const byte * old_data, byte * new_data)=0; virtual int update_row(const byte * old_data, byte * new_data)=0;
virtual int delete_row(const byte * buf)=0; virtual int delete_row(const byte * buf)=0;
virtual int index_read(byte * buf, const byte * key, 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, virtual int index_read_idx(byte * buf, uint index, 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_next(byte * buf)=0; virtual int index_next(byte * buf)=0;
......
...@@ -1914,7 +1914,7 @@ double Item_func_match_nl::val() ...@@ -1914,7 +1914,7 @@ double Item_func_match_nl::val()
if (join_key) if (join_key)
{ {
if (table->file->ft_handler) 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() join_key=0; // Magic here ! See ha_myisam::ft_read()
} }
......
...@@ -893,10 +893,21 @@ class Item_func_match_nl :public Item_func_match ...@@ -893,10 +893,21 @@ class Item_func_match_nl :public Item_func_match
{ {
public: public:
Item_func_match_nl(List<Item> &a, Item *b): Item_func_match(a,b) {} 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(); double val();
int ft_handler_init(const byte *query, uint querylen, bool presort) int ft_handler_init(const byte *query, uint querylen, bool presort)
{ ft_handler=table->file->ft_init_ext(key, query, querylen, presort); } { ft_handler=table->file->ft_init_ext(key, query, querylen, presort); }
int ft_handler_close() { ft_close_search(ft_handler); ft_handler=0; } int ft_handler_close() { ft_close_search(ft_handler); ft_handler=0; }
}; };
#endif
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment