Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
wordstat.php
1<?php
9
10use Bitrix\Main;
15
16Loc::loadMessages(__FILE__);
17
18final class WordStatTable extends Entity\DataManager
19{
20 public static function getFilePath()
21 {
22 return __FILE__;
23 }
24
25 public static function getTableName()
26 {
27 return 'b_sale_loc_word_stat';
28 }
29
30 public static function cleanUp()
31 {
32 Main\HttpApplication::getConnection()->query('truncate table '.static::getTableName());
33 }
34
35 const STEP_SIZE = 100;
36
37 // tmp
38 protected static $blackList = array(
39 '' => true,
40 '' => true,
41 '' => true,
42 '' => true,
43 '' => true,
44 '' => true,
45 'Ѩ' => true,
46 '' => true,
47 '' => true,
48 '' => true,
49 '' => true,
50 '' => true,
51 '˨' => true,
52 '' => true,
53 '' => true,
54 '' => true,
55 '' => true,
56 '' => true,
57 '' => true,
58 '' => true,
59 '' => true
60 );
61
62 public static function parseQuery($query)
63 {
64 $words = explode(' ', $query);
65
66 $result = array();
67 foreach($words as $k => &$word)
68 {
69 $word = ToUpper(trim($word));
70
71 if(strlen($word) < 2 || isset(static::$blackList[$word]))
72 continue;
73
74 $result[] = $word;
75 }
76
77 $result = array_unique($result);
78
79 //natsort($result);
80
81 return $result;
82 }
83
84 public static function reInitData()
85 {
86 static::cleanUp();
87
88 $totalCnt = 0;
89 $offset = 0;
90 $stat = array();
91
92 while(true)
93 {
94 $res = Location\Name\LocationTable::getList(array(
95 'select' => array(
96 'NAME',
97 'LOCATION_ID',
98 'TID' => 'LOCATION.TYPE_ID'
99 ),
100 'filter' => array(
101 '=LOCATION.TYPE.CODE' => array('CITY', 'VILLAGE', 'STREET'),
102 '=LANGUAGE_ID' => 'ru'
103 ),
104 'limit' => self::STEP_SIZE,
105 'offset' => $offset
106 ));
107
108 $cnt = 0;
109 while($item = $res->fetch())
110 {
111 if(strlen($item['NAME']))
112 {
113 $words = static::parseQuery($item['NAME']);
114
115 foreach($words as $k => &$word)
116 {
117 try
118 {
119
120 static::add(array(
121 'WORD' => $word,
122 'TYPE_ID' => $item['TID'],
123 'LOCATION_ID' => $item['LOCATION_ID']
124 ));
125
126 }
127 catch(\Bitrix\Main\DB\SqlQueryException $e)
128 {
129 // duplicate or smth
130 }
131 }
132
133 $stat['W_'.count($words)] += 1;
134
135 //_print_r($words);
136 }
137
138 $cnt++;
139 $totalCnt++;
140 }
141
142 if(!$cnt)
143 break;
144
145 $offset += self::STEP_SIZE;
146 }
147
148 _print_r('Total: '.$totalCnt);
149 _print_r($stat);
150 }
151
152 public static function getMap()
153 {
154 return array(
155
156 'WORD' => array(
157 'data_type' => 'string',
158 'primary' => true,
159 ),
160 'TYPE_ID' => array(
161 'data_type' => 'integer',
162 'primary' => true,
163 ),
164 'LOCATION_ID' => array(
165 'data_type' => 'integer',
166 'primary' => true,
167 ),
168 );
169 }
170}
171
static loadMessages($file)
Definition loc.php:64