diff options
Diffstat (limited to 'src/main/java/com/juick/service')
-rw-r--r-- | src/main/java/com/juick/service/PostgreGINService.java | 8 |
1 files changed, 4 insertions, 4 deletions
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); |