diff options
author | Vitaly Takmazov | 2018-09-13 15:45:52 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-09-13 15:45:52 +0300 |
commit | 62d4f6f3fabe69b0e08195e99eedd72442bffa68 (patch) | |
tree | 65d54c9d2ffe5620d27224825fb4050abe2ea912 | |
parent | d6bd717e553be5d339cf05bca099539844ba68a5 (diff) |
hide banned from search
6 files changed, 23 insertions, 14 deletions
diff --git a/juick-common/src/main/java/com/juick/service/MessagesService.java b/juick-common/src/main/java/com/juick/service/MessagesService.java index 202e967e..77ded81e 100644 --- a/juick-common/src/main/java/com/juick/service/MessagesService.java +++ b/juick-common/src/main/java/com/juick/service/MessagesService.java @@ -86,7 +86,7 @@ public interface MessagesService { List<Integer> getPhotos(int visitorUid, int before); - List<Integer> getSearch(String search, int page); + List<Integer> getSearch(User visitor, String search, int page); List<Integer> getUserBlog(int uid, int privacy, int before); @@ -100,7 +100,7 @@ public interface MessagesService { List<Integer> getUserPhotos(int uid, int privacy, int before); - List<Integer> getUserSearch(int UID, String search, int privacy, int page); + List<Integer> getUserSearch(User visitor, int UID, String search, int privacy, int page); List<com.juick.Message> getMessages(User visitor, List<Integer> mids); diff --git a/juick-common/src/main/java/com/juick/service/SearchService.java b/juick-common/src/main/java/com/juick/service/SearchService.java index cd57eb5b..0dae5cfc 100644 --- a/juick-common/src/main/java/com/juick/service/SearchService.java +++ b/juick-common/src/main/java/com/juick/service/SearchService.java @@ -17,6 +17,8 @@ package com.juick.service; +import com.juick.User; + import java.util.List; /** @@ -25,7 +27,7 @@ import java.util.List; public interface SearchService { void setMaxResult(int maxResult); - List<Integer> searchInAllMessages(String searchString, int messageIdBefore); + List<Integer> searchInAllMessages(User visitor, String searchString, int messageIdBefore); - List<Integer> searchByStringAndUser(String searchString, final int userId, int messageIdBefore); + List<Integer> searchByStringAndUser(User visitor, String searchString, final int userId, int messageIdBefore); } diff --git a/juick-server/src/main/java/com/juick/server/api/Messages.java b/juick-server/src/main/java/com/juick/server/api/Messages.java index 672f328f..e900810f 100644 --- a/juick-server/src/main/java/com/juick/server/api/Messages.java +++ b/juick-server/src/main/java/com/juick/server/api/Messages.java @@ -115,7 +115,7 @@ public class Messages { } else if (daysback > 0) { mids = messagesService.getUserBlogAtDay(user.getUid(), 0, daysback); } else if (!StringUtils.isEmpty(search)) { - mids = messagesService.getUserSearch(user.getUid(), Utils.encodeSphinx(search), 0, page); + mids = messagesService.getUserSearch(visitor, user.getUid(), Utils.encodeSphinx(search), 0, page); } else { mids = messagesService.getUserBlog(user.getUid(), 0, before); } @@ -135,7 +135,7 @@ public class Messages { return NOT_FOUND; } } else if (!StringUtils.isEmpty(search)) { - mids = messagesService.getSearch(Utils.encodeSphinx(search), page); + mids = messagesService.getSearch(visitor, Utils.encodeSphinx(search), page); } else { mids = messagesService.getAll(visitor.getUid(), before); } diff --git a/juick-server/src/main/java/com/juick/server/www/controllers/MessagesWWW.java b/juick-server/src/main/java/com/juick/server/www/controllers/MessagesWWW.java index 5083fd5a..130e1990 100644 --- a/juick-server/src/main/java/com/juick/server/www/controllers/MessagesWWW.java +++ b/juick-server/src/main/java/com/juick/server/www/controllers/MessagesWWW.java @@ -109,7 +109,7 @@ public class MessagesWWW { if (paramSearch != null) { title = "Поиск: " + StringEscapeUtils.escapeHtml4(paramSearch); - mids = messagesService.getSearch(Utils.encodeSphinx(paramSearch), page); + mids = messagesService.getSearch(visitor, Utils.encodeSphinx(paramSearch), page); } else if (paramShow == null) { title = "Обсуждения"; mids = messagesService.getDiscussions(visitor.getUid(), paramTo); @@ -237,7 +237,7 @@ public class MessagesWWW { mids = messagesService.getUserTag(user.getUid(), paramTag.TID, privacy, before); } else if (paramSearch != null) { title = "Блог " + user.getName() + ": " + StringEscapeUtils.escapeHtml4(paramSearch); - mids = messagesService.getUserSearch(user.getUid(), Utils.encodeSphinx(paramSearch), privacy, page); + mids = messagesService.getUserSearch(visitor, user.getUid(), Utils.encodeSphinx(paramSearch), privacy, page); } else { title = "Блог " + user.getName(); mids = messagesService.getUserBlog(user.getUid(), privacy, before); diff --git a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java index 5dba41be..fbf22d59 100644 --- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -652,8 +652,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional(readOnly = true) @Override - public List<Integer> getSearch(final String search, final int page) { - return searchService.searchInAllMessages(search, page); + public List<Integer> getSearch(final User visitor, final String search, final int page) { + return searchService.searchInAllMessages(visitor, search, page); } @Transactional(readOnly = true) @@ -789,8 +789,8 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional(readOnly = true) @Override - public List<Integer> getUserSearch(final int UID, final String search, final int privacy, final int page) { - return searchService.searchByStringAndUser(search, UID, page); + public List<Integer> 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/juick-server/src/main/java/com/juick/service/SphinxSearchService.java b/juick-server/src/main/java/com/juick/service/SphinxSearchService.java index 40927bbb..cdd5e92d 100644 --- a/juick-server/src/main/java/com/juick/service/SphinxSearchService.java +++ b/juick-server/src/main/java/com/juick/service/SphinxSearchService.java @@ -17,10 +17,12 @@ package com.juick.service; +import com.juick.User; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; +import javax.inject.Inject; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -38,13 +40,16 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic private int maxResult = DEFAULT_MAX_RESULT; + @Inject + UserService userService; + 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) { + public List<Integer> searchInAllMessages(User visitor, final String searchString, final int page) { if (StringUtils.isBlank(searchString)) return Collections.emptyList(); @@ -52,6 +57,8 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic sphinxQuery.put("limit", String.valueOf(maxResult)); sphinxQuery.put("mode", "any"); sphinxQuery.put("sort", sortHint(searchString)); + String usersFilter = userService.getUserBLUsers(visitor.getUid()).stream().map(u -> String.valueOf(u.getUid())).collect(Collectors.joining(",")); + sphinxQuery.put("!filter", usersFilter); if (page > 0) { sphinxQuery.put("offset", String.valueOf(page * maxResult)); } @@ -63,7 +70,7 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic } @Override - public List<Integer> searchByStringAndUser(final String searchString, final int userId, int page) { + public List<Integer> searchByStringAndUser(User visitor, final String searchString, final int userId, int page) { if (StringUtils.isBlank(searchString)) return Collections.emptyList(); |