...
|
...
|
@@ -11,12 +11,54 @@ const headerModel = require('../../../doraemon/models/header'); |
|
|
const searchModel = require(`${mRoot}/search`);
|
|
|
const _ = require('lodash');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const stringProcess = require(`${utils}/string-process`);
|
|
|
const searchProcess = require(`${utils}/search-process`);
|
|
|
const productProcess = require(`${utils}/product-process`);
|
|
|
const listParamsProcess = require(`${utils}/list-params-process`);
|
|
|
const co = require('bluebird').coroutine;
|
|
|
|
|
|
/**
|
|
|
* 搜索主页
|
|
|
*/
|
|
|
exports.index = (req, res, next) => {
|
|
|
let title = '搜索',
|
|
|
uid = req.user.uid || 0;
|
|
|
|
|
|
((render) => {
|
|
|
if (_.get(req, 'app.locals.wap.search.removeHotSearch', false)) {
|
|
|
render([]);
|
|
|
} else {
|
|
|
|
|
|
req.ctx(searchModel).getSearchIndex({
|
|
|
gender: req.yoho.channel || 'boys',
|
|
|
uid: uid
|
|
|
}).then((result) => {
|
|
|
render(result);
|
|
|
}).catch(next);
|
|
|
}
|
|
|
|
|
|
})((result) => {
|
|
|
res.render('search/index', Object.assign({
|
|
|
module: 'product',
|
|
|
page: 'search-index',
|
|
|
pageHeader: headerModel.setNav({
|
|
|
navTitle: title
|
|
|
}),
|
|
|
pageFooter: true,
|
|
|
width750: true,
|
|
|
search: {
|
|
|
defaultTerms: (result && result.defaultTerms && result.defaultTerms.length) ?
|
|
|
result.defaultTerms[0].content : '',
|
|
|
url: helpers.urlFormat('', null, 'search'),
|
|
|
hotTerms: result.hotTerms,
|
|
|
wantTerms: result.guessTerms
|
|
|
}
|
|
|
|
|
|
}, searchProcess.getListSeoData()));
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 搜索落地页
|
|
|
*/
|
|
|
exports.list = (req, res, next) => {
|
...
|
...
|
@@ -27,8 +69,7 @@ exports.list = (req, res, next) => { |
|
|
let title = '';
|
|
|
let isQueryFirstClass = false; // 标识用户搜的是不是一级品类
|
|
|
let isQuerySecondClass = false; // 标识用户搜的是不是二级品类
|
|
|
// let domain = null;
|
|
|
let uid = req.user.uid || 0;
|
|
|
let uid = req.user.uid;
|
|
|
|
|
|
if (params.shop_id) {
|
|
|
params.shopId = params.shop_id;
|
...
|
...
|
@@ -76,26 +117,6 @@ exports.list = (req, res, next) => { |
|
|
}
|
|
|
|
|
|
if (params.query) {
|
|
|
// domain = result[0];
|
|
|
|
|
|
// 跳转到品牌商品列表页
|
|
|
// if (domain !== null && !params.shop_id) {
|
|
|
// let urlPro = {
|
|
|
// from: 'search',
|
|
|
// query: params.query
|
|
|
// };
|
|
|
|
|
|
// if (req.query.app_type) {
|
|
|
// urlPro = _.assign(urlPro, {
|
|
|
// app_type: req.query.app_type
|
|
|
// });
|
|
|
// }
|
|
|
|
|
|
// let url = helpers.urlFormat('', urlPro, domain);
|
|
|
|
|
|
// return res.redirect(url);
|
|
|
// }
|
|
|
|
|
|
// 品类名称为空时跳出
|
|
|
if (!result[1]) {
|
|
|
return;
|
...
|
...
|
@@ -141,6 +162,7 @@ exports.list = (req, res, next) => { |
|
|
_noLazy: true,
|
|
|
module: 'product',
|
|
|
page: 'search-list',
|
|
|
localCss: true,
|
|
|
pageHeader: headerModel.setNav({
|
|
|
navTitle: title
|
|
|
}),
|
...
|
...
|
@@ -157,47 +179,6 @@ exports.list = (req, res, next) => { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 搜索主页
|
|
|
*/
|
|
|
exports.index = (req, res, next) => {
|
|
|
let title = '搜索',
|
|
|
uid = req.user.uid || 0;
|
|
|
|
|
|
((render) => {
|
|
|
if (_.get(req, 'app.locals.wap.search.removeHotSearch', false)) {
|
|
|
render([]);
|
|
|
} else {
|
|
|
|
|
|
req.ctx(searchModel).getSearchIndex({
|
|
|
gender: req.yoho.channel || 'boys',
|
|
|
uid: uid
|
|
|
}).then((result) => {
|
|
|
render(result);
|
|
|
}).catch(next);
|
|
|
}
|
|
|
|
|
|
})((result) => {
|
|
|
res.render('search/index', Object.assign({
|
|
|
module: 'product',
|
|
|
page: 'search-index',
|
|
|
pageHeader: headerModel.setNav({
|
|
|
navTitle: title
|
|
|
}),
|
|
|
pageFooter: true,
|
|
|
width750: true,
|
|
|
search: {
|
|
|
defaultTerms: (result && result.defaultTerms && result.defaultTerms.length) ?
|
|
|
result.defaultTerms[0].content : '',
|
|
|
url: helpers.urlFormat('', null, 'search'),
|
|
|
hotTerms: result.hotTerms,
|
|
|
wantTerms: result.guessTerms
|
|
|
}
|
|
|
|
|
|
}, searchProcess.getListSeoData()));
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 联动搜索
|
|
|
*/
|
|
|
exports.fuzzyDatas = (req, res, next) => {
|
...
|
...
|
@@ -213,12 +194,6 @@ exports.fuzzyDatas = (req, res, next) => { |
|
|
* ajax 商品数据请求
|
|
|
*/
|
|
|
exports.search = (req, res, next) => {
|
|
|
let allowOrigin = _.get(req, 'headers.origin', null) ?
|
|
|
req.headers.origin : req.protocol + '://' + req.headers.host;
|
|
|
|
|
|
res.setHeader('Access-Control-Allow-Origin', allowOrigin);
|
|
|
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
|
|
|
|
|
let params = Object.assign({}, req.query);
|
|
|
let uid = req.user.uid || 0;
|
|
|
|
...
|
...
|
@@ -226,8 +201,13 @@ exports.search = (req, res, next) => { |
|
|
params.uid = uid;
|
|
|
}
|
|
|
|
|
|
if (params.query) {
|
|
|
params.query = stringProcess.decodeURIComponent(params.query);
|
|
|
}
|
|
|
|
|
|
params.isApp = req.yoho.isApp;
|
|
|
params.limit = 24;
|
|
|
params.physical_channel = req.yoho.channel && searchProcess.getChannelType(req.yoho.channel);
|
|
|
|
|
|
req.ctx(searchModel).getSearchData(params).then((result) => {
|
|
|
|
...
|
...
|
|