Databases Reference
In-Depth Information
Being armed with the get_word() function we can now write the main
parsing function:
static int andor_parse(MYSQL_FTPARSER_PARAM *param)
{
char *end = param->doc + param->length;
char *s = param->doc;
WORD word, next;
MYSQL_FTPARSER_BOOLEAN_INFO bool_info =
{ FT_TOKEN_WORD, 0, 0, 0, 0, 0, 0 };
First, we read the "next" word. Then we start the loop:
s = get_word(&next, s, end);
for (;;)
{
We never need to read the current word as it is already read, in advance, as next .
We simply copy the next word into the current one, and read the new next word.
Remember, we can safely call get_word() as many times as we want, even if the s
pointer has already reached the end of the text:
word = next;
s = get_word(&next, s, end);
If there is no current word, it means that we have parsed everything and can return:
if (word.start >= end)
return 0;
Otherwise, we go into the details of extracting and interpreting our Boolean
operators, of course, if the parsing mode requires it:
if (param->mode == MYSQL_FTPARSER_FULL_BOOLEAN_INFO)
{
First we check if the next word is AND . If it is, and the current (before the next) word
has yesno==0 , which means there was no AND before the current word, we tell
MySQL to start a subexpression. Then we read the next word:
if (next.start < end &&
strncasecmp(next.start, "and", next.len) == 0)
{
if (word.yesno == 0)
{
bool_info.yesno = 0;
bool_info.type = FT_TOKEN_LEFT_PAREN;
param->mysql_add_word(param, 0, 0, &bool_info);
word.yesno = 1;
}
s = get_word(&next, s, end);
 
Search WWH ::




Custom Search