Authored by OF1706

searchTerms sum

... ... @@ -118,14 +118,17 @@ const serachFilterBrands = (req, res, next) => {
const searchHistory = (req, res) => {
let history = req.cookies['_History'];
let q = req.query.query || '';
let history = _.trim(req.cookies['_History']);
let q = _.trim(decodeURIComponent(req.query.query) || '');
history = history ? history.split(',') : [];
history = _.reject(history, old => old === q ? true : false);
history.unshift(q);
res.cookie('_History', _.take(history, 9).join(','), {
if(q != ''){
history.unshift(q);
}
res.cookie('_History',_.take(history, 9).join(','), {
domain: config.cookieDomain,
maxAge: 60 * 60 * 24 * 1000 * 30 // 一月
});
... ... @@ -153,7 +156,7 @@ const searchHistory = (req, res) => {
* @return {[type]} [description]
*/
const searchRecommend = (req, res, next) => {
search.getSearchRecommend(req.query).then(result => {
search.getSearchRecommend(req.yoho.channel,req.query).then(result => {
if (req.query.json === '1') {
return res.send(result);
... ... @@ -162,7 +165,7 @@ const searchRecommend = (req, res, next) => {
let dest = {
code: 200,
message: 'recommend',
data: result || ''
data: result || '',
};
res.type('text/javascript');
... ...
... ... @@ -424,11 +424,12 @@ const getBrands4Filter = (params) => {
* 搜索 热门搜索和默认搜索
* @return
*/
const getSearchRecommend = (params) => {
const getSearchRecommend = (channel,params) => {
let finalParams = {
method: 'app.search.getTerms',
content: params.content || '',
yh_channel: channel,
sort: params.sort,
status: params.status,
type: params.type
... ...
... ... @@ -192,10 +192,30 @@ exports.getBrands4Filter = (params) => {
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.getSearchRecommend = (params) => {
return searchApi.getSearchRecommend(params).then(result => {
exports.getSearchRecommend = (channel,params) => {
return searchApi.getSearchRecommend(channel,params).then(result => {
if (result.code === 200) {
let channelNum = 1;
switch (channel) {
case 'boys':
channelNum = 1;
break;
case 'girls':
channelNum = 2;
break;
case 'kids':
channelNum = 3;
break;
case 'lifestyle':
channelNum = 3;
break;
default:
break;
}
let resData = {
hotTerms: [],
};
... ...
... ... @@ -97,7 +97,7 @@
<div class="search-2016">
<form action="//search.yohobuy.com" method="get" id="search-form">
<input type="hidden" id="defaultsearch" value="{{defaultSearch}}">
<input class="search-key" type="text" name="query" id="query-key" autocomplete="off" x-webkit-speech="" lang="zh-CN" x-webkit-grammar="builtin:translate" value="" maxlength="30">
<input class="search-key" type="text" name="query" id="query-key" autocomplete="off" x-webkit-speech="" lang="zh-CN" x-webkit-grammar="builtin:translate" value="" maxlength="30">
<a class="search-btn" href="javascript:submitSearch();"></a>
</form>
<ul class="search-hot">
... ... @@ -322,7 +322,7 @@
\{{/data}}
</script>
<script type="text/html" id="search-suggest-history">
<p class="search-suggest-title">最近搜过<a class="searchDel" href="#">删除</a></p>
<p class="search-suggest-title">最近搜过<a class="searchDel" href="#">清空</a></p>
\{{#data}}
<li>
<a style="display: block;" href="\{{href}}" class="clearfix clear search-item" title="\{{keyword}}"
... ...
... ... @@ -867,15 +867,15 @@ function actionAddKeyWords() {
function searchSuggestHistory() {
let $queryKey = $('#query-key');
$.getJSON('//search.yohobuy.com/product/search/history?query=' + $queryKey.val(), function(jsonData) {
$.getJSON('//search.yohobuy.com/product/search/history?query=' + encodeURIComponent($queryKey.val()), function(jsonData) {
var searchSuggestHistoryHtml;
searchSuggestHistoryHtml = handlebars.compile($searchHistoryHbs.html() || '');
$searchHistory.html(searchSuggestHistoryHtml(jsonData)).show();
$(".search-suggest-title .searchDel").click(function(){
console.log("****&&&&&&&&&&&");
window.setCookie('_History','',{domain:'.yohobuy.com'});
$(this).closest('.search-suggest-history').hide();
return false;
});
});
... ... @@ -885,20 +885,38 @@ function searchSuggestHistory() {
* 搜索 历史记录 dom
* @return {[type]} [description]
*/
$searchKey.keydown(function() {
}).focus(function() {
}).focus(function(e) {
var val = $.trim($(this).val());
searchSuggestHistory();
if (val === '') {
if ($searchHistory && $searchHistory.length) {
val = val.replace(new RegExp('\'', 'gm'), ''); // 去掉特殊字符
searchSuggestHistory(val);
// if(e.keyCode === 13){
var val = $.trim($(this).val());
searchSuggestHistory();
if (val === '') {
if ($searchHistory && $searchHistory.length) {
val = val.replace(new RegExp('\'', 'gm'), ''); // 去掉特殊字符
searchSuggestHistory(val);
}
}
}
// }
});
// $searchKey.keydown(function() {
//
// }).focus(function() {
//
// var val = $.trim($(this).val());
// searchSuggestHistory();
// if (val === '') {
// if ($searchHistory && $searchHistory.length) {
// val = val.replace(new RegExp('\'', 'gm'), ''); // 去掉特殊字符
// searchSuggestHistory(val);
// }
// }
// });
/**
* 搜索 热门搜索和默认搜索 api
* @return {[type]} [description]
... ...