-
Notifications
You must be signed in to change notification settings - Fork 0
/
mission2.php~
160 lines (146 loc) · 6.86 KB
/
mission2.php~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
include_once("/var/www/html/dashboard/commonlib.php");
function startsWith($hit_times,$category_data ,$title,$conn,$product_id) {
for($j = 0 ; $j < sizeof($category_data) ; $j++){
$num_of_searchkeyword_matched=0;
//CCC:假設大分類和中分類的search keyword只有一個關鍵字
$search_keyword_array=explode (",",$category_data[$j]['searchKeyword']);
//CCC:假設小分類 的search keyword可以有多個關鍵字
$small_search_keyword_array=explode ("_",$search_keyword_array[2]);
//CCC:掃描大分類、中分類
for($k = 0 ; $k < 2 ; $k++){
//CCC:檢查product的title欄位是否包含某一類別的搜尋關鍵字
if( strpos($title, $search_keyword_array[$k]) >0){
//$ary[i] 包含 $category_data[j]
//echo $ary[$i]['title'].','.$category_data[$j]['searchKeyword'].'<br>';
$num_of_searchkeyword_matched=$num_of_searchkeyword_matched+1;
}
}
for($k1 = 0 ; $k1 < sizeof($small_search_keyword_array) ; $k1++){
//CCC:檢查product的title欄位是否包含某一類別的搜尋關鍵字
if( strpos($title, $small_search_keyword_array[$k1] ) >0){
//$ary[i] 包含 $category_data[j]
//echo $ary[$i]['title'].','.$category_data[$j]['searchKeyword'].'<br>';
$num_of_searchkeyword_matched=$num_of_searchkeyword_matched+1;
}
}
if($num_of_searchkeyword_matched==$hit_times ){
$possible_category=$category_data[$j]['catid'];
$sql="INSERT INTO map_prod_categoryV2 (pid,catid) VALUES ( ".$product_id." , ".$possible_category." )"; //date("Y-m-d",strtotime($news_date)) //strip_tags($g_element->parent()->parent()->childNodes(1))
mysql_query($sql,$conn) or die('MySQL query error '.mysql_error().' '.$sql);
}
}
}
/*
select * from product where created_at>'2016-01-05'
CCC:我們先看product表的一筆data
array(1996) {
[0]=> array(34) {
[0]=> string(8) "25005629"
["id"]=> string(8) "25005629"
[1]=> string(6) "285799"
["store_id"]=> string(6) "285799"
[2]=> string(31) " 簡約時尚針織西裝外套"
["title"]=> string(31) " 簡約時尚針織西裝外套"
[3]=> string(0) ""
["subtitle"]=> string(0) ""
[4]=> string(0) ""
["tag"]=> string(0) ""
[5]=> string(94) "http://www.littlemoni.com.tw/littlemoni/index.php?action=product_detail&prod_no=P0000100003021"
["url"]=> string(94) "http://www.littlemoni.com.tw/littlemoni/index.php?action=product_detail&prod_no=P0000100003021"
[6]=> string(9) "266969264"
["hash_url"]=> string(9) "266969264"
[7]=> string(11) "92330107052"
["enternal_product_id"]=> string(11) "92330107052"
[8]=> string(1179) "
*/
ignore_user_abort(true);
set_time_limit(0);
//CCC:這邊是把categoryV2的資料先載入到記憶體,不要每次都到資料庫取出categoryV2的資料
$conn = getConnection("ibabymall");
$category_data=array();
$list_query="select * from categoryV2 where length(categoryCode)=9";
$list0 = mysql_query($list_query,$conn) or die('MySQL query error '.mysql_error().' '.$list_query);
while($row = mysql_fetch_array($list0))
$category_data[]=$row ;
/*
rray(8) {
[0]=> string(1) "1"
["catid"]=> string(1) "1"
[1]=> string(9) "外出服"
["category"]=> string(9) "外出服"
[2]=> string(3) "001"
["categoryCode"]=> string(3) "001"
[3]=> string(6) "外出"
["searchKeyword"]=> string(6) "外出"
}
*/
//CCC:這裡的問題是只要insert還沒被檢查過的product id到底是哪一類的
$yest_str=date("Y-m-d", strtotime("-1 day"));//前天日期
$conn = getConnection("ibabymall");
$keywords='';
//select * from product where created_at>'2016-01-01' order by created_at desc
//select * from product where catid is NULL and created_at>'2015-12-01' and created_at<='2015-12-31
//select * from product where catid is NULL and created_at>'2015-11-15' and created_at<='2015-12-01
//select * from product where catid is NULL and created_at>'2015-11-01' and created_at<='2015-11-15'
//select * from product where catid is NULL and created_at>'2015-10-20' and created_at<='2015-11-01'
//select * from product where catid is NULL and created_at>'2015-10-10' and created_at<='2015-10-20'
//select * from product where catid is NULL and created_at>'2015-10-01' and created_at<='2015-10-10'
//select * from product where catid is NULL and created_at>'2015-09-17' and created_at<='2015-10-01'
//select * from product where catid is NULL and created_at>'2015-09-06' and created_at<='2015-09-17'
$list_query="select * from product where catid is NULL and created_at>'2015-09-06' and created_at<='2015-09-17'";
echo $list_query;
$list1 = mysql_query($list_query,$conn) or die('MySQL query error '.mysql_error().' '.$list_query);
$ary=array();
while($row = mysql_fetch_array($list1))
$ary[]=$row;
mysql_free_result($list1);
echo '<br><br><br><br><br><br><br><br><br>';
//var_dump($category_data );
for($i = 0 ; $i < sizeof($ary) ; $i++){
$temp_b=false;
$max_num_of_searchkeyword_matched=0;
$possible_category=-1;
for($j = 0 ; $j < sizeof($category_data) ; $j++){
$num_of_searchkeyword_matched=0;
//CCC:假設大分類和中分類的search keyword只有一個關鍵字
$search_keyword_array=explode (",",$category_data[$j]['searchKeyword']);
//CCC:假設小分類 的search keyword可以有多個關鍵字
$small_search_keyword_array=explode ("_",$search_keyword_array[2]);
//CCC:掃描大分類、中分類
for($k = 0 ; $k < 2 ; $k++){
//CCC:檢查product的title欄位是否包含某一類別的搜尋關鍵字
if( strpos($ary[$i]['title'], $search_keyword_array[$k]) >0){
//$ary[i] 包含 $category_data[j]
//echo $ary[$i]['title'].','.$category_data[$j]['searchKeyword'].'<br>';
$temp_b=true;
$num_of_searchkeyword_matched=$num_of_searchkeyword_matched+1;
}
}
for($k1 = 0 ; $k1 < sizeof($small_search_keyword_array) ; $k1++){
//CCC:檢查product的title欄位是否包含某一類別的搜尋關鍵字
if( strpos($ary[$i]['title'], $small_search_keyword_array[$k1] ) >0){
//$ary[i] 包含 $category_data[j]
//echo $ary[$i]['title'].','.$category_data[$j]['searchKeyword'].'<br>';
$temp_b=true;
$num_of_searchkeyword_matched=$num_of_searchkeyword_matched+1;
}
}
if($num_of_searchkeyword_matched>$max_num_of_searchkeyword_matched ){
$max_num_of_searchkeyword_matched=$num_of_searchkeyword_matched;
$possible_category=$category_data[$j]['catid'];
}
}
if($temp_b==false){
//echo 'no category:'.$ary[$i]['title'].'<br>';
}else{
startsWith($max_num_of_searchkeyword_matched,$category_data ,$ary[$i]['title'],$conn,$ary[$i]['id']);
$sql = "UPDATE product SET catid='1' WHERE id=".$ary[$i]['id'];
mysql_query($sql,$conn) or die('MySQL query error '.mysql_error().' '.$sql);
}
}
//var_dump($ary);
passthru('kill -9 ' . getmypid());
exec('kill -9 ' . getmypid());
// CCC:如果要直接執行php程式,可以在cmd執行/usr/bin/php -q /var/www/html/dashboard/mission.php
?>