...
|
...
|
@@ -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');
|
...
|
...
|
@@ -393,7 +394,7 @@ exports.getSearchKeywordData = (params, channel) => { |
|
|
let apiMethod = [
|
|
|
headerModel.requestHeaderData(channel),
|
|
|
searchApi.getSuggest({keyword: searchParams.query.substring(0, 2)}),
|
|
|
searchApi.getProductList(searchParams, 'fuzzySearch')
|
|
|
searchApi.getProductList(Object.assign({order: 'h_v_desc'}, searchParams), 'fuzzySearch')
|
|
|
];
|
|
|
|
|
|
return api.all(apiMethod).then(result => {
|
...
|
...
|
@@ -401,3 +402,50 @@ 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) => {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function * () {
|
|
|
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]);
|
|
|
|
|
|
params.query = redisData.name;
|
|
|
|
|
|
let resData = yield that.getSearchKeywordData(params, channel);
|
|
|
|
|
|
resData.queryKey = params.query;
|
|
|
|
|
|
if (!_.isEmpty(redisData.data)) {
|
|
|
_.forEach(redisData.data, value => {
|
|
|
if (!value) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
Object.assign(value, {
|
|
|
name: value.keyword,
|
|
|
href: helpers.urlFormat(`/chanpin/${value.id}.html`, null, 'www')
|
|
|
});
|
|
|
});
|
|
|
|
|
|
_.set(resData, 'search.leftContent.allSuggest.list', redisData.data);
|
|
|
}
|
|
|
|
|
|
return resData;
|
|
|
})();
|
|
|
}; |
...
|
...
|
|