Jump to content

Order by Relevance


eagles396

Recommended Posts

I was wondering if anyone knows how to order a mysql search result by relevance?

 

For example I have a database that contains a list of over 1000 retailers and if someone was to search for 'sky' I would like sky to appear before skype, kaspersky on the results page.

 

Another example would be if someone searched for 'Play' then I would like Play to appear before Gameplay, Powerplay Direct etc

 

Any help would be appreciated

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/196670-order-by-relevance/
Share on other sites

I've just tried the following sql and it appears to work apart from displaying gameplay in the results. I think that is because there is no space between game and play. Does anyone know why that is?

 

SELECT *, ( (1.3 * (MATCH(retailer) AGAINST ('play' IN BOOLEAN MODE))) + (0.6 * (MATCH(description) AGAINST ('play' IN BOOLEAN MODE))) ) AS relevance FROM retailers WHERE ( MATCH(retailer,description) AGAINST ('play' IN BOOLEAN MODE) ) HAVING relevance > 0 ORDER BY relevance DESC

Link to comment
https://forums.phpfreaks.com/topic/196670-order-by-relevance/#findComment-1032560
Share on other sites

You are going to need to use wildcards in the AGAINST clause if you want to return words that contain the specified string such as doing the following to return records that contain "play" either as a word its self or as part of a word like "gameplay".

 

AGAINST ('*play*' IN BOOLEAN MODE)

Link to comment
https://forums.phpfreaks.com/topic/196670-order-by-relevance/#findComment-1032578
Share on other sites

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.