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?

Link to comment
Share on other sites

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 "+".

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.