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