modify search to use new elastic engine
Showing
11 changed files
with
304 additions
and
151 deletions
@@ -39,5 +39,7 @@ class CacheConfig | @@ -39,5 +39,7 @@ class CacheConfig | ||
39 | const KEY_ACTION_PRODUCT_BRAND_DOMAINS = 'key_action_product_brand_domains'; // 所有品牌域名列表 | 39 | const KEY_ACTION_PRODUCT_BRAND_DOMAINS = 'key_action_product_brand_domains'; // 所有品牌域名列表 |
40 | const KEY_ACTION_PRODUCT_BRAND_NAMES = 'key_action_product_brand_names'; // 所有品牌名称列表 | 40 | const KEY_ACTION_PRODUCT_BRAND_NAMES = 'key_action_product_brand_names'; // 所有品牌名称列表 |
41 | const KEY_ACTION_PRODUCT_BRAND_LOGO = 'key_action_product_brand_logo'; // 品牌信息 | 41 | const KEY_ACTION_PRODUCT_BRAND_LOGO = 'key_action_product_brand_logo'; // 品牌信息 |
42 | + | ||
43 | + const KEY_ACTION_INDEX_SEARCH = 'key_action_search_search'; // 搜索的数据 | ||
42 | 44 | ||
43 | } | 45 | } |
@@ -16,20 +16,27 @@ use Api\Sign; | @@ -16,20 +16,27 @@ use Api\Sign; | ||
16 | */ | 16 | */ |
17 | class SearchData | 17 | class SearchData |
18 | { | 18 | { |
19 | - | 19 | + |
20 | /** | 20 | /** |
21 | - * 阿里云外网 | 21 | + * 获取搜索的服务地址 |
22 | * | 22 | * |
23 | - * @var string | 23 | + * 备注:此处是根据环境来确定使用阿里云内网还是外网的URL |
24 | + * | ||
25 | + * @return string | ||
24 | */ | 26 | */ |
25 | - protected static $_searchurl = 'http://101.200.31.165/yohosearch/search.json'; | ||
26 | - | ||
27 | -// /** | ||
28 | -// * 阿里云内网 | ||
29 | -// * | ||
30 | -// * @var string | ||
31 | -// */ | ||
32 | -// protected static $_searchurl = 'http://100.98.132.63/yohosearch/search.json'; | 27 | + private static function getSearchUrl() |
28 | + { | ||
29 | + defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer'); | ||
30 | + switch (APPLICATION_ENV) { | ||
31 | + case 'release': | ||
32 | + case 'test': | ||
33 | + case 'preview': | ||
34 | + return 'http://100.98.132.63/yohosearch/search.json'; | ||
35 | + case 'developer': | ||
36 | + default: | ||
37 | + return 'http://101.200.31.165/yohosearch/search.json'; | ||
38 | + } | ||
39 | + } | ||
33 | 40 | ||
34 | /** | 41 | /** |
35 | * 模糊搜索提供的关键词 | 42 | * 模糊搜索提供的关键词 |
@@ -50,7 +57,7 @@ class SearchData | @@ -50,7 +57,7 @@ class SearchData | ||
50 | } | 57 | } |
51 | 58 | ||
52 | /** | 59 | /** |
53 | - * 根据给定查询数据搜索数据列表 | 60 | + * 根据给定查询数据搜索数据列表 (老的) |
54 | * | 61 | * |
55 | * @param string $query 查询条件, 默认为null | 62 | * @param string $query 查询条件, 默认为null |
56 | * @param string $brand 品牌,默认为null | 63 | * @param string $brand 品牌,默认为null |
@@ -71,47 +78,29 @@ class SearchData | @@ -71,47 +78,29 @@ class SearchData | ||
71 | * @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活 | 78 | * @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活 |
72 | * @return array 搜索到的数据 | 79 | * @return array 搜索到的数据 |
73 | */ | 80 | */ |
74 | - public static function searchLiDatas($query = null, $brand = null, $gender = null, $color = null, $size = null, $price = null, $p_d = null, $sort = null, $order = 's_t_desc', $page = 1, $limit = 60, $channel = null) | 81 | + public static function searchByCondition($condition) |
75 | { | 82 | { |
76 | - // 排序数据映射表 | ||
77 | - $order_map = array( | ||
78 | - 's_t_desc' => 'shelve_time:desc', | ||
79 | - 's_t_asc' => 'shelve_time:asc', | ||
80 | - 's_p_asc' => 'sales_price:asc', | ||
81 | - 's_p_desc' => 'sales_price:desc', | ||
82 | - 's_d_desc' => 'discount:desc', | ||
83 | - 's_d_asc' => 'discount:asc', | ||
84 | - 'skn_desc' => 'product_skn:desc', | ||
85 | - 'skn_asc' => 'product_skn:asc', | ||
86 | - 'activities_desc' => 'activities.order_by:desc', | ||
87 | - 'activities_asc' => 'activities.order_by:asc', | ||
88 | - 's_n_asc' => 'sales_num:asc', | ||
89 | - 's_n_desc' => 'sales_num:desc', | ||
90 | - 'activities_id_desc' => 'activities.activity_id:desc', | ||
91 | - 'activities_id_asc' => 'activities.activity_id:asc', | ||
92 | - ); | ||
93 | - | ||
94 | - $param = array(); | ||
95 | - | ||
96 | - is_null($query) || $param['query'] = $query; | ||
97 | - is_null($brand) || $param['brand'] = $brand; | ||
98 | - is_null($gender) || $param['gender'] = $gender; | ||
99 | - is_null($color) || $param['color'] = $color; | ||
100 | - is_null($size) || $param['size'] = $size; | ||
101 | - is_null($price) || $param['price'] = $price; | ||
102 | - is_null($p_d) || $param['p_d'] = $p_d; | ||
103 | - is_null($sort) || $param['sort'] = $sort; | ||
104 | - // is_null($channel) || $param['channel'] = $channel; | ||
105 | - $param['order'] = $order_map[$order]; | ||
106 | - $param['page'] = $page; | ||
107 | - $param['viewNum'] = $limit; // 每页记录数 | ||
108 | - $param['status'] = 1; // 是否上架,1表示在架,2表示不在 | 83 | + $param = Yohobuy::param(); |
84 | + $param['method'] = 'app.search.li'; | ||
85 | + if (!isset($condition['order'])) { | ||
86 | + $param['order'] = 's_t_desc'; | ||
87 | + } | ||
88 | + if (!isset($condition['page'])) { | ||
89 | + $param['page'] = 1; | ||
90 | + } | ||
91 | + if (!isset($condition['limit'])) { | ||
92 | + $param['limit'] = 60; | ||
93 | + } | ||
94 | + if (!empty($condition)) { | ||
95 | + $param += $condition; | ||
96 | + } | ||
97 | + $param['client_secret'] = Sign::getSign($param); | ||
109 | 98 | ||
110 | - return Yohobuy::get(self::$_searchurl, $param); | 99 | + return Yohobuy::get(Yohobuy::API_URL, $param); |
111 | } | 100 | } |
112 | - | 101 | + |
113 | /** | 102 | /** |
114 | - * 根据给定查询数据搜索数据列表 | 103 | + * 根据给定查询数据搜索数据列表 (新的) |
115 | * | 104 | * |
116 | * @param string $query 查询条件, 默认为null | 105 | * @param string $query 查询条件, 默认为null |
117 | * @param string $brand 品牌,默认为null | 106 | * @param string $brand 品牌,默认为null |
@@ -132,19 +121,47 @@ class SearchData | @@ -132,19 +121,47 @@ class SearchData | ||
132 | * @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活 | 121 | * @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活 |
133 | * @return array 搜索到的数据 | 122 | * @return array 搜索到的数据 |
134 | */ | 123 | */ |
135 | - public static function searchByCondition($condition, $order = 's_t_desc', $page = 1, $limit = 60) | 124 | + public static function searchElasticByCondition($condition) |
136 | { | 125 | { |
137 | - $param = Yohobuy::param(); | ||
138 | - $param['method'] = 'app.search.li'; | ||
139 | - $param['order'] = $order; | ||
140 | - $param['page'] = $page; | ||
141 | - $param['limit'] = $limit; | 126 | + // 排序数据映射表 |
127 | + $orderMaps = array( | ||
128 | + 's_t_desc' => 'shelve_time:desc', | ||
129 | + 's_t_asc' => 'shelve_time:asc', | ||
130 | + 's_p_asc' => 'sales_price:asc', | ||
131 | + 's_p_desc' => 'sales_price:desc', | ||
132 | + 's_d_desc' => 'discount:desc', | ||
133 | + 's_d_asc' => 'discount:asc', | ||
134 | + 'skn_desc' => 'product_skn:desc', | ||
135 | + 'skn_asc' => 'product_skn:asc', | ||
136 | + 'activities_desc' => 'activities.order_by:desc', | ||
137 | + 'activities_asc' => 'activities.order_by:asc', | ||
138 | + 's_n_asc' => 'sales_num:asc', | ||
139 | + 's_n_desc' => 'sales_num:desc', | ||
140 | + 'activities_id_desc' => 'activities.activity_id:desc', | ||
141 | + 'activities_id_asc' => 'activities.activity_id:asc', | ||
142 | + ); | ||
143 | + | ||
144 | + $param = array(); | ||
145 | + $param['status'] = 1; // 是否上架,1表示在架,2表示不在 | ||
146 | + if (!isset($orderMaps[ $condition['order'] ] )) { | ||
147 | + $param['order'] = $orderMaps['s_t_desc']; | ||
148 | + } else { | ||
149 | + $param['order'] = $orderMaps[ $condition['order'] ]; | ||
150 | + } | ||
151 | + if (!isset($condition['page'])) { | ||
152 | + $param['page'] = 1; | ||
153 | + } | ||
154 | + if (!isset($condition['limit'])) { | ||
155 | + $param['viewNum'] = 60; | ||
156 | + } else { | ||
157 | + $param['viewNum'] = $condition['limit']; | ||
158 | + unset($condition['limit']); | ||
159 | + } | ||
142 | if (!empty($condition)) { | 160 | if (!empty($condition)) { |
143 | $param += $condition; | 161 | $param += $condition; |
144 | } | 162 | } |
145 | - $param['client_secret'] = Sign::getSign($param); | ||
146 | 163 | ||
147 | - return Yohobuy::get(Yohobuy::API_URL, $param, 600); // 有缓存10分钟 | 164 | + return Yohobuy::get(self::getSearchUrl(), $param); |
148 | } | 165 | } |
149 | 166 | ||
150 | } | 167 | } |
@@ -16,14 +16,14 @@ class ListProcess | @@ -16,14 +16,14 @@ class ListProcess | ||
16 | * @param $data | 16 | * @param $data |
17 | * @return array 处理之后的商品数据 | 17 | * @return array 处理之后的商品数据 |
18 | */ | 18 | */ |
19 | - public static function getListData($data) | 19 | + public static function getListData($data, $returnFilter = true) |
20 | { | 20 | { |
21 | $result = array('new' => array(), 'filter' => array()); | 21 | $result = array('new' => array(), 'filter' => array()); |
22 | 22 | ||
23 | if (isset($data['product_list'])) { | 23 | if (isset($data['product_list'])) { |
24 | $result['new'] = self::getProductData($data['product_list']); | 24 | $result['new'] = self::getProductData($data['product_list']); |
25 | } | 25 | } |
26 | - if (isset($data['filter'])) { | 26 | + if ($returnFilter && isset($data['filter'])) { |
27 | $result['filter'] = self::getFilterData($data['filter']); | 27 | $result['filter'] = self::getFilterData($data['filter']); |
28 | } | 28 | } |
29 | 29 |
@@ -193,7 +193,7 @@ class Helpers | @@ -193,7 +193,7 @@ class Helpers | ||
193 | 193 | ||
194 | // 如果$productData['default_images']为空,就取$productData['goods_list']中第一个,为空就不处理 | 194 | // 如果$productData['default_images']为空,就取$productData['goods_list']中第一个,为空就不处理 |
195 | if (empty($productData['default_images'])) { | 195 | if (empty($productData['default_images'])) { |
196 | - $productData['default_images'] = $productData['goods_list'][0]; | 196 | + $productData['default_images'] = $productData['goods_list'][0]['images_url']; |
197 | } | 197 | } |
198 | 198 | ||
199 | $result = array(); | 199 | $result = array(); |
1 | <?php | 1 | <?php |
2 | + | ||
2 | /** | 3 | /** |
3 | * User: Zip | 4 | * User: Zip |
4 | * Date: 15/10/28 | 5 | * Date: 15/10/28 |
5 | * Time: 下午13:08 | 6 | * Time: 下午13:08 |
6 | */ | 7 | */ |
8 | + | ||
7 | namespace Plugin; | 9 | namespace Plugin; |
10 | + | ||
8 | class Images | 11 | class Images |
9 | { | 12 | { |
13 | + | ||
10 | private static $domain = '.static.yhbimg.com'; | 14 | private static $domain = '.static.yhbimg.com'; |
11 | private static $default_image = '/2015/08/25/02/01dd632a6e07bfef457ce4beda21dd6413.png'; | 15 | private static $default_image = '/2015/08/25/02/01dd632a6e07bfef457ce4beda21dd6413.png'; |
12 | private static $domainList = array( | 16 | private static $domainList = array( |
@@ -20,13 +24,11 @@ class Images | @@ -20,13 +24,11 @@ class Images | ||
20 | ), | 24 | ), |
21 | 'yhb-head' => 'head.static.yhbimg.com' | 25 | 'yhb-head' => 'head.static.yhbimg.com' |
22 | ); | 26 | ); |
23 | - | ||
24 | private static $staticDomain = array( | 27 | private static $staticDomain = array( |
25 | 'bucket' => '' | 28 | 'bucket' => '' |
26 | ); | 29 | ); |
27 | - | ||
28 | private static $qiniuDomain = 'yhfair.qiniudn.com'; | 30 | private static $qiniuDomain = 'yhfair.qiniudn.com'; |
29 | - | 31 | + |
30 | /** | 32 | /** |
31 | * 缩略图模板 | 33 | * 缩略图模板 |
32 | * @param $fileName | 34 | * @param $fileName |
@@ -39,7 +41,7 @@ class Images | @@ -39,7 +41,7 @@ class Images | ||
39 | { | 41 | { |
40 | return self::url($fileName, $bucket, $mode); | 42 | return self::url($fileName, $bucket, $mode); |
41 | } | 43 | } |
42 | - | 44 | + |
43 | /** | 45 | /** |
44 | * | 46 | * |
45 | * @param unknown $fileName | 47 | * @param unknown $fileName |
@@ -48,13 +50,13 @@ class Images | @@ -48,13 +50,13 @@ class Images | ||
48 | */ | 50 | */ |
49 | public static function getSourceUrl($fileName, $bucket = 'yhfair') | 51 | public static function getSourceUrl($fileName, $bucket = 'yhfair') |
50 | { | 52 | { |
51 | - if(stripos($fileName, 'http://') === 0){ | 53 | + if (stripos($fileName, 'http://') === 0) { |
52 | return $fileName; | 54 | return $fileName; |
53 | } | 55 | } |
54 | $domain = self::getDomain($bucket, $fileName); | 56 | $domain = self::getDomain($bucket, $fileName); |
55 | return 'http://' . $domain . '/' . $bucket . $fileName; | 57 | return 'http://' . $domain . '/' . $bucket . $fileName; |
56 | } | 58 | } |
57 | - | 59 | + |
58 | /** | 60 | /** |
59 | * 根据尺寸获得图片url | 61 | * 根据尺寸获得图片url |
60 | * @param unknown $fileName | 62 | * @param unknown $fileName |
@@ -64,14 +66,17 @@ class Images | @@ -64,14 +66,17 @@ class Images | ||
64 | * @param string $bucket | 66 | * @param string $bucket |
65 | * @return mixed | 67 | * @return mixed |
66 | */ | 68 | */ |
67 | - public static function getImageUrl($fileName, $width, $height, $mode = 1, $bucket = 'goodsimg') | 69 | + public static function getImageUrl($fileName, $width, $height, $mode = 2, $bucket = 'goodsimg') |
68 | { | 70 | { |
69 | - if (stripos($fileName, 'http://') !== 0){ | ||
70 | - $fileName = self::template($fileName, $bucket, $mode); | ||
71 | - } | ||
72 | - return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode)); | 71 | + if (!is_string($fileName)) { |
72 | + return self::template(self::$default_image, $bucket, $mode); | ||
73 | + } | ||
74 | + if (stripos($fileName, 'http://') !== 0) { | ||
75 | + $fileName = self::template($fileName, $bucket, $mode); | ||
76 | + } | ||
77 | + return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode)); | ||
73 | } | 78 | } |
74 | - | 79 | + |
75 | /** | 80 | /** |
76 | * 获取图片URL模板 | 81 | * 获取图片URL模板 |
77 | * @param $fileName | 82 | * @param $fileName |
@@ -84,13 +89,13 @@ class Images | @@ -84,13 +89,13 @@ class Images | ||
84 | $domain = self::getDomain($bucket, $fileName); | 89 | $domain = self::getDomain($bucket, $fileName); |
85 | return self::getImgTemplateUrl($bucket . $fileName, $mode, $domain); | 90 | return self::getImgTemplateUrl($bucket . $fileName, $mode, $domain); |
86 | } | 91 | } |
87 | - | 92 | + |
88 | public static function getDomain($bucket, $fileName) | 93 | public static function getDomain($bucket, $fileName) |
89 | { | 94 | { |
90 | $domain = ''; | 95 | $domain = ''; |
91 | - if(!empty(self::$domainList[$bucket])){ | 96 | + if (!empty(self::$domainList[$bucket])) { |
92 | $domain = self::$domainList[$bucket]; | 97 | $domain = self::$domainList[$bucket]; |
93 | - }else{ | 98 | + } else { |
94 | $node = mb_substr($fileName, 15, 2); | 99 | $node = mb_substr($fileName, 15, 2); |
95 | if (!empty(self::$domainList[$node])) { | 100 | if (!empty(self::$domainList[$node])) { |
96 | $domainList = self::$domainList[$node]; | 101 | $domainList = self::$domainList[$node]; |
@@ -100,7 +105,7 @@ class Images | @@ -100,7 +105,7 @@ class Images | ||
100 | } | 105 | } |
101 | return $domain; | 106 | return $domain; |
102 | } | 107 | } |
103 | - | 108 | + |
104 | /** | 109 | /** |
105 | * 获取模板的图片地址 | 110 | * 获取模板的图片地址 |
106 | * @param $fileName | 111 | * @param $fileName |
@@ -118,13 +123,13 @@ class Images | @@ -118,13 +123,13 @@ class Images | ||
118 | $baseUrl = self::MakeBaseUrl($domain, $fileName); | 123 | $baseUrl = self::MakeBaseUrl($domain, $fileName); |
119 | return self::MakeTemplateRequest($baseUrl); | 124 | return self::MakeTemplateRequest($baseUrl); |
120 | } | 125 | } |
121 | - | 126 | + |
122 | private static function MakeBaseUrl($domain, $key) // => $baseUrl | 127 | private static function MakeBaseUrl($domain, $key) // => $baseUrl |
123 | { | 128 | { |
124 | $keyEsc = str_replace("%2F", "/", rawurlencode($key)); | 129 | $keyEsc = str_replace("%2F", "/", rawurlencode($key)); |
125 | return "http://$domain/$keyEsc"; | 130 | return "http://$domain/$keyEsc"; |
126 | } | 131 | } |
127 | - | 132 | + |
128 | private static function MakeTemplateRequest($url) | 133 | private static function MakeTemplateRequest($url) |
129 | { | 134 | { |
130 | $ops = array(); | 135 | $ops = array(); |
@@ -135,7 +140,8 @@ class Images | @@ -135,7 +140,8 @@ class Images | ||
135 | if (empty($ops)) { | 140 | if (empty($ops)) { |
136 | return $url; | 141 | return $url; |
137 | } | 142 | } |
138 | - | 143 | + |
139 | return $url . "?imageView/" . implode('/', $ops); | 144 | return $url . "?imageView/" . implode('/', $ops); |
140 | } | 145 | } |
141 | -} | ||
146 | + | ||
147 | +} |
@@ -237,25 +237,6 @@ server | @@ -237,25 +237,6 @@ server | ||
237 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | 237 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
238 | proxy_set_header Accept-Encoding "gzip"; | 238 | proxy_set_header Accept-Encoding "gzip"; |
239 | } | 239 | } |
240 | - | ||
241 | -# # 子域名 | ||
242 | -# if ($host = "sale.test.yoho.cn" ) { | ||
243 | -# proxy_redirect off; | ||
244 | -# proxy_pass http://61.155.222.162; | ||
245 | -# proxy_set_header Host cuxiao.m.yohobuy.com; | ||
246 | -# proxy_set_header X-Real-IP $remote_addr; | ||
247 | -# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
248 | -# proxy_set_header Accept-Encoding "gzip"; | ||
249 | -# } | ||
250 | -# if ($host = "cuxiao.test.yoho.cn" ) { | ||
251 | -# proxy_redirect off; | ||
252 | -# proxy_pass http://101.201.176.121; | ||
253 | -# proxy_set_header Host cuxiao.m.yohobuy.com; | ||
254 | -# proxy_set_header X-Real-IP $remote_addr; | ||
255 | -# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
256 | -# proxy_set_header Accept-Encoding "gzip"; | ||
257 | -# } | ||
258 | - | ||
259 | 240 | ||
260 | #location ~* \.html$ { | 241 | #location ~* \.html$ { |
261 | # root /Data/code/git/yohobuy/assets; | 242 | # root /Data/code/git/yohobuy/assets; |
@@ -274,18 +255,18 @@ server | @@ -274,18 +255,18 @@ server | ||
274 | location =/sitemap.xml { | 255 | location =/sitemap.xml { |
275 | expires 1d; | 256 | expires 1d; |
276 | } | 257 | } |
277 | - location=/robots.txt { | 258 | + location =/robots.txt { |
278 | expires 1d; | 259 | expires 1d; |
279 | } | 260 | } |
280 | 261 | ||
281 | - location / { | ||
282 | - proxy_redirect off; | ||
283 | - proxy_pass http://yohobuy; | ||
284 | - proxy_set_header Host $host; | ||
285 | - proxy_set_header X-Real-IP $remote_addr; | ||
286 | - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
287 | - proxy_set_header Accept-Encoding "gzip"; | ||
288 | - } | 262 | + #location / { |
263 | +# proxy_redirect off; | ||
264 | +# proxy_pass http://yohobuy; | ||
265 | +# proxy_set_header Host $host; | ||
266 | +# proxy_set_header X-Real-IP $remote_addr; | ||
267 | +# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
268 | +# proxy_set_header Accept-Encoding "gzip"; | ||
269 | +# } | ||
289 | 270 | ||
290 | } | 271 | } |
291 | 272 | ||
@@ -310,4 +291,33 @@ server | @@ -310,4 +291,33 @@ server | ||
310 | expires 30d; | 291 | expires 30d; |
311 | } | 292 | } |
312 | 293 | ||
294 | +} | ||
295 | + | ||
296 | +server | ||
297 | +{ | ||
298 | + listen 80; | ||
299 | + server_name sale.test.yoho.cn; | ||
300 | + | ||
301 | + location / { | ||
302 | + proxy_redirect off; | ||
303 | + proxy_pass http://61.155.222.163; | ||
304 | + proxy_set_header Host sale.m.yohobuy.com; | ||
305 | + proxy_set_header X-Real-IP $remote_addr; | ||
306 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
307 | + proxy_set_header Accept-Encoding "gzip"; | ||
308 | + } | ||
309 | +} | ||
310 | + | ||
311 | +server | ||
312 | +{ | ||
313 | + listen 80; | ||
314 | + server_name cuxiao.test.yoho.cn; | ||
315 | + location / { | ||
316 | + proxy_redirect off; | ||
317 | + proxy_pass http://101.201.176.121; | ||
318 | + proxy_set_header Host cuxiao.m.yohobuy.com; | ||
319 | + proxy_set_header X-Real-IP $remote_addr; | ||
320 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
321 | + proxy_set_header Accept-Encoding "gzip"; | ||
322 | + } | ||
313 | } | 323 | } |
@@ -149,7 +149,7 @@ class SearchController extends AbstractAction | @@ -149,7 +149,7 @@ class SearchController extends AbstractAction | ||
149 | $this->setTitle('搜索'); | 149 | $this->setTitle('搜索'); |
150 | $this->setNavHeader('搜索', true, SITE_MAIN); | 150 | $this->setNavHeader('搜索', true, SITE_MAIN); |
151 | } | 151 | } |
152 | - | 152 | + |
153 | // 右下角的购物车链接 | 153 | // 右下角的购物车链接 |
154 | $data['goodList']['cartUrl'] = Helpers::url('/cart/index/index', null); | 154 | $data['goodList']['cartUrl'] = Helpers::url('/cart/index/index', null); |
155 | 155 | ||
@@ -183,8 +183,13 @@ class SearchController extends AbstractAction | @@ -183,8 +183,13 @@ class SearchController extends AbstractAction | ||
183 | { | 183 | { |
184 | $data = array(); | 184 | $data = array(); |
185 | 185 | ||
186 | - if ($this->isAjax()) { | ||
187 | - // 过滤请求参数 | 186 | + do { |
187 | + /* 判断是不是AJAX请求 */ | ||
188 | + if (!$this->isAjax()) { | ||
189 | + break; | ||
190 | + } | ||
191 | + | ||
192 | + /* 过滤请求参数 */ | ||
188 | $condition = filter_input_array(INPUT_GET, array( | 193 | $condition = filter_input_array(INPUT_GET, array( |
189 | 'query' => FILTER_DEFAULT, | 194 | 'query' => FILTER_DEFAULT, |
190 | 'brand' => FILTER_VALIDATE_INT, | 195 | 'brand' => FILTER_VALIDATE_INT, |
@@ -196,55 +201,45 @@ class SearchController extends AbstractAction | @@ -196,55 +201,45 @@ class SearchController extends AbstractAction | ||
196 | 'price' => FILTER_VALIDATE_INT, | 201 | 'price' => FILTER_VALIDATE_INT, |
197 | 'discount' => FILTER_DEFAULT, | 202 | 'discount' => FILTER_DEFAULT, |
198 | 'gender' => FILTER_DEFAULT, | 203 | 'gender' => FILTER_DEFAULT, |
199 | - 'p_d' => FILTER_DEFAULT,), false); | ||
200 | - | 204 | + 'p_d' => FILTER_DEFAULT, |
205 | + 'page' => FILTER_VALIDATE_INT, ), false); | ||
206 | + // 转义分类 | ||
201 | if (isset($condition['sort'])) { | 207 | if (isset($condition['sort'])) { |
202 | $condition['sort'] = rawurldecode($condition['sort']); | 208 | $condition['sort'] = rawurldecode($condition['sort']); |
203 | } | 209 | } |
210 | + // 转换折扣 | ||
204 | if (isset($condition['discount'])) { | 211 | if (isset($condition['discount'])) { |
205 | $condition['p_d'] = rawurldecode($condition['discount']); | 212 | $condition['p_d'] = rawurldecode($condition['discount']); |
206 | unset($condition['discount']); | 213 | unset($condition['discount']); |
207 | } | 214 | } |
215 | + // 转义性别 | ||
208 | if (isset($condition['gender'])) { | 216 | if (isset($condition['gender'])) { |
209 | $condition['gender'] = rawurldecode($condition['gender']); | 217 | $condition['gender'] = rawurldecode($condition['gender']); |
210 | } | 218 | } |
211 | - | ||
212 | // 转换排序方式 | 219 | // 转换排序方式 |
213 | - $page = $this->get('page', 1); | ||
214 | - $orderVal = $this->get('order', 0); | ||
215 | $type = $this->get('type', ''); | 220 | $type = $this->get('type', ''); |
216 | - $order = Helpers::transOrder($orderVal, $type); | ||
217 | - | ||
218 | - // 查询品类或品牌数据 | ||
219 | - if (!isset($condition['query'])) { | ||
220 | - $condition['order'] = $order; | ||
221 | - $condition['page'] = $page; | ||
222 | - // 搜索品类 | ||
223 | - if (!isset($condition['brand'])) { | ||
224 | - $data += Product\ListModel::getClassData($condition); | ||
225 | - } | ||
226 | - // 搜索品牌 | ||
227 | - else { | ||
228 | - $title = ''; | ||
229 | - $data += Product\ListModel::getBrandData($condition, $title); | ||
230 | - } | ||
231 | - if (isset($data['filter'])) { | ||
232 | - unset($data['filter']); | ||
233 | - } | ||
234 | - } | ||
235 | - // 查询数据 | ||
236 | - else { | ||
237 | - $listData = SearchData::searchByCondition($condition, $order, $page); | ||
238 | - // 处理返回的数据 | ||
239 | - if (isset($listData['data'])) { | ||
240 | - if (isset($listData['data']['filter'])) { | ||
241 | - unset($listData['data']['filter']); | ||
242 | - } | ||
243 | - $data = ListProcess::getListData($listData['data']); | ||
244 | - } | ||
245 | - $listData = array(); | ||
246 | - } | ||
247 | - } | 221 | + $order = $this->get('order', 0); |
222 | + $condition['order'] = Helpers::transOrder($order, $type); | ||
223 | + | ||
224 | +// /* 模糊搜索关键词 */ | ||
225 | +// if (isset($condition['query'])) { | ||
226 | +// $data = Product\SearchModel::getSearchData($condition); | ||
227 | +// break; | ||
228 | +// } | ||
229 | +// | ||
230 | +// /* 精确搜索品牌 */ | ||
231 | +// if (isset($condition['brand'])) { | ||
232 | +// $title = ''; | ||
233 | +// $data = Product\ListModel::getBrandData($condition, $title); | ||
234 | +// break; | ||
235 | +// } | ||
236 | +// | ||
237 | +// /* 精确搜索品类 */ | ||
238 | +// $data = Product\ListModel::getClassData($condition); | ||
239 | + | ||
240 | + $data = Product\SearchModel::getSearchData($condition); | ||
241 | + | ||
242 | + } while (false); | ||
248 | 243 | ||
249 | if (empty($data['new'])) { | 244 | if (empty($data['new'])) { |
250 | echo ' '; | 245 | echo ' '; |
@@ -47,7 +47,7 @@ class ListModel | @@ -47,7 +47,7 @@ class ListModel | ||
47 | $listData = ClassData::filterClassData($condition); | 47 | $listData = ClassData::filterClassData($condition); |
48 | // 处理返回的数据 | 48 | // 处理返回的数据 |
49 | if (isset($listData['code']) && $listData['code'] === 200) { | 49 | if (isset($listData['code']) && $listData['code'] === 200) { |
50 | - $result = ListProcess::getListData($listData['data']); | 50 | + $result = ListProcess::getListData($listData['data'], false); |
51 | } | 51 | } |
52 | 52 | ||
53 | if (USE_CACHE) { | 53 | if (USE_CACHE) { |
@@ -121,7 +121,7 @@ class ListModel | @@ -121,7 +121,7 @@ class ListModel | ||
121 | $listData = BrandData::filterBrandData($condition); | 121 | $listData = BrandData::filterBrandData($condition); |
122 | // 处理返回的数据 | 122 | // 处理返回的数据 |
123 | if (isset($listData['code']) && $listData['code'] === 200) { | 123 | if (isset($listData['code']) && $listData['code'] === 200) { |
124 | - $result = ListProcess::getListData($listData['data']); | 124 | + $result = ListProcess::getListData($listData['data'], false); |
125 | if (!empty($listData['data']['brand'])) { | 125 | if (!empty($listData['data']['brand'])) { |
126 | $result['brandWay'] = array( | 126 | $result['brandWay'] = array( |
127 | 'url' => 'http://' . $listData['data']['brand']['brand_domain'] . SUB_DOMAIN, | 127 | 'url' => 'http://' . $listData['data']['brand']['brand_domain'] . SUB_DOMAIN, |
1 | +<?php | ||
2 | + | ||
3 | +namespace Product; | ||
4 | + | ||
5 | +use Configs\CacheConfig; | ||
6 | +use LibModels\Wap\Product\SearchData; | ||
7 | +use Plugin\DataProcess\ListProcess; | ||
8 | + | ||
9 | +/** | ||
10 | + * 搜索相关的模板数据模型 | ||
11 | + * | ||
12 | + * @name Search | ||
13 | + * @package Product | ||
14 | + * @copyright yoho.inc | ||
15 | + * @version 1.0 (2015-11-1 14:35:52) | ||
16 | + */ | ||
17 | +class SearchModel | ||
18 | +{ | ||
19 | + | ||
20 | + /** | ||
21 | + * 获取搜索的数据 | ||
22 | + * | ||
23 | + * @param array $condition 查询条件 | ||
24 | + * @return array | ||
25 | + */ | ||
26 | + public static function getSearchData($condition) | ||
27 | + { | ||
28 | + $result = array(); | ||
29 | + | ||
30 | + if (USE_CACHE) { | ||
31 | + $key = CacheConfig::KEY_ACTION_INDEX_SEARCH; | ||
32 | + if (!empty($condition)) { | ||
33 | + $key .= http_build_query($condition, null, '&'); | ||
34 | + } | ||
35 | + // 先尝试获取一级缓存(master), 有数据则直接返回. | ||
36 | + $result = Cache::get($key, 'master'); | ||
37 | + if (!empty($result)) { | ||
38 | + return $result; | ||
39 | + } | ||
40 | + } | ||
41 | + | ||
42 | + // 调用接口查询数据 (使用新的 Elastic Engine) | ||
43 | + $listData = SearchData::searchElasticByCondition($condition); | ||
44 | + // 调用接口查询数据 (使用老的 Sphinx Engine) | ||
45 | + // $listData = SearchData::searchByCondition($condition); | ||
46 | + // 处理返回的数据 | ||
47 | + if (isset($listData['code']) && $listData['code'] === 200) { | ||
48 | + $result = ListProcess::getListData($listData['data'], false); | ||
49 | + } | ||
50 | + | ||
51 | + if (USE_CACHE) { | ||
52 | + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. | ||
53 | + if (empty($result)) { | ||
54 | + $result = Cache::get($key, 'slave'); | ||
55 | + } | ||
56 | + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 | ||
57 | + else { | ||
58 | + Cache::set($key, $result, 600); // 缓存10分钟 | ||
59 | + } | ||
60 | + } | ||
61 | + | ||
62 | + return $result; | ||
63 | + } | ||
64 | + | ||
65 | +} |
1 | +[common] | ||
2 | +;;默认项目 | ||
3 | +application.directory = APPLICATION_PATH "/application" | ||
4 | +;;website library | ||
5 | +application.library = ROOT_PATH "/library" | ||
6 | +;;默认模块 | ||
7 | +application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart" | ||
8 | +;;加载 | ||
9 | +application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php" | ||
10 | +;;view文件的扩展名 | ||
11 | +application.view.ext = "phtml" | ||
12 | +;;默认layouts | ||
13 | +application.layout.path = APPLICATION_PATH "/application/layouts" | ||
14 | +;;layouts 默认文件 | ||
15 | +application.layout.default = "default" | ||
16 | +;;默认Controller | ||
17 | +application.dispatcher.defaultController = "index" | ||
18 | +;;默认Action | ||
19 | +application.dispatcher.defaultAction = "index" | ||
20 | + | ||
21 | +;;初始化命名空间 | ||
22 | +application.namespaces = "Action,Api,Configs,LibModels,Plugin" | ||
23 | + | ||
24 | +;;使用composer | ||
25 | +composer.autoload = 0 | ||
26 | +composer.path = APPLICATION_PATH "/library/Package" | ||
27 | + | ||
28 | +yaf.use_namespace = 1 | ||
29 | + | ||
30 | +;;调试模式 | ||
31 | +[preview : common] | ||
32 | +application.debug = False | ||
33 | +application.servers.config = APPLICATION_PATH "/configs/core" | ||
34 | + | ||
35 | +;出错的时候是否抛出异常 | ||
36 | +application.dispatcher.throwException = False | ||
37 | + | ||
38 | +;是否使用默认的异常 捕获Controller, 如果开启, 在有未捕获的异常的时候, | ||
39 | +;控制权会交给ErrorController的errorAction 方法, | ||
40 | +;可以通过$request->getException()获得此异常对象 | ||
41 | +application.dispatcher.catchException = False | ||
42 | + | ||
43 | +;模板预编译目录,该目录需要有读写权限 | ||
44 | +application.template.compile = ROOT_PATH "/compile/m.yohobuy.com" | ||
45 | +application.template.path = ROOT_PATH "/template/m.yohobuy.com/actions" | ||
46 | +application.template.partials = ROOT_PATH "/template/m.yohobuy.com/partials" | ||
47 | +application.template.ext = ".phtml" | ||
48 | + | ||
49 | +;静态HTML页面的存放目录, 该目录需要有读写权限 | ||
50 | +application.assets.path = ROOT_PATH "/assets" | ||
51 | + | ||
52 | +; 应用的版本号 | ||
53 | +application.version = "0.0.6" | ||
54 | + | ||
55 | +; 网站SEO信息 | ||
56 | +application.seo.title = "Yoho!Buy有货" | ||
57 | +application.seo.keywords = "Yoho! 有货官网,潮流志,潮流男装,潮牌,美国潮牌,日本潮牌,香港潮牌,潮牌店,新品首发,欧美潮流,全球购,代购,时尚,流行,特卖,B2C,正品,购物网站,网上购物,货到付款" | ||
58 | +application.seo.description = "YOHO! 有货,年轻人潮流购物中心,中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。作为YOHO!旗下的购物平台,汇集了全球潮流时尚商品和中国最流行的商品,也是国内最大的原创文化商品平台,也是香港,台湾地区流行商品的集中地。同时包含日本、韩国等众多国外潮流品牌,带给您全新潮流购物体验。" | ||
59 | + |
-
Please register or login to post a comment