SELECT * FROM mytable WHERE MATCH(title,content)
AGAINST('+search* ~term' IN BOOLEAN MODE) ORDER BY relevance DESC;
Have a look at this for more information.
buddylee17
Practically a Master Poster
697 posts since Nov 2007
Reputation Points: 232
Solved Threads: 137
SELECT * FROM mytable WHERE MATCH(title,content)
AGAINST('+search* ~term' IN BOOLEAN MODE) ORDER BY relevance DESC;
No you, the person writing the query, are telling MySQL to return the results in order of relevance. The +sign means that all words must contain the word search. The * is a wildcard meaning that searched, searching, and searchable will be returned. If the record also contains the word term it will be returned and will be considered less relevant than those which dont contain it, due to the ~ operator. If you want the word term to increase the relevancy, dont use the ~.
MySQL uses your query as a kind of voting system. How you arrange your query and which operators you use, determines which row gets the most number of votes. The row with the most votes gets returned first.
buddylee17
Practically a Master Poster
697 posts since Nov 2007
Reputation Points: 232
Solved Threads: 137
the relevance? It looks as though the query generates it.
scru
Posting Virtuoso
1,629 posts since Feb 2007
Reputation Points: 975
Solved Threads: 140
I found another way to do this.
The table name is Employees . The field name is Role. The query finds all rows in Role that contain an A and the word Sales and returns them in order of relevancy.
SELECT *, MATCH(Role)
AGAINST('+A* *Sales' IN BOOLEAN MODE)AS relevance FROM Employees ORDER BY relevance DESC;
Hopefully you can manipulate this code and get it to work for you.
buddylee17
Practically a Master Poster
697 posts since Nov 2007
Reputation Points: 232
Solved Threads: 137