MYSQL - Return occurrences closer to REGEXP

Asked

Viewed 134 times

1

I need to return the number of occurrences closest to REGEXP, see the example below:

SELECT * FROM tabela WHERE nome_produto REGEXP 'vestido|longo|manga|curta'

The idea is that this query returns me like this

  1. Long Dress with Short Sleeves
  2. Pearly dress with short sleeves
  3. Líndissimo Long Dress ..

But it returns something like:

  1. Beautiful dress to wear in summer
  2. Dress-up..

Anyway, it’s not ordered by the highest number of occurrences, do you have a way to do that? This is for a simple search system I need to do..

1 answer

1

This should help you achieve what you want.

SELECT * , MATCH (nome_produto) AGAINST ('vestido longo manga curta' IN BOOLEAN MODE) AS relevancia 
FROM tabela
WHERE MATCH (nome_produto) AGAINST ('vestido longo manga curta' IN BOOLEAN MODE)
ORDER BY relevancia

Browser other questions tagged

You are not signed in. Login or sign up in order to post.