aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src')
-rw-r--r--juick-server/src/main/java/com/juick/service/SphinxSearchService.java9
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));
}