Showing
1 changed file
with
31 additions
and
17 deletions
@@ -5,8 +5,11 @@ import com.yoho.search.base.utils.ISearchConstants; | @@ -5,8 +5,11 @@ import com.yoho.search.base.utils.ISearchConstants; | ||
5 | import com.yoho.search.core.es.model.SearchParam; | 5 | import com.yoho.search.core.es.model.SearchParam; |
6 | import com.yoho.search.core.es.model.SearchResult; | 6 | import com.yoho.search.core.es.model.SearchResult; |
7 | import com.yoho.search.core.personalized.models.SortBrand; | 7 | import com.yoho.search.core.personalized.models.SortBrand; |
8 | +import com.yoho.search.recall.scene.beans.persional.QueryUserPersionalFactorBean; | ||
8 | import com.yoho.search.service.base.SearchCommonService; | 9 | import com.yoho.search.service.base.SearchCommonService; |
9 | import org.apache.commons.collections.MapUtils; | 10 | import org.apache.commons.collections.MapUtils; |
11 | +import org.slf4j.Logger; | ||
12 | +import org.slf4j.LoggerFactory; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
11 | import org.springframework.stereotype.Component; | 14 | import org.springframework.stereotype.Component; |
12 | 15 | ||
@@ -22,6 +25,8 @@ import java.util.concurrent.TimeUnit; | @@ -22,6 +25,8 @@ import java.util.concurrent.TimeUnit; | ||
22 | @Component | 25 | @Component |
23 | public class SortBrandVectorCacheBean { | 26 | public class SortBrandVectorCacheBean { |
24 | 27 | ||
28 | + private static final Logger RECALL_NEW_LOGGER = LoggerFactory.getLogger("RECALL"); | ||
29 | + | ||
25 | @Autowired | 30 | @Autowired |
26 | private SearchCommonService searchCommonService; | 31 | private SearchCommonService searchCommonService; |
27 | 32 | ||
@@ -37,6 +42,7 @@ public class SortBrandVectorCacheBean { | @@ -37,6 +42,7 @@ public class SortBrandVectorCacheBean { | ||
37 | public List<Double> queryBrandSortVector(SortBrand sortBrand) { | 42 | public List<Double> queryBrandSortVector(SortBrand sortBrand) { |
38 | try { | 43 | try { |
39 | if (sortBrandVector == null || sortBrandVector.isEmpty()) { | 44 | if (sortBrandVector == null || sortBrandVector.isEmpty()) { |
45 | + RECALL_NEW_LOGGER.warn("sortBrandVector is empty,please check........"); | ||
40 | return new ArrayList<>(); | 46 | return new ArrayList<>(); |
41 | } | 47 | } |
42 | return sortBrandVector.get(sortBrand.key()); | 48 | return sortBrandVector.get(sortBrand.key()); |
@@ -46,26 +52,34 @@ public class SortBrandVectorCacheBean { | @@ -46,26 +52,34 @@ public class SortBrandVectorCacheBean { | ||
46 | } | 52 | } |
47 | 53 | ||
48 | private Map<String, List<Double>> loadAllSortBrandVectors() { | 54 | private Map<String, List<Double>> loadAllSortBrandVectors() { |
49 | - SearchParam searchParam = new SearchParam(); | ||
50 | - searchParam.setSize(20000); | ||
51 | - SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_BIGDATASORTBRANDVECTOR, searchParam); | ||
52 | - Map<String, List<Double>> result = new HashMap<>(); | ||
53 | - for (Map<String, Object> sortBrandVector : searchResult.getResultList()) { | ||
54 | - try { | ||
55 | - int middleSortId = MapUtils.getIntValue(sortBrandVector, "middleSortId", 0); | ||
56 | - int brandId = MapUtils.getIntValue(sortBrandVector, "brandId", 0); | ||
57 | - String vector = MapUtils.getString(sortBrandVector, "vector", "[]"); | ||
58 | - List<Double> vectorArray = JSON.parseArray(vector, Double.class); | ||
59 | - if (middleSortId == 0 || brandId == 0 || vectorArray.isEmpty()) { | ||
60 | - continue; | ||
61 | - } | ||
62 | - SortBrand sortBrand = new SortBrand(middleSortId, brandId); | ||
63 | - result.put(sortBrand.key(), vectorArray); | ||
64 | - } catch (Exception e) { | 55 | + try { |
56 | + RECALL_NEW_LOGGER.info("loadAllSortBrandVectors begin ........"); | ||
57 | + long begin = System.currentTimeMillis(); | ||
58 | + SearchParam searchParam = new SearchParam(); | ||
59 | + searchParam.setSize(20000); | ||
60 | + SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_BIGDATASORTBRANDVECTOR, searchParam); | ||
61 | + Map<String, List<Double>> result = new HashMap<>(); | ||
62 | + for (Map<String, Object> sortBrandVector : searchResult.getResultList()) { | ||
63 | + try { | ||
64 | + int middleSortId = MapUtils.getIntValue(sortBrandVector, "middleSortId", 0); | ||
65 | + int brandId = MapUtils.getIntValue(sortBrandVector, "brandId", 0); | ||
66 | + String vector = MapUtils.getString(sortBrandVector, "vector", "[]"); | ||
67 | + List<Double> vectorArray = JSON.parseArray(vector, Double.class); | ||
68 | + if (middleSortId == 0 || brandId == 0 || vectorArray.isEmpty()) { | ||
69 | + continue; | ||
70 | + } | ||
71 | + SortBrand sortBrand = new SortBrand(middleSortId, brandId); | ||
72 | + result.put(sortBrand.key(), vectorArray); | ||
73 | + } catch (Exception e) { | ||
65 | 74 | ||
75 | + } | ||
66 | } | 76 | } |
77 | + RECALL_NEW_LOGGER.info("loadAllSortBrandVectors end,size is[{}],cost is[{}]",result.size(),System.currentTimeMillis()-begin); | ||
78 | + return result; | ||
79 | + }catch (Exception e){ | ||
80 | + RECALL_NEW_LOGGER.error("loadAllSortBrandVectors fail"+e.getMessage(),e); | ||
81 | + return null; | ||
67 | } | 82 | } |
68 | - return result; | ||
69 | } | 83 | } |
70 | 84 | ||
71 | } | 85 | } |
-
Please register or login to post a comment