Пример #1
0
 public static function find2($query, $offset)
 {
     if (!strlen($query)) {
         return false;
     }
     $words = WordStatTable::parseQuery($query);
     return WordChainTable::search($words, $offset);
 }
Пример #2
0
 public static function reInitData($parameters = array())
 {
     static::createTables();
     $offset = 0;
     $stat = array();
     $types = array();
     $typeSort = array();
     $res = Location\TypeTable::getList(array('select' => array('ID', 'CODE', 'SORT')));
     $allowedTypes = array('REGION', 'SUBREGION', 'CITY', 'VILLAGE', 'STREET');
     while ($item = $res->fetch()) {
         if (in_array($item['CODE'], $allowedTypes)) {
             $types[$item['CODE']] = $item['ID'];
         }
         $typeSort[$item['ID']] = $item['SORT'];
     }
     $typesBack = array_flip($types);
     //print_r($types);
     //_print_r($typeSort);
     $wordChain = array();
     $pathChain = array();
     //_dump_r('GO!');
     $prevDepth = 0;
     while (true) {
         $res = Location\LocationTable::getList(array('select' => array('ID', 'TYPE_ID', 'LNAME' => 'NAME.NAME', 'DEPTH_LEVEL', 'SORT'), 'filter' => array('=TYPE_ID' => array_values($types), '=NAME.LANGUAGE_ID' => LANGUAGE_ID), 'order' => array('LEFT_MARGIN' => 'asc'), 'limit' => self::STEP_SIZE, 'offset' => $offset));
         $cnt = 0;
         while ($item = $res->fetch()) {
             if ($item['DEPTH_LEVEL'] < $prevDepth) {
                 //print('DROP to '.$item['DEPTH_LEVEL'].'<br />');
                 // drop chain to DEPTH_LEVEL inclusively
                 $newWC = array();
                 $newPC = array();
                 foreach ($wordChain as $dl => $name) {
                     if ($dl >= $item['DEPTH_LEVEL']) {
                         break;
                     }
                     $newWC[$dl] = $name;
                 }
                 $wordChain = $newWC;
                 foreach ($pathChain as $dl => $id) {
                     if ($dl >= $item['DEPTH_LEVEL']) {
                         break;
                     }
                     $newPC[$dl] = $id;
                 }
                 $pathChain = $newPC;
             }
             $wordChain[$item['DEPTH_LEVEL']] = $item['LNAME'];
             $pathChain[$item['DEPTH_LEVEL']] = array('TYPE' => $item['TYPE_ID'], 'ID' => $item['ID']);
             $prevDepth = $item['DEPTH_LEVEL'];
             //print($item['DEPTH_LEVEL'].' - '.implode(' ', WordStatTable::parseQuery(implode(' ', $wordChain))).'<br />');
             $parsed = WordStatTable::parseQuery(implode(' ', $wordChain));
             $wordMap = array();
             $i = 1;
             foreach ($parsed as $word) {
                 $wordMap['W_' . $i] = $word;
                 $i++;
             }
             $pathMap = array();
             foreach ($pathChain as $elem) {
                 $pathMap[$typesBack[$elem['TYPE']] . '_ID'] = $elem['ID'];
             }
             $data = array_merge($wordMap, $pathMap, array('LOCATION_ID' => $item['ID'], 'TYPE_ID' => $item['TYPE_ID'], 'TYPE_SORT' => $typeSort[$item['TYPE_ID']], 'SORT' => $item['SORT'], 'WORD_COUNT' => count($wordMap)));
             //print('<pre>');
             //print('</pre>');
             try {
                 static::add($data);
             } catch (\Exception $e) {
                 _dump_r('Cant add ' . implode(' ', $wordChain) . ' (' . count($wordMap) . ')<br />');
                 // duplicate or smth
             }
             $cnt++;
         }
         if (!$cnt) {
             break;
         }
         $offset += self::STEP_SIZE;
     }
 }