An important question is: Is there a priority level between sentence combinations? For example: results that are exactly like the original String should come first.
If there is no prioritization of the similarity to the original phrase, for example, if the results are ordered by some other value such as a date or number, then instead of% > You could structure a query dynamic with the N
clauses to perform only one query. That way, limiting results would work without problems.
Another option that would allow you to prioritize certain combinations is to use a native query with a N
selects joined with N
.
Example:
SELECT ... FROM TABELA WHERE CAMPO LIKE '%frase 1%'
UNION
SELECT ... FROM TABELA WHERE CAMPO LIKE '%frase 2%'
UNION
SELECT ... FROM TABELA WHERE CAMPO LIKE '%frase 3%'
(...)
So we would first have the results of "sentence 1", after "sentence 2", etc.