Authored by 郝肖肖

关键词接口逻辑更改

@@ -20,9 +20,8 @@ const list = (req, res, next) => { @@ -20,9 +20,8 @@ const list = (req, res, next) => {
20 let params = Object.assign({ 20 let params = Object.assign({
21 isSearch: true, // 搜索列表将最新改成默认的标识 21 isSearch: true, // 搜索列表将最新改成默认的标识
22 cartUrl: helpers.urlFormat('/cart/index/index') 22 cartUrl: helpers.urlFormat('/cart/index/index')
23 - }, req.query); 23 + }, req.query, {query: (req.query.query || '').toString()});
24 let title = ''; 24 let title = '';
25 - let query = (req.query.query || '').toString();  
26 let isQueryFirstClass = false; // 标识用户搜的是不是一级品类 25 let isQueryFirstClass = false; // 标识用户搜的是不是一级品类
27 let isQuerySecondClass = false; // 标识用户搜的是不是二级品类 26 let isQuerySecondClass = false; // 标识用户搜的是不是二级品类
28 let domain = null; 27 let domain = null;
@@ -32,7 +31,6 @@ const list = (req, res, next) => { @@ -32,7 +31,6 @@ const list = (req, res, next) => {
32 params.shopId = params.shop_id; 31 params.shopId = params.shop_id;
33 } 32 }
34 33
35 - params.query = query;  
36 params.isApp = req.yoho.isApp; 34 params.isApp = req.yoho.isApp;
37 params.physical_channel = req.yoho.channel && searchProcess.getChannelType(req.yoho.channel); 35 params.physical_channel = req.yoho.channel && searchProcess.getChannelType(req.yoho.channel);
38 36
@@ -50,36 +48,30 @@ const list = (req, res, next) => { @@ -50,36 +48,30 @@ const list = (req, res, next) => {
50 limit: 12 48 limit: 12
51 }, params); 49 }, params);
52 50
53 - if (query) {  
54 - query = query.toLowerCase();  
55 - }  
56 -  
57 if (uid) { 51 if (uid) {
58 initialData.uid = uid; 52 initialData.uid = uid;
59 } 53 }
60 54
61 /* 判断是不是品牌, 是品牌跳到品牌列表页(显示搜索框),判断是不是品类, 是品类加导航标题(不显示搜索框) */ 55 /* 判断是不是品牌, 是品牌跳到品牌列表页(显示搜索框),判断是不是品类, 是品类加导航标题(不显示搜索框) */
62 return Promise.all([ 56 return Promise.all([
63 - searchModel.getBrandDomain(query), 57 + searchModel.getBrandDomain(params.query.toLowerCase()),
64 searchModel.getClassNames(), 58 searchModel.getClassNames(),
65 searchModel.getSearchData(initialData) 59 searchModel.getSearchData(initialData)
66 ]).then(result => { 60 ]).then(result => {
67 61
68 // 推荐词条件判断 redmine: 18567 62 // 推荐词条件判断 redmine: 18567
69 - if (params.needSuggestion !== 'Y' &&  
70 - result[2] && result[2].list.length <= 0 &&  
71 - result[2].termsSuggestion && result[2].termsSuggestion.length) {  
72 - return res.redirect(result[2].termsSuggestion[0].link); 63 + if (result[2].isNeedSuggestion && result[2].termsSuggestion && result[2].termsSuggestion[0].name) {
  64 + params.query = result[2].termsSuggestion[0].name;
73 } 65 }
74 66
75 - if (query) { 67 + if (params.query) {
76 domain = result[0]; 68 domain = result[0];
77 69
78 // 跳转到品牌商品列表页 70 // 跳转到品牌商品列表页
79 if (domain !== null && !params.shop_id) { 71 if (domain !== null && !params.shop_id) {
80 let urlPro = { 72 let urlPro = {
81 from: 'search', 73 from: 'search',
82 - query: query 74 + query: params.query
83 }; 75 };
84 76
85 if (req.query.app_type) { 77 if (req.query.app_type) {
@@ -100,7 +92,7 @@ const list = (req, res, next) => { @@ -100,7 +92,7 @@ const list = (req, res, next) => {
100 92
101 _.forEach(result[1].first, (obj) => { 93 _.forEach(result[1].first, (obj) => {
102 // 精确查一级品类 94 // 精确查一级品类
103 - if (obj === query) { 95 + if (obj === params.query) {
104 isQueryFirstClass = true; 96 isQueryFirstClass = true;
105 return false; 97 return false;
106 } 98 }
@@ -108,7 +100,7 @@ const list = (req, res, next) => { @@ -108,7 +100,7 @@ const list = (req, res, next) => {
108 100
109 _.forEach(result[1].second, (obj) => { 101 _.forEach(result[1].second, (obj) => {
110 // 精确查二级品类 102 // 精确查二级品类
111 - if (obj === query) { 103 + if (obj === params.query) {
112 isQuerySecondClass = true; 104 isQuerySecondClass = true;
113 return false; 105 return false;
114 } 106 }
@@ -119,13 +111,13 @@ const list = (req, res, next) => { @@ -119,13 +111,13 @@ const list = (req, res, next) => {
119 111
120 // 搜索是一级品类 112 // 搜索是一级品类
121 if (isQueryFirstClass) { 113 if (isQueryFirstClass) {
122 - title = '全部' + query; 114 + title = '全部' + params.query;
123 } else if (isQuerySecondClass) { // 搜索是二级品类 115 } else if (isQuerySecondClass) { // 搜索是二级品类
124 - title = query; 116 + title = params.query;
125 } else { // 搜索其它内容 117 } else { // 搜索其它内容
126 - if (query || params.form) { 118 + if (params.query || params.form) {
127 params.search = { 119 params.search = {
128 - default: query === '' ? false : query, 120 + default: params.query === '' ? false : params.query,
129 url: helpers.urlFormat('', null, 'search') 121 url: helpers.urlFormat('', null, 'search')
130 }; 122 };
131 } 123 }
@@ -199,13 +199,19 @@ const getSearchData = (params) => { @@ -199,13 +199,19 @@ const getSearchData = (params) => {
199 } 199 }
200 200
201 // 推荐词条件判断 redmine: 18567 201 // 推荐词条件判断 redmine: 18567
202 - if (params.page === 1 && (result.data.total <= 20 || params.needSuggestion === 'Y')) {  
203 - newList.isNeedSuggestion = params.needSuggestion === 'Y'; // 是否是关键词搜索判断 202 + if (params.page === 1 && (result.data.isChangedQuery === 'Y' ||
  203 + result.data.total <= 20 || params.needSuggestion === 'Y')) {
  204 +
  205 + params.isChangedQuery = result.data.isChangedQuery === 'Y';
  206 +
  207 + newList.isNeedSuggestion = params.isChangedQuery ||
  208 + params.needSuggestion === 'Y'; // 是否是关键词搜索判断
204 newList.termsSuggestion = productProcess.termsSuggestion(result.data.suggestion && 209 newList.termsSuggestion = productProcess.termsSuggestion(result.data.suggestion &&
205 - result.data.suggestion.terms_suggestion ||  
206 - ['卫衣', 'vans', '新款', 'VANS 卫衣', 'VANS 休闲'], params); 210 + result.data.suggestion.terms_suggestion || [], params);
  211 + // 如果只有一个<或者试试不显示>
  212 + newList.isNeedSuggestionOne = newList.termsSuggestion.length > 1;
207 213
208 - newList.isMaybeLike = params.needSuggestion === 'Y' && 214 + newList.isMaybeLike = (params.isChangedQuery === 'Y' || params.needSuggestion === 'Y') &&
209 result.data.total > 0 ? false : true; // 猜你喜欢显示不显示判断 215 result.data.total > 0 ? false : true; // 猜你喜欢显示不显示判断
210 } 216 }
211 217
@@ -145,7 +145,7 @@ @@ -145,7 +145,7 @@
145 {{#if @root.firstPageGoods.isNeedSuggestion}} 145 {{#if @root.firstPageGoods.isNeedSuggestion}}
146 {{#each @root.firstPageGoods.termsSuggestion}} 146 {{#each @root.firstPageGoods.termsSuggestion}}
147 {{#if select}} 147 {{#if select}}
148 - 没有找到相关商品,为您推荐"{{name}}"的搜索结果或者试试 148 + 没有找到相关商品,为您推荐"{{name}}"的搜索结果{{#if @root.firstPageGoods.isNeedSuggestionOne}}或者试试{{/if}}
149 {{/if}} 149 {{/if}}
150 {{/each}} 150 {{/each}}
151 {{else}} 151 {{else}}
@@ -10,15 +10,15 @@ const isProduction = process.env.NODE_ENV === 'production'; @@ -10,15 +10,15 @@ const isProduction = process.env.NODE_ENV === 'production';
10 const isTest = process.env.NODE_ENV === 'test'; 10 const isTest = process.env.NODE_ENV === 'test';
11 11
12 const domains = { 12 const domains = {
13 - api: 'http://api-test3.yohops.com:9999/',  
14 - service: 'http://service-test3.yohops.com:9999/',  
15 - liveApi: 'http://testapi.live.yohops.com:9999/',  
16 - singleApi: 'http://api-test3.yohops.com:9999/', 13 + // api: 'http://api-test3.yohops.com:9999/',
  14 + // service: 'http://service-test3.yohops.com:9999/',
  15 + // liveApi: 'http://testapi.live.yohops.com:9999/',
  16 + // singleApi: 'http://api-test3.yohops.com:9999/',
17 17
18 - // api: 'http://dev-api.yohops.com:9999/',  
19 - // service: 'http://dev-service.yohops.com:9999/',  
20 - // liveApi: 'http://api.live.yoho.cn/',  
21 - // singleApi: 'http://single.yoho.cn/', 18 + api: 'http://dev-api.yohops.com:9999/',
  19 + service: 'http://dev-service.yohops.com:9999/',
  20 + liveApi: 'http://api.live.yoho.cn/',
  21 + singleApi: 'http://single.yoho.cn/',
22 22
23 imSocket: 'wss://imsocket.yohobuy.com:443', 23 imSocket: 'wss://imsocket.yohobuy.com:443',
24 imCs: 'https://imhttp.yohobuy.com/api', 24 imCs: 'https://imhttp.yohobuy.com/api',
@@ -241,7 +241,7 @@ gender = getQueryString('gender'); @@ -241,7 +241,7 @@ gender = getQueryString('gender');
241 price = getQueryString('price'); 241 price = getQueryString('price');
242 p_d = getQueryString('p_d'); 242 p_d = getQueryString('p_d');
243 brand = getQueryString('brand'); 243 brand = getQueryString('brand');
244 -query = getQueryString('query'); 244 +query = $('.query-param[data-attr="query"]').val() || getQueryString('query');
245 limited = getQueryString('limited'); 245 limited = getQueryString('limited');
246 specialoffer = getQueryString('specialoffer'); 246 specialoffer = getQueryString('specialoffer');
247 specialsale_id = getQueryString('specialsale_id'); 247 specialsale_id = getQueryString('specialsale_id');
@@ -351,9 +351,9 @@ @@ -351,9 +351,9 @@
351 /* 搜索数据太小,分词 */ 351 /* 搜索数据太小,分词 */
352 .list-too-little { 352 .list-too-little {
353 padding: 25px 20px; 353 padding: 25px 20px;
354 - color: #4b4b4b;  
355 - font-size: 16px;  
356 border-bottom: 1px solid #e6e6e6; 354 border-bottom: 1px solid #e6e6e6;
  355 + color: #444;
  356 + font-size: 24px;
357 357
358 .word { 358 .word {
359 display: inline-block; 359 display: inline-block;
@@ -205,11 +205,12 @@ exports.processProductList = (list, options) => { @@ -205,11 +205,12 @@ exports.processProductList = (list, options) => {
205 exports.termsSuggestion = (list, options) => { 205 exports.termsSuggestion = (list, options) => {
206 let termsSuggestion = []; 206 let termsSuggestion = [];
207 207
208 - _.each(list, (terms) => { 208 + _.each(list, (terms, index) => {
209 termsSuggestion.push({ 209 termsSuggestion.push({
210 name: terms, 210 name: terms,
211 link: helpers.urlFormat('/', {needSuggestion: 'Y', query: terms}, 'search'), 211 link: helpers.urlFormat('/', {needSuggestion: 'Y', query: terms}, 'search'),
212 - select: options.needSuggestion === 'Y' && terms === decodeURIComponent(options.query) 212 + select: (options.isChangedQuery && index === 0) ||
  213 + (options.needSuggestion === 'Y' && terms === decodeURIComponent(options.query))
213 }); 214 });
214 }); 215 });
215 216