Pages of JPA queries

2

I am changing the code of a query because it will return a lot of data when the database is well populated. I'm paging the query. The problem is that when they implemented it, they did the following:

You get a string, and you make all possible combinations with it, for example the phrase: "

asked by anonymous 03.02.2014 / 12:25

1 answer

1

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.

    
03.02.2014 / 13:02