Authored by 周少峰

Merge branch 'feature/recList2.0' into gray

... ... @@ -200,6 +200,35 @@ const keyword = (req, res, next) => {
}).catch(next);
};
/**
* 搜索推荐列表页
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
const keyId = (req, res, next) => {
let params = req.query;
let id = req.params.id;
return search.getSearchKeywordDataById(id, params, req.yoho.channel).then(result => {
let query = result.queryKey;
Object.assign(result, {
pageNoFollow: true,
title: `${query}价格_图片_品牌_怎么样-YOHO!BUY有货`,
keywords: `${query},${query}价格,${query}图片,${query}怎么样,${query}品牌,YOHO!BUY有货`,
description: `YOHO!BUY有货网yohobuy.com是国内专业的${query}网上潮流购物商城,为您找到${_.get(result,
'search.totalCount', 0)}${query}、产品的详细参数,实时报价,价格行情,图片、评价、品牌等信息。买${query},就上YOHO!BUY有货`
});
if (!_.get(result, 'search.goods') || !_.get(result, 'search.goods').length) {
_.set(result, 'search.keyWord', query);
return res.render('search/no-result', result);
}
res.render('search/index', result);
}).catch(next);
};
module.exports = {
index,
suggest,
... ... @@ -207,6 +236,7 @@ module.exports = {
searchFilterBrands,
searchHistory, // 搜索历史记录
searchLessRecommend,
keyword
keyword,
keyId
};
... ...
... ... @@ -1788,7 +1788,11 @@ exports.handleSuggestData = (origin, query) => {
});
});
leftContent.allSuggest = {all: all, list: list};
leftContent.allSuggest = {
all: all,
title: '相关推荐',
list: list
};
return leftContent;
};
... ...
... ... @@ -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;
})();
};
... ...
... ... @@ -103,6 +103,7 @@ router.get('/api/suggest', search.suggest4Old);
router.get('/search/history', search.searchHistory); // 搜索历史提示
router.get('/search/less/recommend', search.searchLessRecommend);// 搜索少或无 有可能喜欢
router.get('/search/keyword/:id', search.keyword);
router.get('/search/chanpin/:id', search.keyId);
// 商品分类列表页
router.get('/list/index', gbk2utf, list.index);
... ...
... ... @@ -77,6 +77,13 @@ module.exports = [
target: (req, match, p1) => `/product/search/keyword/${p1}`
},
// 推荐词id列表页
{
type: TYPE.rewrite,
origin: /^\/chanpin\/(.*)\.html(.*)/,
target: (req, match, p1) => `/product/search/chanpin/${p1}`
},
// erp2good
{
type: TYPE.rewrite,
... ...
const _ = require('lodash');
const redis = require('redis');
const bluebird = require('bluebird');
const config = require('../../config/common');
... ... @@ -9,6 +11,18 @@ try {
bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);
client.all = args => {
if (!client.ready) {
if (Array.isArray(args)) {
return Promise.resolve(_.fill(args, false));
} else {
return Promise.resolve(false);
}
}
return client.multi.call(client, args).execAsync();
};
client.on('error', function() {
global.yoho.redis = '';
});
... ... @@ -20,6 +34,4 @@ try {
global.yoho.redis = '';
}
module.exports = client;
... ...
... ... @@ -36,7 +36,7 @@
</div>
<div class="good-detail-img">
<a class="good-thumb" href="{{url}}" target="_blank">
<img class="lazy" data-original="{{image2 thumb w=280 h=382}}">
<img class="lazy" alt="{{product_name}}" data-original="{{image2 thumb w=280 h=382}}">
</a>
{{# is_few}}
<p class="few-tag">即将售罄</p>
... ...
... ... @@ -89,6 +89,9 @@
{{!-- 搜索推荐--}}
{{# allSuggest}}
<div class="sort-container">
{{# title}}
<h2 class="nav-pic-title">{{.}}</h2>
{{/ title}}
<ul class="sort-child-list suggest-list">
{{#each list}}
<li>
... ... @@ -140,4 +143,4 @@
{{/each}}
</ul>
</div>
{{/signboard}}
\ No newline at end of file
{{/signboard}}
... ...
{
"name": "yohobuy-node",
"version": "5.8.7",
"version": "5.8.8",
"private": true,
"description": "A New Yohobuy Project With Express",
"repository": {
... ...
... ... @@ -84,6 +84,10 @@
padding-left: 5px;
color: #bbb;
}
&:first-child {
margin-top: 4px;
}
}
a {
... ... @@ -93,7 +97,6 @@
white-space: nowrap;
display: block;
color: #666;
padding-left: 10px;
height: 22px;
line-height: 22px;
}
... ...