Friday, June 17, 2005

MySQL relevance in FULLTEXT Search

While searching for a way to implement a Textsearch Engine into a clients website, a friend of mine told me about MATCH .. AGAINST().. and the relevance output.

Here the MySQL Reference Manual for it.

Good for us, all texts where in a mysql database and i added the needed index to all tables we wanted to search through. Then i programmed a php algorithm which searched all databases using the match against statement and put them all into one Array, sorted by their relevance.

Our Result Algorithm then took the Array, and prepared the text for output by cuting it and highlighting the searched word. (using css ;-)

Naturally i wanted to add a Percentage to it, but was not sure how to calculate the right one.
After searching a while in the Internet i found that source.

In Short:
a = the relevance of the current Array Value.
b = highest relevance of the search

percentage = (a / b) * 100

The first one gets 100 Percent, and then it drops in direct proportion...

1 comment:

Anonymous said...

:-)

Also, quite simply for b, since if you sort for revelance, it's the first one anyway. So the first one needs to calculation since you know it's 100% anyway, for all later ones you have it then.

I didn't mentioned that part, I knew you'ld figure it out yourself. Guess I was right :)