diff options
author | Vitaly Takmazov | 2020-06-05 11:20:38 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2020-06-05 11:20:38 +0300 |
commit | c571ab6ad8c215cae54c17a454ec8f84b24ba1b5 (patch) | |
tree | 1e8e857429cb3d5e8eabd626fb923bab9283b1e6 /src | |
parent | dde18e12688a47f81cb7c4336901008158a3637e (diff) |
Use best-match ranker for one word queries
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/juick/service/SphinxSearchService.java | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/main/java/com/juick/service/SphinxSearchService.java b/src/main/java/com/juick/service/SphinxSearchService.java index 1553e22f..aa62ddda 100644 --- a/src/main/java/com/juick/service/SphinxSearchService.java +++ b/src/main/java/com/juick/service/SphinxSearchService.java @@ -43,12 +43,12 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic @Inject UserService userService; - public String sortHint(String searchString) { - return "extended:@weight desc, @id desc"; + boolean isOneWord(String searchString) { + return searchString.split("[^\\S\\+]+").length == 1; } + public String keywordBoost(String searchString) { - boolean isOneWord = searchString.split("[^\\S\\+]+").length == 1; - return isOneWord ? String.format("%s^3", searchString) : searchString; + return isOneWord(searchString) ? String.format("%s^3", searchString) : searchString; } @Override @@ -59,9 +59,12 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic Map<String, String> sphinxQuery = new HashMap<>(); sphinxQuery.put("limit", String.valueOf(maxResult)); sphinxQuery.put("mode", "any"); - sphinxQuery.put("sort", sortHint(searchString)); + sphinxQuery.put("sort", "extended:@weight desc, @id desc"); String usersFilter = userService.getUserBLUsers(visitor.getUid()).stream().map(u -> String.valueOf(u.getUid())).collect(Collectors.joining(",")); sphinxQuery.put("!filter", "user_id," + usersFilter); + if (isOneWord(searchString)) { + sphinxQuery.put("ranker", "bm25"); + } if (page > 0) { sphinxQuery.put("offset", String.valueOf(page * maxResult)); } |