aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2020-06-05 11:08:25 +0300
committerGravatar Vitaly Takmazov2020-06-05 11:08:25 +0300
commitdde18e12688a47f81cb7c4336901008158a3637e (patch)
treeea89b04f5eeea10b525c0b80d13a598c37358750 /src
parent1afd00943ee58f911fa27eb5b181f0ee3a22e605 (diff)
boost keyword weight on search
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/service/SphinxSearchService.java7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/main/java/com/juick/service/SphinxSearchService.java b/src/main/java/com/juick/service/SphinxSearchService.java
index dd06c485..1553e22f 100644
--- a/src/main/java/com/juick/service/SphinxSearchService.java
+++ b/src/main/java/com/juick/service/SphinxSearchService.java
@@ -44,8 +44,11 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic
UserService userService;
public String sortHint(String searchString) {
+ return "extended:@weight desc, @id desc";
+ }
+ public String keywordBoost(String searchString) {
boolean isOneWord = searchString.split("[^\\S\\+]+").length == 1;
- return isOneWord ? "extended:@id desc" : "extended:@weight desc, @id desc";
+ return isOneWord ? String.format("%s^3", searchString) : searchString;
}
@Override
@@ -64,7 +67,7 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic
}
return getJdbcTemplate().queryForList(
- String.format("SELECT id FROM search WHERE query = '%s;%s'", searchString,
+ String.format("SELECT id FROM search WHERE query = '%s;%s'", keywordBoost(searchString),
sphinxQuery.entrySet().stream().map(Object::toString)
.collect(Collectors.joining(";"))), Integer.class);
}