diff options
author | Alexander Alexeev | 2016-11-18 01:30:39 +0700 |
---|---|---|
committer | Vitaly Takmazov | 2016-11-23 13:02:57 +0300 |
commit | 36f0ced4b46a1823a15d3e33e664891c92618b78 (patch) | |
tree | 92b3bc196701b3011049eaf58ec7c8143cf52ecc /juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java | |
parent | 149fc39c00c11b5be208914ea93a3c5bd5b7f11c (diff) |
search service for full text search implementation;
search bean configuration
Diffstat (limited to 'juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java')
-rw-r--r-- | juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java | 45 |
1 files changed, 12 insertions, 33 deletions
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 6fc71ac3..6f33bbf3 100644 --- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -4,6 +4,7 @@ import com.juick.Message; import com.juick.Tag; import com.juick.User; import com.juick.server.helpers.PrivacyOpts; +import com.juick.service.search.SearchService; import com.juick.util.MessageUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringEscapeUtils; @@ -30,13 +31,17 @@ import java.util.*; @Repository public class MessagesServiceImpl extends BaseJdbcService implements MessagesService { private final UserService userService; + private final SearchService searchService; @Inject - public MessagesServiceImpl(JdbcTemplate jdbcTemplate, UserService userService) { + public MessagesServiceImpl(JdbcTemplate jdbcTemplate, UserService userService, SearchService searchService) { super(jdbcTemplate, null); Assert.notNull(userService); this.userService = userService; + + Assert.notNull(searchService); + this.searchService = searchService; } private class MessageMapper implements RowMapper<Message> { @@ -576,26 +581,14 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional(readOnly = true) @Override - public List<Integer> getSearch(final JdbcTemplate sqlSearch, final String search, final int before) { - List<Integer> mids; - - if (before > 0) { - mids = sqlSearch.queryForList( - "SELECT id AS message_id FROM messages WHERE MATCH(?) AND id < ? ORDER BY id DESC LIMIT 25", - Integer.class, - search, before); - } else { - mids = sqlSearch.queryForList( - "SELECT id AS message_id FROM messages WHERE MATCH(?) ORDER BY id DESC LIMIT 25", - Integer.class, - search); - } - if (mids.size() > 0) { + public List<Integer> getSearch(final String search, final int before) { + List<Integer> mids = searchService.getMessageIdsInAllMessages(search, before); + + if (!mids.isEmpty()) return getNamedParameterJdbcTemplate().queryForList( "SELECT message_id FROM messages WHERE message_id IN (:ids) AND privacy > 0 ORDER BY message_id DESC LIMIT 20", new MapSqlParameterSource("ids", mids), Integer.class); - } return mids; } @@ -672,23 +665,9 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional(readOnly = true) @Override public List<Integer> getUserSearch(final JdbcTemplate sqlSearch, final int UID, final String search, final int privacy, final int before) { - List<Integer> mids; - - if (before > 0) { - mids = sqlSearch.queryForList( - "SELECT id AS message_id FROM messages WHERE user_id=? AND MATCH(?) AND id<? " + - "ORDER BY id DESC LIMIT 20", - new Object[]{UID, search, before}, - Integer.class); - } else { - mids = sqlSearch.queryForList( - "SELECT id AS message_id FROM messages WHERE user_id=? AND MATCH(?) " + - "ORDER BY id DESC LIMIT 20", - new Object[]{UID, search}, - Integer.class); - } + List<Integer> mids = searchService.getMessageIdsByUser(search, UID, before); - if (mids.size() > 0) { + if (!mids.isEmpty()) { return getNamedParameterJdbcTemplate().queryForList( "SELECT message_id FROM messages WHERE message_id IN (:ids) AND privacy >= :privacy ORDER BY message_id DESC", new MapSqlParameterSource("ids", mids) |