diff options
author | unknown <serg@serg.mysql.com> | 2001-10-09 14:53:54 +0200 |
---|---|---|
committer | unknown <serg@serg.mysql.com> | 2001-10-09 14:53:54 +0200 |
commit | 736e5b0de2281ab75af2cf3d88480aa6db9a18d2 (patch) | |
tree | c39107b036ff091f557b03a1f37183735dcddbad /myisam/ft_nlq_search.c | |
parent | 734e2a8bcaa4a5d2de6059f4cdcac8e71bbb5d6d (diff) | |
download | mariadb-git-736e5b0de2281ab75af2cf3d88480aa6db9a18d2.tar.gz |
Boolean search passes _some_ tests
sql/ha_myisam.cc:
One more abstraction layer added (C++ emulated in C :).
include/ft_global.h:
boolean search code plugged in
mysql-test/r/fulltext_cache.result:
boolean search code plugged in
mysql-test/r/fulltext_left_join.result:
boolean search code plugged in
mysql-test/r/fulltext_multi.result:
boolean search code plugged in
mysql-test/r/fulltext_order_by.result:
boolean search code plugged in
sql/lex.h:
IN BOOLEAN MODE syntax
myisam/ft_nlq_search.c:
boolean search code plugged in
myisam/ftdefs.h:
boolean search code plugged in
sql/ha_myisam.h:
boolean search code plugged in
sql/handler.h:
boolean search code plugged in
include/my_base.h:
do_not_sort_keyseg feature for MyISAM
include/my_global.h:
#define comp(a,b) (((a) < (b)) ? -1 : ((a) > (b)) ? 1 : 0)
myisam/ft_boolean_search.c:
bugfixing
myisam/ft_parser.c:
cleanup
myisam/ft_static.c:
do_not_sort_keyseg feature for MyISAM
myisam/mi_search.c:
do_not_sort_keyseg feature for MyISAM
myisam/mi_write.c:
cleanup
mysql-test/t/fulltext.test:
boolean search tests added
BitKeeper/etc/ignore:
Added myisam/FT1.MYD myisam/FT1.MYI to the ignore list
sql/item_func.cc:
boolean search
sql/item_func.h:
boolean search
sql/sql_yacc.yy:
boolean search
Diffstat (limited to 'myisam/ft_nlq_search.c')
-rw-r--r-- | myisam/ft_nlq_search.c | 85 |
1 files changed, 70 insertions, 15 deletions
diff --git a/myisam/ft_nlq_search.c b/myisam/ft_nlq_search.c index be11c5a9c4c..f0f878a7f16 100644 --- a/myisam/ft_nlq_search.c +++ b/myisam/ft_nlq_search.c @@ -16,10 +16,24 @@ /* Written by Sergei A. Golubchik, who has a shared copyright to this code */ +#define FT_CORE #include "ftdefs.h" /* search with natural language queries */ +typedef struct ft_doc_rec { + my_off_t dpos; + double weight; +} FT_DOC; + +struct st_ft_info { + struct _ft_vft *please; + MI_INFO *info; + int ndocs; + int curdoc; + FT_DOC doc[1]; +}; + typedef struct st_all_in_one { MI_INFO *info; uint keynr; @@ -152,27 +166,27 @@ 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) +FT_INFO *ft_init_nlq_search(MI_INFO *info, uint keynr, byte *query, + uint query_len, my_bool presort) { TREE *wtree, allocated_wtree; ALL_IN_ONE aio; FT_DOC *dptr; - FT_DOCLIST *dlist=NULL; - my_off_t saved_lastpos=((MI_INFO *)info)->lastpos; + FT_INFO *dlist=NULL; + my_off_t saved_lastpos=info->lastpos; /* black magic ON */ - if ((int) (keynr = _mi_check_index((MI_INFO *)info,keynr)) < 0) + if ((int) (keynr = _mi_check_index(info,keynr)) < 0) return NULL; - if (_mi_readinfo((MI_INFO *)info,F_RDLCK,1)) + if (_mi_readinfo(info,F_RDLCK,1)) return NULL; /* black magic OFF */ - aio.info=(MI_INFO *)info; + aio.info=info; aio.keynr=keynr; - aio.keybuff=aio.info->lastkey+aio.info->s->base.max_key_length; - aio.keyinfo=aio.info->s->keyinfo+keynr; - aio.key_root=aio.info->s->state.key_root[keynr]; + aio.keybuff=info->lastkey+info->s->base.max_key_length; + aio.keyinfo=info->s->keyinfo+keynr; + aio.key_root=info->s->state.key_root[keynr]; bzero(&allocated_wtree,sizeof(allocated_wtree)); @@ -186,18 +200,19 @@ FT_DOCLIST *ft_nlq_init_search(void *info, uint keynr, byte *query, left_root_right)) goto err2; - dlist=(FT_DOCLIST *)my_malloc(sizeof(FT_DOCLIST)+ + dlist=(FT_INFO *)my_malloc(sizeof(FT_INFO)+ sizeof(FT_DOC)*(aio.dtree.elements_in_tree-1),MYF(0)); if(!dlist) goto err2; + dlist->please=& _ft_vft_nlq; 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); if(presort) qsort(dlist->doc, dlist->ndocs, sizeof(FT_DOC), (qsort_cmp)&FT_DOC_cmp); @@ -207,11 +222,11 @@ err2: delete_tree(&aio.dtree); err: - ((MI_INFO *)info)->lastpos=saved_lastpos; + info->lastpos=saved_lastpos; return dlist; } -int ft_nlq_read_next(FT_DOCLIST *handler, char *record) +int ft_nlq_read_next(FT_INFO *handler, char *record) { MI_INFO *info= (MI_INFO *) handler->info; @@ -232,3 +247,43 @@ int ft_nlq_read_next(FT_DOCLIST *handler, char *record) return my_errno; } +float ft_nlq_find_relevance(FT_INFO *handler, my_off_t docid) +{ + int a,b,c; + FT_DOC *docs=handler->doc; + + // Assuming docs[] is sorted by dpos... + + for (a=0, b=handler->ndocs, c=(a+b)/2; b-a>1; c=(a+b)/2) + { + if (docs[c].dpos > docid) + b=c; + else + a=c; + } + if (docs[a].dpos == docid) + return docs[a].weight; + else + return 0.0; +} + +void ft_nlq_close_search(FT_INFO *handler) +{ + my_free((gptr)handler,MYF(0)); +} + +float ft_nlq_get_relevance(FT_INFO *handler) +{ + return handler->doc[handler->curdoc].weight; +} + +my_off_t ft_nlq_get_docid(FT_INFO *handler) +{ + return handler->doc[handler->curdoc].dpos; +} + +void ft_nlq_reinit_search(FT_INFO *handler) +{ + handler->curdoc=-1; +} + |