Prioritize keywords found in title in sql search

1

Hello, I have a 'videos' table with 3 fields 'name', 'description' and 'categories'. When doing a search I want to appear at the top videos that in the 'name' have more of these keywords, for example if I search "beautiful house" a video with name 'CASA in Alagoas BONITA' has to stay more on top than a video with name "sao paulo CASA" and description "look how beautiful it is" (because I do the research looking for the key words in name and description).

Does anyone have an idea how to do this?

    
asked by anonymous 09.12.2017 / 16:43

1 answer

0

This subject may be much more complex than it appears to be. The relevant search, so to speak.

But, answering your question more directly, I would suggest using the UNION clause.

SELECT * (<condicoes com alta prioridade>)
UNION
SELECT * (<condicoes com um pouco menos de prioridades>)
UNION
SELECT * (<condicoes com menos de prioridades ainda>)

Or, another suggestion is to use a ranking variable

  

SELECT t. *, [ranking expression] AS ranking FROM () AS t ORDER BY   ranking DESC

    
09.12.2017 / 16:53