How to weight in full-text search?

How to give more weight for title than other fields in Mysql Full Text Search Index

  • I am implementing mysql full text search, here I am facing one issue, results displaying but not working as I expect. When I perform search for 'Samsung Galaxy S6' it is coming at second position. I need title has more weight than other fields. If search string in title found, it will come first, and one more thing when I perform only with "S6" results are strange 0 results showing, how should I do this. Please help. My http://sqlfiddle.com/#!9/f0549/14

  • Answer:

    I cannot provide an answer to the weighting of results if the search term was found in the title. I can provide the reason as to why searching for just "S6" returns 0 results, this is a MySQL limitation, where it's minimum word length is 4 characters by default, this can be changed in my.ini, look for the ft_min_word_len (and inversely ft_max_word_len). This is assuming you're using the MATCH() of course. Further reading: https://dev.mysql.com/doc/refman/5.0/en/fulltext-natural-language.html

jack brone at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

In order to apply a different weight for the fields text and title, you have to create an separate index on each column. Then you use both indices with a weight factor. select * from mytable where match(title) against 'word' or match(text) against 'word' order by 2 * match(title) against 'word' + match(text) against 'word' desc Choose an appropriate weighing factor (2 might be good).

Lorenz Meyer

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.