Authored by wangnan

【图片搜索】 两次查询

@@ -18,6 +18,7 @@ import com.yoho.search.service.servicenew.ISknImageVectorsService; @@ -18,6 +18,7 @@ import com.yoho.search.service.servicenew.ISknImageVectorsService;
18 import com.yoho.search.service.utils.SearchApiResultUtils; 18 import com.yoho.search.service.utils.SearchApiResultUtils;
19 import com.yoho.search.service.vo.SearchApiResult; 19 import com.yoho.search.service.vo.SearchApiResult;
20 import org.apache.commons.collections.CollectionUtils; 20 import org.apache.commons.collections.CollectionUtils;
  21 +import org.apache.commons.lang.StringUtils;
21 import org.elasticsearch.common.lucene.search.function.CombineFunction; 22 import org.elasticsearch.common.lucene.search.function.CombineFunction;
22 import org.elasticsearch.index.query.BoolQueryBuilder; 23 import org.elasticsearch.index.query.BoolQueryBuilder;
23 import org.elasticsearch.index.query.MatchAllQueryBuilder; 24 import org.elasticsearch.index.query.MatchAllQueryBuilder;
@@ -26,6 +27,7 @@ import org.elasticsearch.index.query.QueryBuilders; @@ -26,6 +27,7 @@ import org.elasticsearch.index.query.QueryBuilders;
26 import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder; 27 import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
27 import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders; 28 import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
28 import org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionBuilder; 29 import org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionBuilder;
  30 +import org.elasticsearch.script.Script;
29 import org.elasticsearch.script.ScriptService; 31 import org.elasticsearch.script.ScriptService;
30 import org.elasticsearch.search.sort.SortBuilder; 32 import org.elasticsearch.search.sort.SortBuilder;
31 import org.elasticsearch.search.sort.SortBuilders; 33 import org.elasticsearch.search.sort.SortBuilders;
@@ -38,14 +40,7 @@ import org.springframework.context.ApplicationEventPublisherAware; @@ -38,14 +40,7 @@ import org.springframework.context.ApplicationEventPublisherAware;
38 import org.springframework.stereotype.Service; 40 import org.springframework.stereotype.Service;
39 41
40 import javax.annotation.PostConstruct; 42 import javax.annotation.PostConstruct;
41 -import java.util.ArrayList;  
42 -import java.util.HashMap;  
43 -import java.util.LinkedHashMap;  
44 -import java.util.List;  
45 -import java.util.Map;  
46 -  
47 -import org.apache.commons.lang.StringUtils;  
48 -import org.elasticsearch.script.Script; 43 +import java.util.*;
49 44
50 /** 45 /**
51 * Created by wangnan on 2017/7/28. 46 * Created by wangnan on 2017/7/28.
@@ -103,7 +98,6 @@ public class SknImageVectorsServiceImpl implements ISknImageVectorsService, Appl @@ -103,7 +98,6 @@ public class SknImageVectorsServiceImpl implements ISknImageVectorsService, Appl
103 if (pageSize > 50) { 98 if (pageSize > 50) {
104 pageSize = 50; 99 pageSize = 50;
105 } 100 }
106 - searchParam.setPage(page);  
107 searchParam.setOffset((page - 1) * pageSize); 101 searchParam.setOffset((page - 1) * pageSize);
108 searchParam.setSize(VECTORS_32_QUERY_BACK_NUM); 102 searchParam.setSize(VECTORS_32_QUERY_BACK_NUM);
109 searchParam.setQuery(buildFunctionScoreQueryBuilder(VECTORS_32_KEY, vectors_32, null)); 103 searchParam.setQuery(buildFunctionScoreQueryBuilder(VECTORS_32_KEY, vectors_32, null));
@@ -120,11 +114,9 @@ public class SknImageVectorsServiceImpl implements ISknImageVectorsService, Appl @@ -120,11 +114,9 @@ public class SknImageVectorsServiceImpl implements ISknImageVectorsService, Appl
120 sknFilterString += map.get("productSkn").toString() + ","; 114 sknFilterString += map.get("productSkn").toString() + ",";
121 } 115 }
122 //2.2第二次查询,用128维向量粗查询这些skn 116 //2.2第二次查询,用128维向量粗查询这些skn
123 - searchParam.setPage(page);  
124 searchParam.setOffset((page - 1) * pageSize); 117 searchParam.setOffset((page - 1) * pageSize);
125 searchParam.setSize(pageSize); 118 searchParam.setSize(pageSize);
126 - //todo 先用32维的,后面要改成128的  
127 - searchParam.setQuery(buildFunctionScoreQueryBuilder(VECTORS_32_KEY, vectors_32, sknFilterString)); 119 + searchParam.setQuery(buildFunctionScoreQueryBuilder(VECTORS_128_KEY, vectors_128, sknFilterString));
128 searchResult = searchCommonService.doSearch(indexName, searchParam); 120 searchResult = searchCommonService.doSearch(indexName, searchParam);
129 if (CollectionUtils.isNotEmpty(searchResult.getResultList())) { 121 if (CollectionUtils.isNotEmpty(searchResult.getResultList())) {
130 sknList = getSknImageMap(searchResult.getResultList()); 122 sknList = getSknImageMap(searchResult.getResultList());