Showing
6 changed files
with
92 additions
and
42 deletions
@@ -112,7 +112,7 @@ const serachFilterBrands = (req, res, next) => { | @@ -112,7 +112,7 @@ const serachFilterBrands = (req, res, next) => { | ||
112 | * @param {[type]} res [description] | 112 | * @param {[type]} res [description] |
113 | * @return {[type]} [description] | 113 | * @return {[type]} [description] |
114 | */ | 114 | */ |
115 | -const suggestHistory = (req, res, next) => { | 115 | +const searchHistory = (req, res, next) => { |
116 | search.getSearchHistory(req.query).then(result => { | 116 | search.getSearchHistory(req.query).then(result => { |
117 | 117 | ||
118 | if (req.query.json === '1') { | 118 | if (req.query.json === '1') { |
@@ -121,7 +121,7 @@ const suggestHistory = (req, res, next) => { | @@ -121,7 +121,7 @@ const suggestHistory = (req, res, next) => { | ||
121 | 121 | ||
122 | let dest = { | 122 | let dest = { |
123 | code: 200, | 123 | code: 200, |
124 | - message: 'suggest', | 124 | + message: 'history', |
125 | data: result || '' | 125 | data: result || '' |
126 | }; | 126 | }; |
127 | 127 | ||
@@ -138,16 +138,17 @@ const suggestHistory = (req, res, next) => { | @@ -138,16 +138,17 @@ const suggestHistory = (req, res, next) => { | ||
138 | * @param {[type]} res [description] | 138 | * @param {[type]} res [description] |
139 | * @return {[type]} [description] | 139 | * @return {[type]} [description] |
140 | */ | 140 | */ |
141 | -const suggestRecommend = (req, res, next) => { | 141 | +const searchRecommend = (req, res, next) => { |
142 | search.getSearchRecommend(req.query).then(result => { | 142 | search.getSearchRecommend(req.query).then(result => { |
143 | 143 | ||
144 | + // console.log(JSON.stringify(result)); | ||
144 | if (req.query.json === '1') { | 145 | if (req.query.json === '1') { |
145 | return res.send(result); | 146 | return res.send(result); |
146 | } | 147 | } |
147 | 148 | ||
148 | let dest = { | 149 | let dest = { |
149 | code: 200, | 150 | code: 200, |
150 | - message: 'suggest', | 151 | + message: 'recommend', |
151 | data: result || '' | 152 | data: result || '' |
152 | }; | 153 | }; |
153 | 154 | ||
@@ -162,6 +163,6 @@ module.exports = { | @@ -162,6 +163,6 @@ module.exports = { | ||
162 | suggest, | 163 | suggest, |
163 | suggest4Old, | 164 | suggest4Old, |
164 | serachFilterBrands, | 165 | serachFilterBrands, |
165 | - suggestHistory, | ||
166 | - suggestRecommend | 166 | + searchHistory, |
167 | + searchRecommend | ||
167 | }; | 168 | }; |
@@ -424,7 +424,7 @@ const getBrands4Filter = (params) => { | @@ -424,7 +424,7 @@ const getBrands4Filter = (params) => { | ||
424 | * 搜索 历史记录提示 | 424 | * 搜索 历史记录提示 |
425 | * @return | 425 | * @return |
426 | */ | 426 | */ |
427 | -const getSuggestHistory = (params) => { | 427 | +const getSearchHistory = (params) => { |
428 | let finalParams = { | 428 | let finalParams = { |
429 | method: 'app.search.getTerms', | 429 | method: 'app.search.getTerms', |
430 | keyword: params.keyword || '' | 430 | keyword: params.keyword || '' |
@@ -437,10 +437,14 @@ const getSuggestHistory = (params) => { | @@ -437,10 +437,14 @@ const getSuggestHistory = (params) => { | ||
437 | * 搜索 热门搜索和默认搜索 | 437 | * 搜索 热门搜索和默认搜索 |
438 | * @return | 438 | * @return |
439 | */ | 439 | */ |
440 | -const getSuggestRecommend = (params) => { | 440 | +const getSearchRecommend = (params) => { |
441 | + | ||
441 | let finalParams = { | 442 | let finalParams = { |
442 | method: 'app.search.getTerms', | 443 | method: 'app.search.getTerms', |
443 | - keyword: params.keyword || '' | 444 | + content: params.content || '', |
445 | + sort: params.sort, | ||
446 | + status: params.status, | ||
447 | + type: params.type | ||
444 | }; | 448 | }; |
445 | 449 | ||
446 | return api.get('', finalParams, config.apiCache); | 450 | return api.get('', finalParams, config.apiCache); |
@@ -471,6 +475,6 @@ module.exports = { | @@ -471,6 +475,6 @@ module.exports = { | ||
471 | getBrands4Filter, | 475 | getBrands4Filter, |
472 | getProductListOrig, | 476 | getProductListOrig, |
473 | getSearchCacheKey, | 477 | getSearchCacheKey, |
474 | - getSuggestHistory, | ||
475 | - getSuggestRecommend | 478 | + getSearchHistory, |
479 | + getSearchRecommend | ||
476 | }; | 480 | }; |
@@ -6,6 +6,7 @@ | @@ -6,6 +6,7 @@ | ||
6 | 'use strict'; | 6 | 'use strict'; |
7 | const utils = '../../../utils'; | 7 | const utils = '../../../utils'; |
8 | const api = global.yoho.API; | 8 | const api = global.yoho.API; |
9 | +const helpers = global.yoho.helpers; | ||
9 | const saleApi = require('./sale-api'); | 10 | const saleApi = require('./sale-api'); |
10 | const searchApi = require('./search-api'); | 11 | const searchApi = require('./search-api'); |
11 | const headerModel = require('../../../doraemon/models/header'); | 12 | const headerModel = require('../../../doraemon/models/header'); |
@@ -190,14 +191,14 @@ exports.getBrands4Filter = (params) => { | @@ -190,14 +191,14 @@ exports.getBrands4Filter = (params) => { | ||
190 | * 搜索 历史记录提示 | 191 | * 搜索 历史记录提示 |
191 | */ | 192 | */ |
192 | exports.getSearchHistory = (params) => { | 193 | exports.getSearchHistory = (params) => { |
193 | - return searchApi.getSuggestHistory(params).then(result => { | ||
194 | - let dest = []; | 194 | + return searchApi.getSearchHistory(params).then(result => { |
195 | + let resData = []; | ||
195 | 196 | ||
196 | if (result.code === 200) { | 197 | if (result.code === 200) { |
197 | - dest = searchHandler.handleSuggest(result.data); | 198 | + resData = searchHandler.handleSuggest(result.data); |
198 | } | 199 | } |
199 | 200 | ||
200 | - return dest; | 201 | + return resData; |
201 | }); | 202 | }); |
202 | }; | 203 | }; |
203 | 204 | ||
@@ -208,14 +209,52 @@ exports.getSearchHistory = (params) => { | @@ -208,14 +209,52 @@ exports.getSearchHistory = (params) => { | ||
208 | * @return {[type]} [description] | 209 | * @return {[type]} [description] |
209 | */ | 210 | */ |
210 | exports.getSearchRecommend = (params) => { | 211 | exports.getSearchRecommend = (params) => { |
211 | - return searchApi.getSuggestRecommend(params).then(result => { | ||
212 | - let dest = []; | 212 | + return searchApi.getSearchRecommend(params).then(result => { |
213 | + | ||
214 | + // console.log(result); | ||
213 | 215 | ||
214 | if (result.code === 200) { | 216 | if (result.code === 200) { |
215 | - dest = searchHandler.handleSuggest(result.data); | 217 | + let resData = { |
218 | + defaultTerms: [], | ||
219 | + hotTerms: [], | ||
220 | + guessTerms: [] | ||
221 | + }; | ||
222 | + | ||
223 | + resData.defaultTerms = _.map(result.data.defaultTerms, function(value) { | ||
224 | + return { | ||
225 | + href: helpers.urlFormat('', {query: value.url}, 'search'), | ||
226 | + content: value.content, | ||
227 | + sort: value.sort, | ||
228 | + status: value.status, | ||
229 | + type: value.type, | ||
230 | + }; | ||
231 | + }); | ||
232 | + | ||
233 | + resData.hotTerms = _.map(result.data.hotTerms, function(value) { | ||
234 | + return { | ||
235 | + href: helpers.urlFormat('', {query: value.url}, 'search'), | ||
236 | + content: value.content, | ||
237 | + sort: value.sort, | ||
238 | + status: value.status, | ||
239 | + type: value.type, | ||
240 | + }; | ||
241 | + }); | ||
242 | + | ||
243 | + resData.guessTerms = _.map(result.data.guessTerms, function(value) { | ||
244 | + return { | ||
245 | + href: helpers.urlFormat('', {query: value.url}, 'search'), | ||
246 | + content: value.content, | ||
247 | + sort: value.sort, | ||
248 | + status: value.status, | ||
249 | + type: value.type, | ||
250 | + }; | ||
251 | + }); | ||
252 | + | ||
253 | + return resData; | ||
254 | + }else{ | ||
255 | + return result; | ||
216 | } | 256 | } |
217 | 257 | ||
218 | - return dest; | ||
219 | }); | 258 | }); |
220 | }; | 259 | }; |
221 | 260 |
@@ -87,8 +87,8 @@ router.get('/search/index', gbk2utf, search.index); | @@ -87,8 +87,8 @@ router.get('/search/index', gbk2utf, search.index); | ||
87 | router.get('/search/filter/brands', search.serachFilterBrands); | 87 | router.get('/search/filter/brands', search.serachFilterBrands); |
88 | router.get('/search/suggest', search.suggest); // 搜索提示 | 88 | router.get('/search/suggest', search.suggest); // 搜索提示 |
89 | router.get('/api/suggest', search.suggest4Old); | 89 | router.get('/api/suggest', search.suggest4Old); |
90 | -router.get('/search/suggest/history', search.suggestHistory); // 搜索历史提示 | ||
91 | -router.get('/search/suggest/recommend', search.suggestRecommend); // 热门搜索和默认搜索 | 90 | +router.get('/search/history', search.searchHistory); // 搜索历史提示 |
91 | +router.get('/search/recommend', search.searchRecommend); // 热门搜索和默认搜索 | ||
92 | 92 | ||
93 | // 商品分类列表页 | 93 | // 商品分类列表页 |
94 | router.get('/list/index', gbk2utf, list.index); | 94 | router.get('/list/index', gbk2utf, list.index); |
@@ -17,14 +17,14 @@ module.exports = { | @@ -17,14 +17,14 @@ module.exports = { | ||
17 | cookieDomain: '.yohobuy.com', | 17 | cookieDomain: '.yohobuy.com', |
18 | domains: { | 18 | domains: { |
19 | // test3 | 19 | // test3 |
20 | - singleApi: 'http://api-test3.yohops.com:9999/', | ||
21 | - api: 'http://api-test3.yohops.com:9999/', | ||
22 | - service: 'http://service-test3.yohops.com:9999/', | 20 | + // singleApi: 'http://api-test3.yohops.com:9999/', |
21 | + // api: 'http://api-test3.yohops.com:9999/', | ||
22 | + // service: 'http://service-test3.yohops.com:9999/', | ||
23 | 23 | ||
24 | // // prod | 24 | // // prod |
25 | - // singleApi: 'http://single.yoho.cn/', | ||
26 | - // api: 'http://api.yoho.cn/', | ||
27 | - // service: 'http://service.yoho.cn/', | 25 | + singleApi: 'http://single.yoho.cn/', |
26 | + api: 'http://api.yoho.cn/', | ||
27 | + service: 'http://service.yoho.cn/', | ||
28 | 28 | ||
29 | // gray | 29 | // gray |
30 | // singleApi: 'http://single.gray.yohops.com/', | 30 | // singleApi: 'http://single.gray.yohops.com/', |
@@ -129,11 +129,26 @@ | @@ -129,11 +129,26 @@ | ||
129 | <a class="search-btn" href="javascript:submitSearch();"></a> | 129 | <a class="search-btn" href="javascript:submitSearch();"></a> |
130 | </form> | 130 | </form> |
131 | <ul class="search-hot"> | 131 | <ul class="search-hot"> |
132 | - <li><a href=""><span>8888</span></a></li> | ||
133 | - <li><a href=""><span>8888</span></a></li> | ||
134 | - <li><a href=""><span>8888</span></a></li> | ||
135 | - <li><a href=""><span>8888</span></a></li> | ||
136 | - <li><a href=""><span>8888</span></a></li> | 132 | + <script type="text/html" id="search-suggest-recommend"> |
133 | + \{{#data}} | ||
134 | + \{{#hotTerms}} | ||
135 | + <li> | ||
136 | + <a style="display: block;" href="\{{href}}" title="\{{content}}" | ||
137 | + act="\{{href}}"> | ||
138 | + <span class="searchvalue">\{{content}}</span> | ||
139 | + </a> | ||
140 | + </li> | ||
141 | + \{{/hotTerms}} | ||
142 | + \{{#guessTerms}} | ||
143 | + <li> | ||
144 | + <a style="display: block;" href="\{{href}}" title="\{{content}}" | ||
145 | + act="\{{href}}"> | ||
146 | + <span class="searchvalue">\{{content}}</span> | ||
147 | + </a> | ||
148 | + </li> | ||
149 | + \{{/guessTerms}} | ||
150 | + \{{/data}} | ||
151 | + </script> | ||
137 | </ul> | 152 | </ul> |
138 | </div> | 153 | </div> |
139 | 154 | ||
@@ -345,16 +360,7 @@ | @@ -345,16 +360,7 @@ | ||
345 | </li> | 360 | </li> |
346 | \{{/data}} | 361 | \{{/data}} |
347 | </script> | 362 | </script> |
348 | - <script type="text/html" id="search-suggest-recommend"> | ||
349 | - \{{#data}} | ||
350 | - <li> | ||
351 | - <a style="display: block;" href="\{{href}}" title="\{{keyword}}" | ||
352 | - act="\{{href}}"> | ||
353 | - <span class="searchvalue">\{{keyword}}</span> | ||
354 | - </a> | ||
355 | - </li> | ||
356 | - \{{/data}} | ||
357 | - </script> | 363 | + |
358 | </div> | 364 | </div> |
359 | 365 | ||
360 | <input id="api-domain" type="hidden" value="{{apiDomain}}"> | 366 | <input id="api-domain" type="hidden" value="{{apiDomain}}"> |
-
Please register or login to post a comment