Authored by OF1706

searchTerms sum

... ... @@ -120,27 +120,29 @@ const searchHistory = (req, res) => {
let history = _.trim(req.cookies['_History']);
let q = _.trim(decodeURIComponent(req.query.query) || '');
let data = [];
let list = {};
let ResData = {};
history = history ? history.split(',') : [];
history = _.reject(history, old => old === q ? true : false);
if(q != ''){
if (q !== '') {
history.unshift(q);
}
res.cookie('_History',_.take(history, 9).join(','), {
res.cookie('_History', _.take(history, 9).join(','), {
domain: config.cookieDomain,
maxAge: 60 * 60 * 24 * 1000 * 30 // 一月
});
let data = [];
_.forEach(history, function(item) {
let list = {};
list['keyword'] = item;
list['href'] = helpers.urlFormat('', {query: list['keyword']}, 'search')
list['href'] = helpers.urlFormat('', {query: list['keyword']}, 'search');
data.push(list);
});
let ResData = {};
ResData['data'] = data;
res.type('text/plain');
... ... @@ -156,7 +158,7 @@ const searchHistory = (req, res) => {
* @return {[type]} [description]
*/
const searchRecommend = (req, res, next) => {
search.getSearchRecommend(req.yoho.channel,req.query).then(result => {
search.getSearchRecommend(req.yoho.channel, req.query).then(result => {
if (req.query.json === '1') {
return res.send(result);
... ... @@ -165,7 +167,7 @@ const searchRecommend = (req, res, next) => {
let dest = {
code: 200,
message: 'recommend',
data: result || '',
data: result || ''
};
res.type('text/javascript');
... ...
... ... @@ -424,7 +424,7 @@ const getBrands4Filter = (params) => {
* 搜索 热门搜索和默认搜索
* @return
*/
const getSearchRecommend = (channel,params) => {
const getSearchRecommend = (channel, params) => {
let finalParams = {
method: 'app.search.getTerms',
... ...
... ... @@ -192,12 +192,12 @@ exports.getBrands4Filter = (params) => {
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.getSearchRecommend = (channel,params) => {
return searchApi.getSearchRecommend(channel,params).then(result => {
exports.getSearchRecommend = (channel, params) => {
return searchApi.getSearchRecommend(channel, params).then(result => {
if (result.code === 200) {
let channelNum = 1;
let channelNum = 1; // -eslint-disable-line
switch (channel) {
case 'boys':
... ... @@ -217,7 +217,7 @@ exports.getSearchRecommend = (channel,params) => {
}
let resData = {
hotTerms: [],
hotTerms: []
};
resData.hotTerms = _.map(result.data.hotTerms, function(value) {
... ... @@ -226,12 +226,12 @@ exports.getSearchRecommend = (channel,params) => {
content: value.content,
sort: value.sort,
status: value.status,
type: value.type,
type: value.type
};
});
return resData;
}else{
} else {
return result;
}
... ...
... ... @@ -867,14 +867,16 @@ function actionAddKeyWords() {
function searchSuggestHistory() {
let $queryKey = $('#query-key');
$.getJSON('//search.yohobuy.com/product/search/history?query=' + encodeURIComponent($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(){
window.setCookie('_History','',{domain:'.yohobuy.com'});
$('.search-suggest-title .searchDel').click(function() {
window.setCookie('_History', '', {domain: '.yohobuy.com'});
$(this).closest('.search-suggest-history').hide();
return false;
});
... ... @@ -888,10 +890,11 @@ function searchSuggestHistory() {
$searchKey.keydown(function() {
}).focus(function(e) {
}).focus(function() {
// if(e.keyCode === 13){
var val = $.trim($(this).val());
searchSuggestHistory();
if (val === '') {
if ($searchHistory && $searchHistory.length) {
... ... @@ -899,24 +902,11 @@ $searchKey.keydown(function() {
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]
... ...