aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service/PostgreGINService.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-12-19 03:49:47 +0300
committerGravatar Vitaly Takmazov2022-12-19 03:49:47 +0300
commitdc9ec52a4e3763ec612a70dda50b9fe86611d943 (patch)
tree08a58359c519915521efa35c451384bf0d6b09db /src/main/java/com/juick/service/PostgreGINService.java
parent54e3741aee9cfa1b941d8ffa7cfec545bce174f6 (diff)
postgres: websearch_to_tsquery
Diffstat (limited to 'src/main/java/com/juick/service/PostgreGINService.java')
-rw-r--r--src/main/java/com/juick/service/PostgreGINService.java8
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);