Authored by hugufei

add try catch

@@ -2,34 +2,42 @@ package com.yoho.search.service.recall.models.personal; @@ -2,34 +2,42 @@ package com.yoho.search.service.recall.models.personal;
2 2
3 import com.yoho.search.core.personalized.models.PersonalizedSearch; 3 import com.yoho.search.core.personalized.models.PersonalizedSearch;
4 import org.apache.commons.lang.StringUtils; 4 import org.apache.commons.lang.StringUtils;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
5 7
6 import java.util.ArrayList; 8 import java.util.ArrayList;
7 import java.util.List; 9 import java.util.List;
8 10
9 public class UserFeatureFactor { 11 public class UserFeatureFactor {
10 12
  13 + private static final Logger logger = LoggerFactory.getLogger(UserFeatureFactor.class);
  14 +
11 private List<Double> userFeatureVectorList = null; 15 private List<Double> userFeatureVectorList = null;
12 private double userFeatureVectorNorm = 0.0D; 16 private double userFeatureVectorNorm = 0.0D;
13 private String vectorFeatureVersion; 17 private String vectorFeatureVersion;
14 18
15 public UserFeatureFactor(PersonalizedSearch personalizedSearch) { 19 public UserFeatureFactor(PersonalizedSearch personalizedSearch) {
16 - if (personalizedSearch == null) {  
17 - return;  
18 - }  
19 - this.vectorFeatureVersion = personalizedSearch.getVectorFeatureVersion();  
20 - String userVectorFeature = personalizedSearch.getUserVectorFeature();  
21 - if(StringUtils.isBlank(userVectorFeature)){  
22 - return;  
23 - }  
24 - String[] userFeatureFactorStrArr = userVectorFeature.split(",");  
25 - if(userFeatureFactorStrArr.length==0){  
26 - return;  
27 - }  
28 - userFeatureVectorList = new ArrayList<>(userFeatureFactorStrArr.length);  
29 - for (String userFeatureFactorStr : userFeatureFactorStrArr) {  
30 - double userFeatureVector = Double.parseDouble(userFeatureFactorStr.trim());  
31 - userFeatureVectorList.add(userFeatureVector);  
32 - userFeatureVectorNorm += userFeatureVector * userFeatureVector; 20 + try {
  21 + if (personalizedSearch == null) {
  22 + return;
  23 + }
  24 + this.vectorFeatureVersion = personalizedSearch.getVectorFeatureVersion();
  25 + String userVectorFeature = personalizedSearch.getUserVectorFeature();
  26 + if(StringUtils.isBlank(userVectorFeature)){
  27 + return;
  28 + }
  29 + String[] userFeatureFactorStrArr = userVectorFeature.split(",");
  30 + if(userFeatureFactorStrArr.length==0){
  31 + return;
  32 + }
  33 + userFeatureVectorList = new ArrayList<>(userFeatureFactorStrArr.length);
  34 + for (String userFeatureFactorStr : userFeatureFactorStrArr) {
  35 + double userFeatureVector = Double.parseDouble(userFeatureFactorStr.trim());
  36 + userFeatureVectorList.add(userFeatureVector);
  37 + userFeatureVectorNorm += userFeatureVector * userFeatureVector;
  38 + }
  39 + }catch (Exception e){
  40 + logger.error(e.getMessage());
33 } 41 }
34 } 42 }
35 43