Authored by unknown

fix page

1 package com.yoho.search.service.servicenew.impl; 1 package com.yoho.search.service.servicenew.impl;
2 2
3 -import com.alibaba.fastjson.JSONObject;  
4 -import com.yoho.error.event.SearchEvent;  
5 -import com.yoho.search.base.utils.EventReportEnum;  
6 -import com.yoho.search.base.utils.ISearchConstants;  
7 -import com.yoho.search.base.utils.ProductIndexEsField;  
8 -import com.yoho.search.core.es.model.SearchParam;  
9 -import com.yoho.search.core.es.model.SearchResult;  
10 -import com.yoho.search.core.es.utils.IgnoreSomeException;  
11 -import com.yoho.search.service.cache.SearchCacheFactory;  
12 -import com.yoho.search.service.cache.model.SearchCache;  
13 -import com.yoho.search.service.service.SearchCacheService;  
14 -import com.yoho.search.service.service.SearchCommonService;  
15 -import com.yoho.search.service.service.base.ProductIndexBaseService;  
16 -import com.yoho.search.service.servicenew.ISknImageVectorsService;  
17 -import com.yoho.search.service.utils.SearchApiResultUtils;  
18 -import com.yoho.search.service.vo.SearchApiResult; 3 +import java.util.ArrayList;
  4 +import java.util.HashMap;
  5 +import java.util.LinkedHashMap;
  6 +import java.util.List;
  7 +import java.util.Map;
  8 +
  9 +import javax.annotation.PostConstruct;
  10 +
19 import org.apache.commons.collections.CollectionUtils; 11 import org.apache.commons.collections.CollectionUtils;
20 import org.apache.commons.lang.StringUtils; 12 import org.apache.commons.lang.StringUtils;
21 import org.elasticsearch.common.lucene.search.function.CombineFunction; 13 import org.elasticsearch.common.lucene.search.function.CombineFunction;
@@ -38,8 +30,22 @@ import org.springframework.context.ApplicationEventPublisher; @@ -38,8 +30,22 @@ import org.springframework.context.ApplicationEventPublisher;
38 import org.springframework.context.ApplicationEventPublisherAware; 30 import org.springframework.context.ApplicationEventPublisherAware;
39 import org.springframework.stereotype.Service; 31 import org.springframework.stereotype.Service;
40 32
41 -import javax.annotation.PostConstruct;  
42 -import java.util.*; 33 +import com.alibaba.fastjson.JSONObject;
  34 +import com.yoho.error.event.SearchEvent;
  35 +import com.yoho.search.base.utils.EventReportEnum;
  36 +import com.yoho.search.base.utils.ISearchConstants;
  37 +import com.yoho.search.base.utils.ProductIndexEsField;
  38 +import com.yoho.search.core.es.model.SearchParam;
  39 +import com.yoho.search.core.es.model.SearchResult;
  40 +import com.yoho.search.core.es.utils.IgnoreSomeException;
  41 +import com.yoho.search.service.cache.SearchCacheFactory;
  42 +import com.yoho.search.service.cache.model.SearchCache;
  43 +import com.yoho.search.service.service.SearchCacheService;
  44 +import com.yoho.search.service.service.SearchCommonService;
  45 +import com.yoho.search.service.service.base.ProductIndexBaseService;
  46 +import com.yoho.search.service.servicenew.ISknImageVectorsService;
  47 +import com.yoho.search.service.utils.SearchApiResultUtils;
  48 +import com.yoho.search.service.vo.SearchApiResult;
43 49
44 /** 50 /**
45 * Created by wangnan on 2017/7/28. 51 * Created by wangnan on 2017/7/28.
@@ -102,7 +108,6 @@ public class SknImageVectorsServiceImpl implements ISknImageVectorsService, Appl @@ -102,7 +108,6 @@ public class SknImageVectorsServiceImpl implements ISknImageVectorsService, Appl
102 if (pageSize > 50) { 108 if (pageSize > 50) {
103 pageSize = 50; 109 pageSize = 50;
104 } 110 }
105 - searchParam.setPage(page);  
106 searchParam.setOffset((page - 1) * pageSize); 111 searchParam.setOffset((page - 1) * pageSize);
107 searchParam.setSize(pageSize); 112 searchParam.setSize(pageSize);
108 searchParam.setQuery(buildFunctionScoreQueryBuilder(vectorsFieldName,vectorsValue)); 113 searchParam.setQuery(buildFunctionScoreQueryBuilder(vectorsFieldName,vectorsValue));
@@ -135,7 +140,6 @@ public class SknImageVectorsServiceImpl implements ISknImageVectorsService, Appl @@ -135,7 +140,6 @@ public class SknImageVectorsServiceImpl implements ISknImageVectorsService, Appl
135 searchParam.setFiter(this.getDefaultBoolQueryBuilder()); 140 searchParam.setFiter(this.getDefaultBoolQueryBuilder());
136 searchParam.setQuery(this.builderProductQueryBuilder(paramMap, querySknList)); 141 searchParam.setQuery(this.builderProductQueryBuilder(paramMap, querySknList));
137 searchParam.setAggregationBuilders(null); 142 searchParam.setAggregationBuilders(null);
138 - searchParam.setPage(page);  
139 searchParam.setOffset((page - 1) * pageSize); 143 searchParam.setOffset((page - 1) * pageSize);
140 searchParam.setSize(pageSize); 144 searchParam.setSize(pageSize);
141 List<SortBuilder> sortBuilders = new ArrayList<>(); 145 List<SortBuilder> sortBuilders = new ArrayList<>();
@@ -162,7 +166,7 @@ public class SknImageVectorsServiceImpl implements ISknImageVectorsService, Appl @@ -162,7 +166,7 @@ public class SknImageVectorsServiceImpl implements ISknImageVectorsService, Appl
162 dataMap.put("page", searchResult.getPage()); 166 dataMap.put("page", searchResult.getPage());
163 dataMap.put("page_size", searchParam.getSize()); 167 dataMap.put("page_size", searchParam.getSize());
164 dataMap.put("page_total", searchResult.getTotalPage()); 168 dataMap.put("page_total", searchResult.getTotalPage());
165 - dataMap.put("product_list", productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList(), Arrays.asList("phrase"))); 169 + dataMap.put("product_list", productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList()));
166 photoListData.put("photoListData", dataMap); 170 photoListData.put("photoListData", dataMap);
167 // 5.将结果存进缓存 171 // 5.将结果存进缓存
168 searchCacheService.addJSONObjectToCache(searchCache, indexName, searchParam, photoListData); 172 searchCacheService.addJSONObjectToCache(searchCache, indexName, searchParam, photoListData);