aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service/SphinxSearchService.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2020-06-05 12:17:52 +0300
committerGravatar Vitaly Takmazov2020-06-05 12:17:52 +0300
commit85c5c69ffb5a14258eafb4c67c550f6018b3c621 (patch)
treee7f3f6ef8680aad33ed0802ca681821cbfe69cca /src/main/java/com/juick/service/SphinxSearchService.java
parent63a52408f430cb2109943c18c37adef5c3bd8da0 (diff)
Append * to keyword search
Diffstat (limited to 'src/main/java/com/juick/service/SphinxSearchService.java')
-rw-r--r--src/main/java/com/juick/service/SphinxSearchService.java17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/main/java/com/juick/service/SphinxSearchService.java b/src/main/java/com/juick/service/SphinxSearchService.java
index dd06c485..1b80cea0 100644
--- a/src/main/java/com/juick/service/SphinxSearchService.java
+++ b/src/main/java/com/juick/service/SphinxSearchService.java
@@ -43,13 +43,19 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic
@Inject
UserService userService;
- public String sortHint(String searchString) {
+ String sortHint(String searchString) {
boolean isOneWord = searchString.split("[^\\S\\+]+").length == 1;
return isOneWord ? "extended:@id desc" : "extended:@weight desc, @id desc";
}
+ String searchTerm(String searchString, boolean exact) {
+ String prefix = exact ? "*" : "";
+ return String.format("%s%s", prefix, searchString);
+ }
+
@Override
- public List<Integer> searchInAllMessages(User visitor, final String searchString, final int page) {
+ public List<Integer> searchInAllMessages(User visitor, final String searchString, final int page,
+ final boolean exact) {
if (StringUtils.isBlank(searchString))
return Collections.emptyList();
@@ -64,13 +70,14 @@ 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'", searchTerm(searchString, exact),
sphinxQuery.entrySet().stream().map(Object::toString)
.collect(Collectors.joining(";"))), Integer.class);
}
@Override
- public List<Integer> searchByStringAndUser(User visitor, final String searchString, final int userId, int page) {
+ public List<Integer> searchByStringAndUser(User visitor, final String searchString, final int userId, int page,
+ final boolean exact) {
if (StringUtils.isBlank(searchString))
return Collections.emptyList();
@@ -82,7 +89,7 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic
sphinxQuery.put("offset", String.valueOf(page * maxResult));
}
return getJdbcTemplate().queryForList(
- String.format("SELECT id FROM search WHERE query = '%s;%s;filter=user_id,%d'", searchString,
+ String.format("SELECT id FROM search WHERE query = '%s;%s;filter=user_id,%d'", searchTerm(searchString, exact),
sphinxQuery.entrySet().stream().map(Object::toString)
.collect(Collectors.joining(";")), userId), Integer.class);
}