Commit 6d2166d2 authored by Quxl's avatar Quxl

优化搜索API

parent b0744e26
...@@ -10,6 +10,7 @@ import com.egolm.common.jdbc.Page; ...@@ -10,6 +10,7 @@ import com.egolm.common.jdbc.Page;
import com.egolm.shop.service.SolrGoodsService; import com.egolm.shop.service.SolrGoodsService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@Api @Api
...@@ -23,8 +24,10 @@ public class SolrGoodsController { ...@@ -23,8 +24,10 @@ public class SolrGoodsController {
@ResponseBody @ResponseBody
@RequestMapping("query") @RequestMapping("query")
@ApiOperation("搜索引擎商品搜索") @ApiOperation("搜索引擎商品搜索")
public Object query(Page page, String queryKey, String[] keywords, String[] orders, String[] facetFields, String[] facetPivotFields) { @ApiImplicitParams({
return service.query(page, queryKey, keywords, orders, facetFields, facetPivotFields); })
public Object query(Page page, String queryKey, String[] keywords, String[] facetFields, String[] facetPivotFields) {
return service.query(page, queryKey, keywords, facetFields, facetPivotFields);
} }
@ResponseBody @ResponseBody
......
...@@ -5,7 +5,7 @@ import com.egolm.common.jdbc.Page; ...@@ -5,7 +5,7 @@ import com.egolm.common.jdbc.Page;
public interface SolrGoodsService { 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(); public void update();
......
...@@ -42,8 +42,8 @@ public class SolrGoodsServiceImpl implements SolrGoodsService { ...@@ -42,8 +42,8 @@ public class SolrGoodsServiceImpl implements SolrGoodsService {
private HttpSolrClient solrClient; private HttpSolrClient solrClient;
@Override @Override
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) {
logger.info("收到商品检索请求:" + Rjx.json().set("page", page).set("queryKey", queryKey).set("keywords", keywords).set("orders", orders).set("facetFields", facetFields).set("facetPivotFields", facetPivotFields)); logger.info("收到商品检索请求:" + Rjx.json().set("page", page).set("queryKey", queryKey).set("keywords", keywords).set("facetFields", facetFields).set("facetPivotFields", facetPivotFields));
if(page == null) { if(page == null) {
page = new Page(1L, 20L); page = new Page(1L, 20L);
} }
...@@ -57,9 +57,10 @@ public class SolrGoodsServiceImpl implements SolrGoodsService { ...@@ -57,9 +57,10 @@ public class SolrGoodsServiceImpl implements SolrGoodsService {
solrQuery.addFilterQuery(keyword); solrQuery.addFilterQuery(keyword);
} }
} }
if(orders != null) { String[] limitKeys = page.getLimitKey();
for(String order : orders) { if(limitKeys != null) {
String[] kv = order.split(":", 2); 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; ORDER sc = kv[1] == null || kv[1].trim().length() == 0 || kv[1].equalsIgnoreCase("asc") ? ORDER.asc : ORDER.desc;
solrQuery.addSort(kv[0], sc); solrQuery.addSort(kv[0], sc);
} }
...@@ -150,7 +151,7 @@ public class SolrGoodsServiceImpl implements SolrGoodsService { ...@@ -150,7 +151,7 @@ public class SolrGoodsServiceImpl implements SolrGoodsService {
} }
@Override @Override
public void deleteById(String... documentIds) { public void deleteById(String[] documentIds) {
try { try {
solrClient.deleteById(Arrays.asList(documentIds)); solrClient.deleteById(Arrays.asList(documentIds));
solrClient.commit(); 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