diff options
author | Vitaly Takmazov | 2018-08-03 14:04:18 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-08-03 14:04:18 +0300 |
commit | f0408a341bdefb9f4c17b2bfc8dff576f620d651 (patch) | |
tree | 633cbb23fe3eb365ef9d47e3f2d28c6fdbfe339f /juick-server/src/main | |
parent | 162262eb58c4642b7ffb9ed41bc760e0f009d6a6 (diff) |
search: ignore weight for one word query
Diffstat (limited to 'juick-server/src/main')
-rw-r--r-- | juick-server/src/main/java/com/juick/service/SphinxSearchService.java | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/juick-server/src/main/java/com/juick/service/SphinxSearchService.java b/juick-server/src/main/java/com/juick/service/SphinxSearchService.java index da27196f..40927bbb 100644 --- a/juick-server/src/main/java/com/juick/service/SphinxSearchService.java +++ b/juick-server/src/main/java/com/juick/service/SphinxSearchService.java @@ -38,6 +38,11 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic private int maxResult = DEFAULT_MAX_RESULT; + public String sortHint(String searchString) { + boolean isOneWord = searchString.split("[^\\S\\+]+").length == 1; + return isOneWord ? "extended:@id desc" : "extended:@weight desc, @id desc"; + } + @Override public List<Integer> searchInAllMessages(final String searchString, final int page) { if (StringUtils.isBlank(searchString)) @@ -46,7 +51,7 @@ 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", "extended:@weight desc, @id desc"); + sphinxQuery.put("sort", sortHint(searchString)); if (page > 0) { sphinxQuery.put("offset", String.valueOf(page * maxResult)); } @@ -65,7 +70,7 @@ 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", "extended:@weight desc, @id desc"); + sphinxQuery.put("sort", sortHint(searchString)); if (page > 0) { sphinxQuery.put("offset", String.valueOf(page * maxResult)); } |