From dc9ec52a4e3763ec612a70dda50b9fe86611d943 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 19 Dec 2022 03:49:47 +0300 Subject: postgres: websearch_to_tsquery --- src/main/java/com/juick/service/PostgreGINService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/juick') diff --git a/src/main/java/com/juick/service/PostgreGINService.java b/src/main/java/com/juick/service/PostgreGINService.java index 583836a7..d02e79a7 100644 --- a/src/main/java/com/juick/service/PostgreGINService.java +++ b/src/main/java/com/juick/service/PostgreGINService.java @@ -60,7 +60,7 @@ public class PostgreGINService extends BaseJdbcService implements SearchService public String sortHint(String escapedSearchString) { boolean isOneWord = escapedSearchString.split("[^\\S\\+]+").length == 1; - return isOneWord ? " message_id desc" : String.format(" ts_rank(to_tsvector('russian', txt), plainto_tsquery('russian', '%s')) DESC, message_id desc", escapedSearchString); + return isOneWord ? " message_id desc" : String.format(" ts_rank(to_tsvector('russian', txt), websearch_to_tsquery('russian', '%s')) DESC, message_id desc", escapedSearchString); } @Override @@ -70,8 +70,8 @@ public class PostgreGINService extends BaseJdbcService implements SearchService String usersFilter = userService.getUserBLUsers(visitor.getUid()).stream().map(u -> String.valueOf(u.getUid())).collect(Collectors.joining(",")); var filter = usersFilter.isBlank() ? - "to_tsvector('russian', txt) @@ plainto_tsquery('russian', '" + escapeQuery(searchString) + "')" - : "to_tsvector('russian', txt) @@ plainto_tsquery('russian', '" + escapeQuery(searchString) + "') AND messages.user_id not in (" + usersFilter + ")"; + "to_tsvector('russian', txt) @@ websearch_to_tsquery('russian', '" + escapeQuery(searchString) + "')" + : "to_tsvector('russian', txt) @@ websearch_to_tsquery('russian', '" + escapeQuery(searchString) + "') AND messages.user_id not in (" + usersFilter + ")"; var offset = page * maxResult; var sql = String.format(""" SELECT messages.message_id FROM messages_txt inner join messages @@ -92,7 +92,7 @@ public class PostgreGINService extends BaseJdbcService implements SearchService var sql = String.format(""" SELECT messages.message_id FROM messages_txt inner join messages on messages.message_id = messages_txt.message_id - WHERE to_tsvector('russian', txt) @@ plainto_tsquery('russian', '%s') AND user_id=%d + WHERE to_tsvector('russian', txt) @@ websearch_to_tsquery('russian', '%s') AND user_id=%d ORDER BY %s LIMIT %d OFFSET %d """, escapeQuery(searchString), userId, sortHint(escapeQuery(searchString)), maxResult, offset); -- cgit v1.2.3