aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-06-01 11:09:49 +0300
committerGravatar Vitaly Takmazov2018-06-01 11:09:49 +0300
commit84b2f994bd9b6b46155dda5953922cc0882c6514 (patch)
treea5882968fdc39ebc67ad0986b7f8e40e38082ab8
parent52280c2560ab7b8471c0dc3955b5002157713fd2 (diff)
server: fix SphinxSE query languae mapping
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/SphinxSearchService.java47
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