-2

I'm developing a search engine and I use the following code for my query:

SELECT * FROM books WHERE MATCH(titulo, description) AGAINST ('mark the android' IN BOOLEAN MODE)

I get many results but what i want to get them ordered by best results prior to less coherent results.

How can I accomplish this?

Thanks

Apalabrados
  • 998
  • 7
  • 19
  • 35
  • possible duplicate of [MySQL match() against() - order by relevance and column?](http://stackoverflow.com/questions/6259647/mysql-match-against-order-by-relevance-and-column) – vincent kleine Jan 18 '14 at 21:09
  • Well, I get results with books that contains single words but i would like to get first records matching as many words as possible first. No matter if it is in any column – Apalabrados Jan 18 '14 at 21:12

1 Answers1

0

What you want to do is drop the IN BOOLEAN MODE and order by that MATCH ... AGAINST ... since it returns a number that represents relevancy.

SELECT * FROM books 
WHERE MATCH(titulo, description) AGAINST ('mark the android')
ORDER BY MATCH(titulo, description) AGAINST ('mark the android') DESC

if you want to see the numbers to have a feel of what the numbers are you can simply select it too like this

SELECT *,MATCH(titulo, description) AGAINST ('mark the android') as relevancy FROM books 
WHERE MATCH(titulo, description) AGAINST ('mark the android')
ORDER BY MATCH(titulo, description) AGAINST ('mark the android') DESC
Tin Tran
  • 5,995
  • 2
  • 15
  • 32