Commit 6d2166d2 authored by Quxl's avatar Quxl

优化搜索API

parent b0744e26
......@@ -10,6 +10,7 @@ import com.egolm.common.jdbc.Page;
import com.egolm.shop.service.SolrGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api
......@@ -23,8 +24,10 @@ public class SolrGoodsController {
@ResponseBody
@RequestMapping("query")
@ApiOperation("搜索引擎商品搜索")
public Object query(Page page, String queryKey, String[] keywords, String[] orders, String[] facetFields, String[] facetPivotFields) {
return service.query(page, queryKey, keywords, orders, facetFields, facetPivotFields);
@ApiImplicitParams({
})
public Object query(Page page, String queryKey, String[] keywords, String[] facetFields, String[] facetPivotFields) {
return service.query(page, queryKey, keywords, facetFields, facetPivotFields);
}
@ResponseBody
......
......@@ -5,7 +5,7 @@ import com.egolm.common.jdbc.Page;
public interface SolrGoodsService {
public Rjx query(Page page, String queryKey, String[] keywords, String[] orders, String[] facetFields, String[] facetPivotFields);
public Rjx query(Page page, String queryKey, String[] keywords, String[] facetFields, String[] facetPivotFields);
public void update();
......
......@@ -42,8 +42,8 @@ public class SolrGoodsServiceImpl implements SolrGoodsService {
private HttpSolrClient solrClient;
@Override
public Rjx query(Page page, String queryKey, String[] keywords, String[] orders, String[] facetFields, String[] facetPivotFields) {
logger.info("收到商品检索请求:" + Rjx.json().set("page", page).set("queryKey", queryKey).set("keywords", keywords).set("orders", orders).set("facetFields", facetFields).set("facetPivotFields", facetPivotFields));
public Rjx query(Page page, String queryKey, String[] keywords, String[] facetFields, String[] facetPivotFields) {
logger.info("收到商品检索请求:" + Rjx.json().set("page", page).set("queryKey", queryKey).set("keywords", keywords).set("facetFields", facetFields).set("facetPivotFields", facetPivotFields));
if(page == null) {
page = new Page(1L, 20L);
}
......@@ -57,9 +57,10 @@ public class SolrGoodsServiceImpl implements SolrGoodsService {
solrQuery.addFilterQuery(keyword);
}
}
if(orders != null) {
for(String order : orders) {
String[] kv = order.split(":", 2);
String[] limitKeys = page.getLimitKey();
if(limitKeys != null) {
for(String key : limitKeys) {
String[] kv = key.split(" ", 2);
ORDER sc = kv[1] == null || kv[1].trim().length() == 0 || kv[1].equalsIgnoreCase("asc") ? ORDER.asc : ORDER.desc;
solrQuery.addSort(kv[0], sc);
}
......@@ -150,7 +151,7 @@ public class SolrGoodsServiceImpl implements SolrGoodsService {
}
@Override
public void deleteById(String... documentIds) {
public void deleteById(String[] documentIds) {
try {
solrClient.deleteById(Arrays.asList(documentIds));
solrClient.commit();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment