|
@@ -42,9 +42,9 @@ public class CsSearchResourceFuzzyIndexBaseService { |
|
@@ -42,9 +42,9 @@ public class CsSearchResourceFuzzyIndexBaseService { |
42
|
|
42
|
|
43
|
//Guava Cache
|
43
|
//Guava Cache
|
44
|
private LoadingCache<String, List<Map<String, Object>>> fuzzySearchResourceCache = CacheBuilder.newBuilder()
|
44
|
private LoadingCache<String, List<Map<String, Object>>> fuzzySearchResourceCache = CacheBuilder.newBuilder()
|
45
|
- .maximumSize(100).expireAfterWrite(3, TimeUnit.MINUTES).build(new CacheLoader<String, List<Map<String, Object>>>() {
|
45
|
+ .maximumSize(100).expireAfterWrite(2, TimeUnit.MINUTES).build(new CacheLoader<String, List<Map<String, Object>>>() {
|
46
|
public List<Map<String, Object>> load(String key) {
|
46
|
public List<Map<String, Object>> load(String key) {
|
47
|
- return queryValidFuzzySearchResourceFromEs(1000);
|
47
|
+ return queryValidFuzzySearchResourceFromEs(500);
|
48
|
}
|
48
|
}
|
49
|
});
|
49
|
});
|
50
|
|
50
|
|
|
@@ -96,44 +96,45 @@ public class CsSearchResourceFuzzyIndexBaseService { |
|
@@ -96,44 +96,45 @@ public class CsSearchResourceFuzzyIndexBaseService { |
96
|
String image = MapUtils.getString(esMap, "image", "");
|
96
|
String image = MapUtils.getString(esMap, "image", "");
|
97
|
map.put("image", ImageUrlAssist.getAllProductPicUrl(image, "goodsimg", "center", "d2hpdGU="));
|
97
|
map.put("image", ImageUrlAssist.getAllProductPicUrl(image, "goodsimg", "center", "d2hpdGU="));
|
98
|
map.put("resource_type", MapUtils.getIntValue(esMap, "resourceType", 0));
|
98
|
map.put("resource_type", MapUtils.getIntValue(esMap, "resourceType", 0));
|
99
|
- Object esDetails = MapUtils.getObject(esMap,"details",new ArrayList<>());
|
|
|
100
|
- List<JSONObject> esDetailList = JSON.parseObject(JSON.toJSONString(esDetails), new TypeReference<List<JSONObject>>(){});
|
|
|
101
|
- List<JSONObject> detailResults = esDetailList.stream().map(details->transferDetails(details)).collect(Collectors.toList());
|
99
|
+ Object esDetails = MapUtils.getObject(esMap, "details", new ArrayList<>());
|
|
|
100
|
+ List<JSONObject> esDetailList = JSON.parseObject(JSON.toJSONString(esDetails), new TypeReference<List<JSONObject>>() {
|
|
|
101
|
+ });
|
|
|
102
|
+ List<JSONObject> detailResults = esDetailList.stream().map(details -> transferDetails(details)).collect(Collectors.toList());
|
102
|
map.put("details", detailResults);
|
103
|
map.put("details", detailResults);
|
103
|
return map;
|
104
|
return map;
|
104
|
}
|
105
|
}
|
105
|
|
106
|
|
106
|
- private JSONObject transferDetails(JSONObject detail){
|
107
|
+ private JSONObject transferDetails(JSONObject detail) {
|
107
|
JSONObject result = new JSONObject();
|
108
|
JSONObject result = new JSONObject();
|
108
|
- result.put("id",detail.getIntValue("id"));
|
|
|
109
|
- result.put("show_name",detail.getString("showName"));
|
109
|
+ result.put("id", detail.getIntValue("id"));
|
|
|
110
|
+ result.put("show_name", detail.getString("showName"));
|
110
|
int link_type = detail.getIntValue("linkType");
|
111
|
int link_type = detail.getIntValue("linkType");
|
111
|
String param = detail.getString("param");
|
112
|
String param = detail.getString("param");
|
112
|
- result.put("link_type",link_type);
|
|
|
113
|
- if(link_type==1){
|
|
|
114
|
- result.put("keyword",param);
|
|
|
115
|
- }else{
|
|
|
116
|
- result.put("params",transfer(param));
|
113
|
+ result.put("link_type", link_type);
|
|
|
114
|
+ if (link_type == 1) {
|
|
|
115
|
+ result.put("keyword", param);
|
|
|
116
|
+ } else {
|
|
|
117
|
+ result.put("params", transfer(param));
|
117
|
}
|
118
|
}
|
118
|
return result;
|
119
|
return result;
|
119
|
}
|
120
|
}
|
120
|
|
121
|
|
121
|
@Data
|
122
|
@Data
|
122
|
- public static class ParamKeyValue{
|
123
|
+ public static class ParamKeyValue {
|
123
|
String key;
|
124
|
String key;
|
124
|
String value;
|
125
|
String value;
|
125
|
}
|
126
|
}
|
126
|
|
127
|
|
127
|
// "param": "brand=248&sort=1"
|
128
|
// "param": "brand=248&sort=1"
|
128
|
- private List<ParamKeyValue> transfer(String param){
|
129
|
+ private List<ParamKeyValue> transfer(String param) {
|
129
|
List<ParamKeyValue> results = new ArrayList<>();
|
130
|
List<ParamKeyValue> results = new ArrayList<>();
|
130
|
- String [] paramParts = param.split("&");
|
|
|
131
|
- for(String paramPart : paramParts){
|
|
|
132
|
- String [] keyValueArr = paramPart.split("=");
|
|
|
133
|
- if(keyValueArr.length!=2){
|
131
|
+ String[] paramParts = param.split("&");
|
|
|
132
|
+ for (String paramPart : paramParts) {
|
|
|
133
|
+ String[] keyValueArr = paramPart.split("=");
|
|
|
134
|
+ if (keyValueArr.length != 2) {
|
134
|
continue;
|
135
|
continue;
|
135
|
}
|
136
|
}
|
136
|
- ParamKeyValue keyValue = new ParamKeyValue();
|
137
|
+ ParamKeyValue keyValue = new ParamKeyValue();
|
137
|
keyValue.key = keyValueArr[0];
|
138
|
keyValue.key = keyValueArr[0];
|
138
|
keyValue.value = keyValueArr[1];
|
139
|
keyValue.value = keyValueArr[1];
|
139
|
results.add(keyValue);
|
140
|
results.add(keyValue);
|
|
@@ -141,17 +142,20 @@ public class CsSearchResourceFuzzyIndexBaseService { |
|
@@ -141,17 +142,20 @@ public class CsSearchResourceFuzzyIndexBaseService { |
141
|
return results;
|
142
|
return results;
|
142
|
}
|
143
|
}
|
143
|
|
144
|
|
144
|
-
|
|
|
145
|
- public List<Map<String, Object>> queryFuzzySearchResourcesByKeyWord(Map<String, String> paramMap) {
|
145
|
+ public List<Map<String, Object>> queryFuzzySearchResourcesByKeyWord(String keyword, boolean contain_xixuan) {
|
146
|
try {
|
146
|
try {
|
147
|
- String keyword = MapUtils.getString(paramMap, SearchRequestParams.PARAM_SEARCH_QUERY, "");
|
|
|
148
|
List<Map<String, Object>> cacheResult = fuzzySearchResourceCache.get("DEFAULT");
|
147
|
List<Map<String, Object>> cacheResult = fuzzySearchResourceCache.get("DEFAULT");
|
149
|
return cacheResult.stream().filter(resource -> {
|
148
|
return cacheResult.stream().filter(resource -> {
|
150
|
- if (MapUtils.getString(resource, "keyword").equalsIgnoreCase(keyword)) {
|
|
|
151
|
- return true;
|
|
|
152
|
- } else {
|
149
|
+ // 判断是否包含细选
|
|
|
150
|
+ int resource_type = MapUtils.getIntValue(resource, "resource_type", 0);
|
|
|
151
|
+ if (!contain_xixuan && resource_type == 1) {
|
153
|
return false;
|
152
|
return false;
|
154
|
}
|
153
|
}
|
|
|
154
|
+ // 判断关键字能否匹配
|
|
|
155
|
+ if (MapUtils.getString(resource, "keyword", "").equalsIgnoreCase(keyword)) {
|
|
|
156
|
+ return true;
|
|
|
157
|
+ }
|
|
|
158
|
+ return false;
|
155
|
}).collect(Collectors.toList());
|
159
|
}).collect(Collectors.toList());
|
156
|
} catch (Exception e) {
|
160
|
} catch (Exception e) {
|
157
|
logger.error(e.getMessage(), e);
|
161
|
logger.error(e.getMessage(), e);
|