|
|
package com.yoho.search.service.scene.pages;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.base.utils.SearchPageIdDefine;
|
|
|
import com.yoho.search.common.SearchRequestParams;
|
|
|
import com.yoho.search.common.utils.SearchApiResultUtils;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import com.yoho.search.common.SearchRequestParams;
|
|
|
import com.yoho.search.service.helper.SearchCommonHelper;
|
|
|
import com.yoho.search.service.helper.SearchKeyWordHelper;
|
|
|
import com.yoho.search.service.scene.pages.entrance.ProductListSwitchService;
|
...
|
...
|
@@ -16,6 +17,7 @@ import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Service
|
...
|
...
|
@@ -46,6 +48,7 @@ public class MiniappFuzzyPageSceneService extends AbstractPageSceneService { |
|
|
super.addDefaultParamsToParamMap(paramMap);
|
|
|
super.filterNotNormalToMap(paramMap);
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_NEED_SUGGESTION, "Y");// 返回建议词
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_NOT_MAXSORT_ID, "1186");
|
|
|
paramMap.remove(SearchRequestParams.PARAM_SEARCH_ISADVANCE);// 放开普通预售
|
|
|
}
|
|
|
|
...
|
...
|
@@ -69,19 +72,49 @@ public class MiniappFuzzyPageSceneService extends AbstractPageSceneService { |
|
|
// 4、加入建议词
|
|
|
fuzzySceneService.addSuggestion(productListResult, paramMap);
|
|
|
|
|
|
// 5、模糊搜索页记录关键字对应的查询结果
|
|
|
// 5、去除成人用品关键字
|
|
|
this.removeBlackKeyword(productListResult);
|
|
|
|
|
|
// 6、模糊搜索页记录关键字对应的查询结果
|
|
|
String queryWord = paramMap.get("query");
|
|
|
if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySknOrSku(queryWord)) {
|
|
|
long total = ((JSONObject) productListResult.getData()).getLongValue("total");
|
|
|
searchKeyWordService.recordKeyWordByResultCount(queryWord, total);
|
|
|
}
|
|
|
//6、返回结果
|
|
|
// 7、返回结果
|
|
|
return productListResult;
|
|
|
} catch (Exception e) {
|
|
|
return SearchApiResultUtils.errorSearchApiResult(logger, paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void removeBlackKeyword(SearchApiResult productListResult) {
|
|
|
try {
|
|
|
JSONObject result = (JSONObject) productListResult.getData();
|
|
|
if (result == null) {
|
|
|
return;
|
|
|
}
|
|
|
JSONObject suggestion = result.getJSONObject("suggestion");
|
|
|
if (suggestion == null) {
|
|
|
return;
|
|
|
}
|
|
|
JSONArray termsSuggestion = suggestion.getJSONArray("terms_suggestion");
|
|
|
if (termsSuggestion == null || termsSuggestion.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
Iterator<Object> iterator = termsSuggestion.iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
String keyWord = iterator.next().toString();
|
|
|
if (keyWord.contains("成人")) {
|
|
|
iterator.remove();
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public SearchApiResult aggregations(Map<String, String> paramMap) {
|
|
|
try {
|
...
|
...
|
@@ -93,7 +126,7 @@ public class MiniappFuzzyPageSceneService extends AbstractPageSceneService { |
|
|
this.addParamsToParamMap(paramMap);
|
|
|
// 2、返回聚合结果
|
|
|
SearchApiResult result = pageSelectionsService.aggregations(paramMap);
|
|
|
if(result!=null){
|
|
|
if (result != null) {
|
|
|
scenePageSelectionsBrandsService.getRecommendBrands(paramMap, result);
|
|
|
}
|
|
|
return result;
|
...
|
...
|
|