...
|
...
|
@@ -20,7 +20,6 @@ const config = global.yoho.config; |
|
|
*/
|
|
|
const index = (req, res, next) => {
|
|
|
let params = req.query;
|
|
|
|
|
|
let resData = {
|
|
|
title: '潮流商品搜索 | YOHO!BUY 有货',
|
|
|
keywords: 'Yoho! 有货,潮流,时尚,流行,购物,B2C,正品,购物网站,网上购物,货到付款,' +
|
...
|
...
|
@@ -44,7 +43,6 @@ const index = (req, res, next) => { |
|
|
return res.render('search/no-result', resData);
|
|
|
}
|
|
|
res.render('search/index', resData);
|
|
|
|
|
|
});
|
|
|
}).catch(next);
|
|
|
};
|
...
|
...
|
@@ -97,7 +95,7 @@ const suggest4Old = (req, res, next) => { |
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
const serachFilterBrands = (req, res, next) => {
|
|
|
const searchFilterBrands = (req, res, next) => {
|
|
|
search.getBrands4Filter(Object.assign({}, req.query, {
|
|
|
keyword: req.query.query || ''
|
|
|
})).then(result => {
|
...
|
...
|
@@ -119,15 +117,10 @@ const serachFilterBrands = (req, res, next) => { |
|
|
*/
|
|
|
|
|
|
const searchHistory = (req, res) => {
|
|
|
let history = req.cookies['_History'] || ''; //eslint-disable-line
|
|
|
let q = req.query.query ? _.trim(decodeURIComponent(req.query.query)) : '';
|
|
|
|
|
|
let history = _.trim(req.cookies['_History']); //eslint-disable-line
|
|
|
let q = _.trim(decodeURIComponent(req.query.query));
|
|
|
|
|
|
let data = [];
|
|
|
let ResData = {};
|
|
|
|
|
|
history = history ? history.split(',') : [];
|
|
|
history = _.reject(history, old => old === q ? true : false);
|
|
|
history = _.filter(history.split(','), old => old && old !== q);
|
|
|
|
|
|
if (q) {
|
|
|
history.unshift(q);
|
...
|
...
|
@@ -137,20 +130,15 @@ const searchHistory = (req, res) => { |
|
|
});
|
|
|
}
|
|
|
|
|
|
_.forEach(history, function(item) {
|
|
|
if (item !== 'undefined') {
|
|
|
let list = {};
|
|
|
|
|
|
list['keyword'] = item; //eslint-disable-line
|
|
|
list['href'] = helpers.urlFormat('', {query: list['keyword']}, 'search'); //eslint-disable-line
|
|
|
data.push(list);
|
|
|
}
|
|
|
let data = _.map(history, (item) => {
|
|
|
return {
|
|
|
keyword: item,
|
|
|
href: helpers.urlFormat('', {query: item}, 'search')
|
|
|
};
|
|
|
});
|
|
|
ResData['data'] = data; //eslint-disable-line
|
|
|
|
|
|
res.type('text/javascript');
|
|
|
res.send(req.query.callback + '(' + JSON.stringify(ResData) + ')');
|
|
|
|
|
|
res.send(req.query.callback + '(' + JSON.stringify({ data }) + ')');
|
|
|
};
|
|
|
|
|
|
|
...
|
...
|
@@ -162,11 +150,6 @@ const searchHistory = (req, res) => { |
|
|
*/
|
|
|
const searchRecommend = (req, res, next) => {
|
|
|
search.getSearchRecommend(req.yoho.channel, req.query).then(result => {
|
|
|
|
|
|
if (req.query.json === '1') {
|
|
|
return res.send(result);
|
|
|
}
|
|
|
|
|
|
let dest = {
|
|
|
code: 200,
|
|
|
message: 'recommend',
|
...
|
...
|
@@ -179,32 +162,11 @@ const searchRecommend = (req, res, next) => { |
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 搜索少或无 有可能喜欢
|
|
|
**/
|
|
|
const searchLessRecommend = (req, res, next) => {
|
|
|
let channel = req.yoho.channel;
|
|
|
let uid = req.user.uid;
|
|
|
let udid = req.yoho.udid;
|
|
|
let page = Number(req.query.page || 1);
|
|
|
|
|
|
if (page <= 0 || page >= 6) {
|
|
|
page = 1;
|
|
|
}
|
|
|
|
|
|
search.getSearchLessProduct(channel, uid, udid, page).then(result => {
|
|
|
return res.send(result);
|
|
|
}).catch(next);
|
|
|
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
index,
|
|
|
suggest,
|
|
|
suggest4Old,
|
|
|
serachFilterBrands,
|
|
|
searchHistory,
|
|
|
searchRecommend,
|
|
|
searchLessRecommend
|
|
|
searchFilterBrands,
|
|
|
searchHistory, // 搜索历史记录
|
|
|
searchRecommend // 搜索框下方 热门搜索
|
|
|
}; |
|
|
|
...
|
...
|
|