MYSQL - Return occurrences closer to REGEXP

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

  • Long sleeves with short sleeves
  • Pearly dress with short sleeves
  • Dress Long lenght ..
  • But it returns something like:

  • Beautiful summer dress
  • Dress any thing ..
  • Anyway, it's not ordered by the largest number of occurrences, can you do that? This is for a simple search engine I need to do ..

        
    asked by anonymous 28.04.2015 / 00:36

    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
    
        
    28.04.2015 / 10:46