Jump to content

[SOLVED] Any way to make FULLTEXT weigh columns differently?


morphboy23

Recommended Posts

I know in boolean mode, you can put  >  and  < in front of search terms to increase or decrease the weight of that term in the search result. But is there any way to weigh the term based on what column it was found in?

 

Example:

Say I have a table with FULLTEXT(keywords, title, text).  Can I have it weigh terms found in 'keywords' more than keywords found in the other two?

I don't believe you can.

 

What you can do is search the keywords column seperately and add it to or multiply it by the FULLTEXT score.

 

SELECT
title,
MATCH(title, text) AGAINST (('foo +bar' IN BOOLEAN MODE)) + 2 * (keywords LIKE '%foo%' + keywords LIKE '%bar%') AS score
FROM
table
WHERE
MATCH(title, text) AGAINST ('foo +bar' IN BOOLEAN MODE)
AND (keywords LIKE '%foo%' OR keywords LIKE '%bar%')
ORDER BY score DESC, title;

 

You could even parse the query string in PHP and add even more weight to keywords preceeded by a "+".

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.