Authored by htoooth

merge search

... ... @@ -20,6 +20,7 @@ const config = global.yoho.config;
*/
const index = (req, res, next) => {
let params = req.query;
let resData = {
title: '潮流商品搜索 | YOHO!BUY 有货',
keywords: 'Yoho! 有货,潮流,时尚,流行,购物,B2C,正品,购物网站,网上购物,货到付款,' +
... ... @@ -43,6 +44,7 @@ const index = (req, res, next) => {
return res.render('search/no-result', resData);
}
res.render('search/index', resData);
});
}).catch(next);
};
... ... @@ -141,27 +143,6 @@ const searchHistory = (req, res) => {
res.send(req.query.callback + '(' + JSON.stringify({ data }) + ')');
};
/**
* search 热门搜索和默认搜索
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
const searchRecommend = (req, res, next) => {
search.getSearchRecommend(req.yoho.channel, req.query).then(result => {
let dest = {
code: 200,
message: 'recommend',
data: result || ''
};
res.type('text/javascript');
res.send(req.query.callback + '(' + JSON.stringify(dest) + ')');
}).catch(next);
};
/**
* 搜索少或无 有可能喜欢
**/
... ... @@ -187,6 +168,6 @@ module.exports = {
suggest4Old,
searchFilterBrands,
searchHistory, // 搜索历史记录
searchRecommend, // 搜索框下方 热门搜索
searchLessRecommend
};
... ...
... ... @@ -421,21 +421,6 @@ const getBrands4Filter = (params) => {
};
/**
* 搜索 热门搜索和默认搜索
* @return
*/
const getSearchRecommend = (channel, params) => {
return api.get('', {
method: 'app.search.getTerms',
content: params.content || '',
yh_channel: channel,
sort: params.sort,
status: params.status,
type: params.type
}, config.apiCache);
};
/**
* 有可能喜欢的商品
* @param int $channel 频道,1代表男生,2代表女生,3代表潮童,4代表创意生活
... ... @@ -486,6 +471,5 @@ module.exports = {
getBrands4Filter,
getProductListOrig,
getSearchCacheKey,
getSearchRecommend,
lessRecommend
};
... ...
... ... @@ -222,50 +222,6 @@ exports.getBrands4Filter = (params) => {
return this.getListBrandsFilter(params, nparams);
};
/**
* 搜索 热门搜索和默认搜索
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.getSearchRecommend = (channel, params) => {
let channelNum = (function() {
switch (channel) {
case 'boys':
return 1;
case 'girls':
return 2;
case 'kids':
case 'lifestyle':
return 3;
default:
return 1;
}
}());
return searchApi.getSearchRecommend(channelNum, params).then((result) => {
if (result.code === 200) {
let resData = {
code: 200,
hotTerms: []
};
resData.hotTerms = _.map(result.data.hotTerms, (value) => {
return {
href: helpers.urlFormat('', {query: value.content}, 'search'),
content: value.content,
sort: value.sort,
status: value.status,
type: value.type
};
});
return resData;
} else {
return result;
}
});
};
/**
* 搜索少或无 可能喜欢
... ...
... ... @@ -89,7 +89,6 @@ router.get('/search/filter/brands', search.searchFilterBrands);
router.get('/search/suggest', search.suggest); // 搜索提示
router.get('/api/suggest', search.suggest4Old);
router.get('/search/history', search.searchHistory); // 搜索历史提示
router.get('/search/recommend', search.searchRecommend); // 热门搜索和默认搜索
router.get('/search/less/recommend', search.searchLessRecommend);// 搜索少或无 有可能喜欢
// 商品分类列表页
... ...
... ... @@ -17,14 +17,14 @@ module.exports = {
cookieDomain: '.yohobuy.com',
domains: {
// test3
//singleApi: 'http://api-test3.yohops.com:9999/',
//api: 'http://api-test3.yohops.com:9999/',
//service: 'http://service-test3.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
// prod
singleApi: 'http://single.yoho.cn/',
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
//singleApi: 'http://single.yoho.cn/',
//api: 'http://api.yoho.cn/',
//service: 'http://service.yoho.cn/',
// gray
// singleApi: 'http://single.gray.yohops.com/',
... ...
... ... @@ -10,6 +10,7 @@ const _ = require('lodash');
const api = global.yoho.API;
const serviceApi = global.yoho.ServiceAPI;
const helpers = global.yoho.helpers;
/**
* 获取菜单
... ... @@ -191,11 +192,14 @@ const setHeaderData = (resData, type) => (
);
const getHotSearchAsync = () => {
return api.get('', {method: 'app.search.getTerms'}, {
const getHotSearchAsync = (channel) => {
return api.get('', {method: 'app.search.getTerms', yh_channel: channel}, {
cache: 600,
code: 200
});
};
const getHeaderNavAsync = () => {
... ... @@ -215,9 +219,24 @@ exports.requestHeaderData = (type) => {
type = type || 'boys';
let channelNum = (function() {
switch (type) {
case 'boys':
return 1;
case 'girls':
return 2;
case 'kids':
case 'lifestyle':
return 3;
default:
return 1;
}
}());
return Promise.all([
getHeaderNavAsync(),
getHotSearchAsync()
getHotSearchAsync(channelNum)
]).then(res => {
resData.headerData = {};
... ... @@ -227,6 +246,15 @@ exports.requestHeaderData = (type) => {
if (res[1] && res[1].data) {
resData.headerData.defaultSearch = _.get(res[1], 'data.defaultTerms[0].content', '');
resData.headerData.hotTerms = _.map(_.get(res[1], 'data.hotTerms', []), (value) => {
return {
href: helpers.urlFormat('', {query: value.content}, 'search'),
content: value.content,
sort: value.sort,
status: value.status,
type: value.type
};
});
}
return resData;
... ...
... ... @@ -101,26 +101,14 @@
<a class="search-btn" href="javascript:submitSearch();"></a>
</form>
<ul class="search-hot">
<script type="text/html" id="search-suggest-recommend">
\{{#data}}
\{{#hotTerms}}
<li>
<a style="display: block;" href="\{{href}}" title="\{{content}}"
act="\{{href}}" target="_blank">
<span class="searchvalue">\{{content}}</span>
</a>
</li>
\{{/hotTerms}}
\{{#guessTerms}}
<li>
<a style="display: block;" href="\{{href}}" title="\{{content}}"
act="\{{href}}" target="_blank">
<span class="searchvalue">\{{content}}</span>
</a>
</li>
\{{/guessTerms}}
\{{/data}}
</script>
{{#hotTerms}}
<li>
<a style="display: block;" href="{{href}}" title="{{content}}"
act="{{href}}" target="_blank">
<span class="searchvalue">{{content}}</span>
</a>
</li>
{{/hotTerms}}
</ul>
</div>
... ...
No preview for this file type
... ... @@ -2,7 +2,7 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg xmlns="http://www.w3.org/2000/svg">
<metadata>
Created by FontForge 20120731 at Wed Mar 8 10:34:08 2017
Created by FontForge 20120731 at Mon Mar 6 13:49:44 2017
By admin
</metadata>
<defs>
... ...
No preview for this file type
No preview for this file type
... ... @@ -16,9 +16,7 @@ var $head = $('.head-wrapper'),
$logotrans = $head.find('.main-logo'),
$searchSug = $head.find('.search-suggest'),
$searchHistory = $head.find('.search-suggest-history'),
$searchRecommend = $head.find('.search-hot'),
$searchHistoryHbs = $('#search-suggest-history'),
$searchRecommendHbs = $head.find('#search-suggest-recommend'),
$goCart = $head.find('.go-cart'),
$myYohoBox = $('#myYohoBox'),
$goodsNum = $goCart.find('.goods-num-tip'),
... ... @@ -979,43 +977,6 @@ $searchKey.focus(function() {
}
});
/**
* 搜索 热门搜索 api
* @return {[type]} [description]
*/
function searchSuggestRecommend(channel, key) {
var param = {
channel: channel,
return_type: 'jsonp',
keyword: key
};
$.getJSON('//search.yohobuy.com/product/search/recommend?callback=?', param, function(jsonData) {
var searchSuggestRecommendHtml; //eslint-disable-line
if (jsonData.code === 200) {
searchSuggestRecommendHtml = handlebars.compile($searchRecommendHbs.html() || '');
$searchRecommend.html(searchSuggestRecommendHtml(jsonData)).show();
} else {
$searchRecommend.hide();
}
});
}
/**
* 搜索 热门搜索和默认搜索 dom
* @return {[type]} [description]
*/
$(function() {
searchSuggestRecommend();
});
actionCover();
actionAddKeyWords();
setTimeout(emailUserCertTip, 0);
... ...