BigdataSimilarSknIndexBaseService.java
2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.yoho.search.service.index;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.bo.BigdataSimilarSknIndexBO;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.dal.model.BigdataSimilarSkn;
import com.yoho.search.common.SearchCommonService;
import org.apache.commons.beanutils.BeanUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Map;
@Service
public class BigdataSimilarSknIndexBaseService {
private static final Logger logger = LoggerFactory.getLogger(BigdataSimilarSknIndexBaseService.class);
@Autowired
private SearchCommonService searchCommonService;
public BigdataSimilarSknIndexBO querySimilarSkn(String productSkn) {
try {
SearchParam searchParam = new SearchParam();
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, productSkn));
searchParam.setFiter(boolFilter);
searchParam.setAggregationBuilders(null);
searchParam.setSize(1);
String productIndexName = ISearchConstants.INDEX_NAME_BIGDATA_SIMILAR_SKN_INDEX;
SearchResult searchResult = searchCommonService.doSearch(productIndexName, searchParam);
if (searchResult == null) {
return null;
}
List<Map<String, Object>> similarSknResults = searchResult.getResultList();
if (CollectionUtils.isEmpty(similarSknResults) || similarSknResults.get(0) == null) {
return null;
}
Map<String, Object> result = similarSknResults.get(0);
BigdataSimilarSknIndexBO bigdataSimilarSkn = new BigdataSimilarSknIndexBO();
BeanUtils.populate(bigdataSimilarSkn, result);
return bigdataSimilarSkn;
}catch (Exception e){
logger.error(e.getMessage(),e);
return null;
}
}
}