diff options
Diffstat (limited to 'juick-server-jdbc/src/main')
-rw-r--r-- | juick-server-jdbc/src/main/java/com/juick/service/SphinxSearchService.java | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/SphinxSearchService.java b/juick-server-jdbc/src/main/java/com/juick/service/SphinxSearchService.java index 26cf3a16..d8330908 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/SphinxSearchService.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/SphinxSearchService.java @@ -18,12 +18,14 @@ package com.juick.service; import org.apache.commons.lang3.StringUtils; -import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; /** * Created by aalexeev on 11/18/16. @@ -41,17 +43,17 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic if (StringUtils.isBlank(searchString)) return Collections.emptyList(); - MapSqlParameterSource sqlParameterSource = new MapSqlParameterSource() - .addValue("search", searchString) - .addValue("before", messageIdBefore - 1) - .addValue("limit", maxResult); + Map<String, String> sphinxQuery = new HashMap<>(); + sphinxQuery.put("limit", String.valueOf(maxResult)); + sphinxQuery.put("mode", "any"); + sphinxQuery.put("sort", "extended:@id desc"); + if (messageIdBefore > 0) { + sphinxQuery.put("maxid", String.valueOf(messageIdBefore - 1)); + } - return getNamedParameterJdbcTemplate().queryForList( - "SELECT id FROM search WHERE query = ':search;limit=:limit;mode=any;sort=extended:@id desc" + - (messageIdBefore > 0 ? - ";maxid=:before" : StringUtils.EMPTY) + "'", - sqlParameterSource, - Integer.class); + return getJdbcTemplate().queryForList( + "SELECT id FROM search WHERE query = '?;?'", Integer.class, searchString, + sphinxQuery.keySet().stream().map(Object::toString).collect(Collectors.joining(";"))); } @Override @@ -59,18 +61,17 @@ public class SphinxSearchService extends BaseJdbcService implements SearchServic if (StringUtils.isBlank(searchString)) return Collections.emptyList(); - MapSqlParameterSource sqlParameterSource = new MapSqlParameterSource() - .addValue("search", searchString) - .addValue("userId", userId) - .addValue("before", messageIdBefore - 1) - .addValue("limit", maxResult); - - return getNamedParameterJdbcTemplate().queryForList( - "SELECT id FROM search WHERE query = ':search;filter=user_id,:userId;sort=extended:@id desc" + - (messageIdBefore > 0 ? - ";maxid=:before" : StringUtils.EMPTY) + "'", - sqlParameterSource, - Integer.class); + Map<String, String> sphinxQuery = new HashMap<>(); + sphinxQuery.put("limit", String.valueOf(maxResult)); + sphinxQuery.put("mode", "any"); + sphinxQuery.put("sort", "extended:@id desc"); + if (messageIdBefore > 0) { + sphinxQuery.put("maxid", String.valueOf(messageIdBefore - 1)); + } + return getJdbcTemplate().queryForList( + "SELECT id FROM search WHERE query = '?;filter=user_id,?;?'", + Integer.class, searchString, userId, + sphinxQuery.keySet().stream().map(Object::toString).collect(Collectors.joining(";"))); } @Override |