summaryrefslogtreecommitdiff
path: root/storage/maria/ma_ft_boolean_search.c
diff options
context:
space:
mode:
authorGuilhem Bichot <guilhem@mysql.com>2009-02-12 18:51:00 +0100
committerGuilhem Bichot <guilhem@mysql.com>2009-02-12 18:51:00 +0100
commit998b4ae52d72010513035c969ff938d5d79c640c (patch)
tree88ca7a14047d5229de9b4da4b488867145c64940 /storage/maria/ma_ft_boolean_search.c
parentb90ff5340fc10a9306be1b1201612e382b8ab051 (diff)
downloadmariadb-git-998b4ae52d72010513035c969ff938d5d79c640c.tar.gz
Merge of MyISAM changes done in 5.1-main, into Maria
Diffstat (limited to 'storage/maria/ma_ft_boolean_search.c')
-rw-r--r--storage/maria/ma_ft_boolean_search.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/storage/maria/ma_ft_boolean_search.c b/storage/maria/ma_ft_boolean_search.c
index 3bcbd9edfbf..148fc8c783c 100644
--- a/storage/maria/ma_ft_boolean_search.c
+++ b/storage/maria/ma_ft_boolean_search.c
@@ -161,11 +161,11 @@ static int FTB_WORD_cmp(my_off_t *v, FTB_WORD *a, FTB_WORD *b)
static int FTB_WORD_cmp_list(CHARSET_INFO *cs, FTB_WORD **a, FTB_WORD **b)
{
- /* ORDER BY word DESC, ndepth DESC */
- int i= ha_compare_text(cs, (uchar*) (*b)->word+1,(*b)->len-1,
- (uchar*) (*a)->word+1,(*a)->len-1,0,0);
+ /* ORDER BY word, ndepth */
+ int i= ha_compare_text(cs, (uchar*) (*a)->word + 1,(*a)->len - 1,
+ (uchar*) (*b)->word + 1,(*b)->len - 1, 0, 0);
if (!i)
- i=CMP_NUM((*b)->ndepth,(*a)->ndepth);
+ i=CMP_NUM((*a)->ndepth, (*b)->ndepth);
return i;
}
@@ -879,23 +879,49 @@ static int ftb_find_relevance_add_word(MYSQL_FTPARSER_PARAM *param,
FT_INFO *ftb= ftb_param->ftb;
FTB_WORD *ftbw;
int a, b, c;
+ /*
+ Find right-most element in the array of query words matching this
+ word from a document.
+ */
for (a= 0, b= ftb->queue.elements, c= (a+b)/2; b-a>1; c= (a+b)/2)
{
ftbw= ftb->list[c];
if (ha_compare_text(ftb->charset, (uchar*)word, len,
(uchar*)ftbw->word+1, ftbw->len-1,
- (my_bool)(ftbw->flags&FTB_FLAG_TRUNC), 0) > 0)
+ (my_bool)(ftbw->flags&FTB_FLAG_TRUNC), 0) < 0)
b= c;
else
a= c;
}
+ /*
+ If there were no words with truncation operator, we iterate to the
+ beginning of an array until array element is equal to the word from
+ a document. This is done mainly because the same word may be
+ mentioned twice (or more) in the query.
+
+ In case query has words with truncation operator we must iterate
+ to the beginning of the array. There may be non-matching query words
+ between matching word with truncation operator and the right-most
+ matching element. E.g., if we're looking for 'aaa15' in an array of
+ 'aaa1* aaa14 aaa15 aaa16'.
+
+ Worse of that there still may be match even if the binary search
+ above didn't find matching element. E.g., if we're looking for
+ 'aaa15' in an array of 'aaa1* aaa14 aaa16'. The binary search will
+ stop at 'aaa16'.
+ */
for (; c >= 0; c--)
{
ftbw= ftb->list[c];
if (ha_compare_text(ftb->charset, (uchar*)word, len,
(uchar*)ftbw->word + 1,ftbw->len - 1,
(my_bool)(ftbw->flags & FTB_FLAG_TRUNC), 0))
- break;
+ {
+ if (ftb->with_scan & FTB_FLAG_TRUNC)
+ continue;
+ else
+ break;
+ }
if (ftbw->docid[1] == ftb->info->cur_row.lastpos)
continue;
ftbw->docid[1]= ftb->info->cur_row.lastpos;