...
|
...
|
@@ -10,6 +10,7 @@ const api = global.yoho.API; |
|
|
const Promise = require('bluebird');
|
|
|
const co = Promise.coroutine;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const redis = global.yoho.redis;
|
|
|
const saleApi = require('./sale-api');
|
|
|
const searchApi = require('./search-api');
|
|
|
const headerModel = require('../../../doraemon/models/header');
|
...
|
...
|
@@ -401,3 +402,71 @@ exports.getSearchKeywordData = (params, channel) => { |
|
|
return setSearchKeywordData(result, params, channel);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取搜索建议数据
|
|
|
* @id {[number]} origin [description]
|
|
|
* @param {[object]} origin [description]
|
|
|
* @channel {[string]} origin [description]
|
|
|
* @return {[object]} [description]
|
|
|
*/
|
|
|
exports.getSearchKeywordDataById = (id, params, channel) => {
|
|
|
return co(function * () {
|
|
|
let searchParams = searchHandler.getSearchParams(params);
|
|
|
|
|
|
switch (channel) {
|
|
|
case 'boys':
|
|
|
searchParams.physical_channel = 1;
|
|
|
break;
|
|
|
case 'girls':
|
|
|
searchParams.physical_channel = 2;
|
|
|
break;
|
|
|
case 'kids':
|
|
|
searchParams.physical_channel = 3;
|
|
|
break;
|
|
|
case 'lifestyle':
|
|
|
searchParams.physical_channel = 4;
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
searchParams.need_filter = 'no';
|
|
|
|
|
|
let redisData = yield redis.all([
|
|
|
['get', `golobal:yoho:seo:keywords:id:${id}`]
|
|
|
]);
|
|
|
|
|
|
if (!redisData[0]) {
|
|
|
return Promise.reject('get redis canpin keywords by id error!' +
|
|
|
`key: golobal:yoho:seo:keywords:id:${id} value: ${redisData[0]}`);
|
|
|
}
|
|
|
|
|
|
redisData = JSON.parse(redisData[0]);
|
|
|
|
|
|
searchParams.query = redisData.name;
|
|
|
|
|
|
let result = yield api.all([
|
|
|
headerModel.requestHeaderData(channel),
|
|
|
searchApi.getSuggest({keyword: searchParams.query.substring(0, 2)}),
|
|
|
searchApi.getProductList(searchParams, 'fuzzySearch')
|
|
|
]);
|
|
|
|
|
|
let resData = setSearchKeywordData(result, params, channel);
|
|
|
|
|
|
resData.queryKey = searchParams.query;
|
|
|
|
|
|
if (!_.isEmpty(redisData.data)) {
|
|
|
_.forEach(redisData.data, value => {
|
|
|
Object.assign({
|
|
|
name: value.keyword,
|
|
|
href: helpers.urlFormat(`/canpin/${value.root_id}.html`, null, 'www')
|
|
|
});
|
|
|
});
|
|
|
|
|
|
_.set(resData, 'search.allSuggest.list', redisData.data);
|
|
|
}
|
|
|
|
|
|
return resData;
|
|
|
})();
|
|
|
}; |
...
|
...
|
|