Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using MySQL full text search for my application, I have a situation where I want to set relevancy according to the priority of the phrases. For example I have 3 phrases "dark blue", "medium blue" and "light blue". Now I want relevant results following this ["dark blue">"medium blue">"light blue"] presidency I.e. records having "dark blue" will show on top after that "medium blue" and in last "light blue". I've tried my times and using different ways but it does not work.

SQL
SELECT *, MATCH (searchable) AGAINST ('+(>("dark blue" @2) <("medium blue" @2) <("light blue" @2))' IN BOOLEAN MODE) as score from `collection_data`  where  MATCH (searchable) AGAINST ('+(>("dark blue" @2) <("medium blue" @2) <("light blue" @2))' IN BOOLEAN MODE)


This gives the matched records but not the in-order I want. searchable is a text column which contains some description of a product.

What I have tried:

SQL
SELECT *, MATCH (searchable) AGAINST ('+(>("dark blue" @2) <("medium blue" @2) <("light blue" @2))' IN BOOLEAN MODE) as score from `collection_data`  where  MATCH (searchable) AGAINST ('+(>("dark blue" @2) <("medium blue" @2) <("light blue" @2))' IN BOOLEAN MODE)
Posted
Updated 23-May-22 19:55pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900