From b5932feefae1c371c062db09e8424f2f08f2cada Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 3 Feb 2023 23:52:54 +0300 Subject: PostgresSearchService: limit search results in code to force query use GIN --- src/main/java/com/juick/service/PostgresSearchService.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main/java/com/juick/service/PostgresSearchService.java b/src/main/java/com/juick/service/PostgresSearchService.java index 2493a45e..79986670 100644 --- a/src/main/java/com/juick/service/PostgresSearchService.java +++ b/src/main/java/com/juick/service/PostgresSearchService.java @@ -30,6 +30,7 @@ import javax.sql.DataSource; import java.sql.SQLException; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; /** * Created by aalexeev on 11/18/16. @@ -85,17 +86,13 @@ public class PostgresSearchService extends BaseJdbcService implements SearchServ """ ORDER BY """ - + (isOneWord ? "message_id DESC" : "ts_rank_cd(v, q) DESC, message_id DESC") + - """ - LIMIT :limit OFFSET :offset - """; + + (isOneWord ? "message_id DESC" : "ts_rank_cd(v, q) DESC, message_id DESC"); return getNamedParameterJdbcTemplate().queryForList(sql, new MapSqlParameterSource() .addValue("query", escapeQuery(searchString)) .addValue("user_id", userId) - .addValue("filter", usersFilter) - .addValue("limit", maxResult) - .addValue("offset", offset), Integer.class); + .addValue("filter", usersFilter), Integer.class).stream() + .skip(offset).limit(maxResult).collect(Collectors.toList()); } @Override -- cgit v1.2.3