Commit 57e4c8ef authored by serg@serg.mysql.com's avatar serg@serg.mysql.com

Initial checkin of the new boolean fulltext search code

parent c18a94f3
...@@ -53,8 +53,8 @@ void ft_free_stopwords(void); ...@@ -53,8 +53,8 @@ void ft_free_stopwords(void);
FT_DOCLIST * ft_init_search(void *, uint, byte *, uint, my_bool); FT_DOCLIST * ft_init_search(void *, uint, byte *, uint, my_bool);
int ft_read_next(FT_DOCLIST *, char *); int ft_read_next(FT_DOCLIST *, char *);
#define ft_close_search(handler) my_free(((gptr)(handler)),MYF(0)) #define ft_close_search(handler) my_free(((gptr)(handler)),MYF(0))
#define ft_get_relevance(handler) ((handler)->doc[(handler)->curdoc].weight) #define ft_get_relevance(handler) (((FT_DOCLIST *)(handler))->doc[((FT_DOCLIST *)(handler))->curdoc].weight)
#define ft_get_docid(handler) ((handler)->doc[(handler)->curdoc].dpos) #define ft_get_docid(handler) (((FT_DOCLIST *)(handler))->doc[((FT_DOCLIST *)(handler))->curdoc].dpos)
#define ft_reinit_search(handler) (((FT_DOCLIST *)(handler))->curdoc=-1) #define ft_reinit_search(handler) (((FT_DOCLIST *)(handler))->curdoc=-1)
#ifdef __cplusplus #ifdef __cplusplus
......
This diff is collapsed.
...@@ -38,9 +38,9 @@ FT_DOCLIST *ft_init_search(void *info, uint keynr, byte *query, ...@@ -38,9 +38,9 @@ FT_DOCLIST *ft_init_search(void *info, uint keynr, byte *query,
return NULL; return NULL;
/* black magic OFF */ /* black magic OFF */
if (is_boolean(query, query_len)) // if (is_boolean(query, query_len))
dlist=ft_boolean_search(info,keynr,query,query_len); // dlist=ft_boolean_search(info,keynr,query,query_len);
else // else
dlist=ft_nlq_search(info,keynr,query,query_len); dlist=ft_nlq_search(info,keynr,query,query_len);
if(dlist && presort) if(dlist && presort)
...@@ -72,3 +72,4 @@ int ft_read_next(FT_DOCLIST *handler, char *record) ...@@ -72,3 +72,4 @@ int ft_read_next(FT_DOCLIST *handler, char *record)
} }
return my_errno; return my_errno;
} }
...@@ -1903,7 +1903,7 @@ longlong Item_func_inet_aton::val_int() ...@@ -1903,7 +1903,7 @@ longlong Item_func_inet_aton::val_int()
return 0; return 0;
} }
double Item_func_match::val() double Item_func_match_nl::val()
{ {
if (ft_handler==NULL) if (ft_handler==NULL)
init_search(1); init_search(1);
...@@ -1922,7 +1922,7 @@ double Item_func_match::val() ...@@ -1922,7 +1922,7 @@ double Item_func_match::val()
/* we'll have to find ft_relevance manually in ft_handler array */ /* we'll have to find ft_relevance manually in ft_handler array */
int a,b,c; int a,b,c;
FT_DOC *docs=ft_handler->doc; FT_DOC *docs=((FT_DOCLIST *)ft_handler)->doc;
my_off_t docid=table->file->row_position(); my_off_t docid=table->file->row_position();
if ((null_value=(docid==HA_OFFSET_ERROR))) if ((null_value=(docid==HA_OFFSET_ERROR)))
...@@ -1930,7 +1930,7 @@ double Item_func_match::val() ...@@ -1930,7 +1930,7 @@ double Item_func_match::val()
// Assuming docs[] is sorted by dpos... // Assuming docs[] is sorted by dpos...
for (a=0, b=ft_handler->ndocs, c=(a+b)/2; b-a>1; c=(a+b)/2) for (a=0, b=((FT_DOCLIST *)ft_handler)->ndocs, c=(a+b)/2; b-a>1; c=(a+b)/2)
{ {
if (docs[c].dpos > docid) if (docs[c].dpos > docid)
b=c; b=c;
...@@ -1941,7 +1941,6 @@ double Item_func_match::val() ...@@ -1941,7 +1941,6 @@ double Item_func_match::val()
return docs[a].weight; return docs[a].weight;
else else
return 0.0; return 0.0;
} }
void Item_func_match::init_search(bool no_order) void Item_func_match::init_search(bool no_order)
...@@ -1969,9 +1968,7 @@ void Item_func_match::init_search(bool no_order) ...@@ -1969,9 +1968,7 @@ void Item_func_match::init_search(bool no_order)
tmp2.set("",0); tmp2.set("",0);
} }
ft_handler=(FT_DOCLIST *) ft_handler_init(ft_tmp->ptr(), ft_tmp->length(), join_key && !no_order);
table->file->ft_init_ext(key, (byte*) ft_tmp->ptr(), ft_tmp->length(),
join_key && !no_order);
if (join_key) if (join_key)
{ {
...@@ -2024,7 +2021,6 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist) ...@@ -2024,7 +2021,6 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist)
return 0; return 0;
} }
bool Item_func_match::fix_index() bool Item_func_match::fix_index()
{ {
List_iterator_fast<Item> li(fields); List_iterator_fast<Item> li(fields);
......
...@@ -863,30 +863,40 @@ class Item_func_match :public Item_real_func ...@@ -863,30 +863,40 @@ class Item_func_match :public Item_real_func
uint key; uint key;
bool join_key; bool join_key;
Item_func_match *master; Item_func_match *master;
FT_DOCLIST *ft_handler; void * ft_handler;
Item_func_match(List<Item> &a, Item *b): Item_real_func(b), Item_func_match(List<Item> &a, Item *b): Item_real_func(b),
fields(a), table(0), join_key(0), master(0), ft_handler(0) {} fields(a), table(0), join_key(0), master(0), ft_handler(0) {}
~Item_func_match() ~Item_func_match()
{ {
if (!master) if (!master && ft_handler)
{ {
if (ft_handler) ft_handler_close();
{
ft_close_search(ft_handler);
if(join_key) if(join_key)
table->file->ft_handler=0; table->file->ft_handler=0;
} }
} }
} virtual int ft_handler_init(const byte *key, uint keylen, bool presort)
const char *func_name() const { return "match"; } { return 1; }
virtual int ft_handler_close() { return 1; }
enum Functype functype() const { return FT_FUNC; } enum Functype functype() const { return FT_FUNC; }
void update_used_tables() {} void update_used_tables() {}
bool fix_fields(THD *thd,struct st_table_list *tlist); bool fix_fields(THD *thd,struct st_table_list *tlist);
bool eq(const Item *) const; bool eq(const Item *) const;
double val();
longlong val_int() { return val()!=0.0; } longlong val_int() { return val()!=0.0; }
bool fix_index(); bool fix_index();
void init_search(bool no_order); void init_search(bool no_order);
}; };
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"; }
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; }
};
...@@ -605,7 +605,7 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds, ...@@ -605,7 +605,7 @@ mysql_select(THD *thd,TABLE_LIST *tables,List<Item> &fields,COND *conds,
List_iterator_fast<Item_func_match> li(ftfuncs); List_iterator_fast<Item_func_match> li(ftfuncs);
Item_func_match *ifm; Item_func_match *ifm;
DBUG_PRINT("info",("Performing FULLTEXT search")); DBUG_PRINT("info",("Performing FULLTEXT search"));
thd->proc_info="FULLTEXT searching"; thd->proc_info="FULLTEXT search init";
while ((ifm=li++)) while ((ifm=li++))
{ {
...@@ -1455,13 +1455,13 @@ add_ft_keys(DYNAMIC_ARRAY *keyuse_array, ...@@ -1455,13 +1455,13 @@ add_ft_keys(DYNAMIC_ARRAY *keyuse_array,
functype == Item_func::GT_FUNC) && functype == Item_func::GT_FUNC) &&
arg0->type() == Item::FUNC_ITEM && arg0->type() == Item::FUNC_ITEM &&
arg0->functype() == Item_func::FT_FUNC && arg0->functype() == Item_func::FT_FUNC &&
arg1->const_item() && arg1->val()>=0) arg1->const_item() && arg1->val()>0)
cond_func=(Item_func_match *) arg0; cond_func=(Item_func_match *) arg0;
else if ((functype == Item_func::LE_FUNC || else if ((functype == Item_func::LE_FUNC ||
functype == Item_func::LT_FUNC) && functype == Item_func::LT_FUNC) &&
arg1->type() == Item::FUNC_ITEM && arg1->type() == Item::FUNC_ITEM &&
arg1->functype() == Item_func::FT_FUNC && arg1->functype() == Item_func::FT_FUNC &&
arg0->const_item() && arg0->val()>=0) arg0->const_item() && arg0->val()>0)
cond_func=(Item_func_match *) arg1; cond_func=(Item_func_match *) arg1;
} }
} }
...@@ -1473,7 +1473,7 @@ add_ft_keys(DYNAMIC_ARRAY *keyuse_array, ...@@ -1473,7 +1473,7 @@ add_ft_keys(DYNAMIC_ARRAY *keyuse_array,
{ {
Item *item; Item *item;
/* /*
I', (Sergei) too lazy to implement proper recursive descent here, I, (Sergei) too lazy to implement proper recursive descent here,
and anyway, nobody will use such a stupid queries and anyway, nobody will use such a stupid queries
that will require it :-) that will require it :-)
May be later... May be later...
......
...@@ -1549,10 +1549,10 @@ simple_expr: ...@@ -1549,10 +1549,10 @@ simple_expr:
| '{' ident expr '}' { $$= $3; } | '{' ident expr '}' { $$= $3; }
| MATCH '(' ident_list ')' AGAINST '(' expr ')' | MATCH '(' ident_list ')' AGAINST '(' expr ')'
{ Select->ftfunc_list.push_back( { Select->ftfunc_list.push_back(
(Item_func_match *)($$=new Item_func_match(*$3,$7))); } (Item_func_match *)($$=new Item_func_match_nl(*$3,$7))); }
| MATCH ident_list AGAINST '(' expr ')' | MATCH ident_list AGAINST '(' expr ')'
{ Select->ftfunc_list.push_back( { Select->ftfunc_list.push_back(
(Item_func_match *)($$=new Item_func_match(*$2,$5))); } (Item_func_match *)($$=new Item_func_match_nl(*$2,$5))); }
| BINARY expr %prec NEG { $$= new Item_func_binary($2); } | BINARY expr %prec NEG { $$= new Item_func_binary($2); }
| CASE_SYM opt_expr WHEN_SYM when_list opt_else END | CASE_SYM opt_expr WHEN_SYM when_list opt_else END
{ $$= new Item_func_case(* $4, $2, $5 ) } { $$= new Item_func_case(* $4, $2, $5 ) }
......
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