From ddfaa389a00fc198a35f8d505b24d9eb50ff75a5 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 20 Oct 2020 23:43:41 +0300 Subject: Revert "Append * to keyword search" This reverts commit 85c5c69ffb5a14258eafb4c67c550f6018b3c621. --- src/main/java/com/juick/service/MessagesService.java | 4 ++-- .../java/com/juick/service/MessagesServiceImpl.java | 9 ++++----- src/main/java/com/juick/service/SearchService.java | 4 ++-- .../java/com/juick/service/SphinxSearchService.java | 17 +++++------------ 4 files changed, 13 insertions(+), 21 deletions(-) (limited to 'src/main/java/com/juick/service') diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java index 43f4bd11..bb12a61e 100644 --- a/src/main/java/com/juick/service/MessagesService.java +++ b/src/main/java/com/juick/service/MessagesService.java @@ -89,7 +89,7 @@ public interface MessagesService { List getPhotos(int visitorUid, int before); - List getSearch(User visitor, String search, int page, boolean isTag); + List getSearch(User visitor, String search, int page); List getUserBlog(int uid, int privacy, int before); @@ -103,7 +103,7 @@ public interface MessagesService { List getUserPhotos(int uid, int privacy, int before); - List getUserSearch(User visitor, int UID, String search, int privacy, int page, boolean isTag); + List getUserSearch(User visitor, int UID, String search, int privacy, int page); List getMessages(User visitor, List mids); diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index 49fc4f1f..b3b51bcc 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -724,8 +724,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional(readOnly = true) @Override - public List getSearch(final User visitor, final String search, final int page, final boolean isTag) { - return searchService.searchInAllMessages(visitor, search, page, isTag); + public List getSearch(final User visitor, final String search, final int page) { + return searchService.searchInAllMessages(visitor, search, page); } @Transactional(readOnly = true) @@ -863,9 +863,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional(readOnly = true) @Override - public List getUserSearch(final User visitor, final int UID, final String search, final int privacy, - final int page, final boolean isTag) { - return searchService.searchByStringAndUser(visitor, search, UID, page, isTag); + public List getUserSearch(final User visitor, final int UID, final String search, final int privacy, final int page) { + return searchService.searchByStringAndUser(visitor, search, UID, page); } @Transactional(readOnly = true) diff --git a/src/main/java/com/juick/service/SearchService.java b/src/main/java/com/juick/service/SearchService.java index e484fd7b..377a26a4 100644 --- a/src/main/java/com/juick/service/SearchService.java +++ b/src/main/java/com/juick/service/SearchService.java @@ -27,7 +27,7 @@ import java.util.List; public interface SearchService { void setMaxResult(int maxResult); - List searchInAllMessages(User visitor, String searchString, int messageIdBefore, boolean exact); + List searchInAllMessages(User visitor, String searchString, int messageIdBefore); - List searchByStringAndUser(User visitor, String searchString, final int userId, int messageIdBefore, boolean exact); + List searchByStringAndUser(User visitor, String searchString, final int userId, int messageIdBefore); } diff --git a/src/main/java/com/juick/service/SphinxSearchService.java b/src/main/java/com/juick/service/SphinxSearchService.java index e907515d..302f10de 100644 --- a/src/main/java/com/juick/service/SphinxSearchService.java +++ b/src/main/java/com/juick/service/SphinxSearchService.java @@ -43,19 +43,13 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic @Inject UserService userService; - String sortHint(String searchString) { + public 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 searchInAllMessages(User visitor, final String searchString, final int page, - final boolean exact) { + public List searchInAllMessages(User visitor, final String searchString, final int page) { if (StringUtils.isBlank(searchString)) return Collections.emptyList(); @@ -70,14 +64,13 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic } return getJdbcTemplate().queryForList( - String.format("SELECT id FROM search WHERE query = '%s;%s'", searchTerm(searchString, exact), + String.format("SELECT id FROM search WHERE query = '%s;%s'", searchString, sphinxQuery.entrySet().stream().map(Object::toString) .collect(Collectors.joining(";"))), Integer.class); } @Override - public List searchByStringAndUser(User visitor, final String searchString, final int userId, int page, - final boolean exact) { + public List searchByStringAndUser(User visitor, final String searchString, final int userId, int page) { if (StringUtils.isBlank(searchString)) return Collections.emptyList(); @@ -89,7 +82,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'", searchTerm(searchString, exact), + String.format("SELECT id FROM search WHERE query = '%s;%s;filter=user_id,%d'", searchString, sphinxQuery.entrySet().stream().map(Object::toString) .collect(Collectors.joining(";")), userId), Integer.class); } -- cgit v1.2.3