public static function reInitData() { static::cleanUp(); $totalCnt = 0; $offset = 0; $stat = array(); while (true) { $res = Location\Name\LocationTable::getList(array('select' => array('NAME', 'LOCATION_ID', 'TID' => 'LOCATION.TYPE_ID'), 'filter' => array('=LOCATION.TYPE.CODE' => array('CITY', 'VILLAGE', 'STREET'), '=LANGUAGE_ID' => 'ru'), 'limit' => self::STEP_SIZE, 'offset' => $offset)); $cnt = 0; while ($item = $res->fetch()) { if (strlen($item['NAME'])) { $words = static::parseQuery($item['NAME']); foreach ($words as $k => &$word) { try { static::add(array('WORD' => $word, 'TYPE_ID' => $item['TID'], 'LOCATION_ID' => $item['LOCATION_ID'])); } catch (\Bitrix\Main\DB\SqlQueryException $e) { // duplicate or smth } } $stat['W_' . count($words)] += 1; //_print_r($words); } $cnt++; $totalCnt++; } if (!$cnt) { break; } $offset += self::STEP_SIZE; } _print_r('Total: ' . $totalCnt); _print_r($stat); }
protected function getSubpercentForStageCreateDictionary() { if (!isset($this->data['LOC_NAMES_2_INDEX_COUNT'])) { $item = Location\Name\LocationTable::getList(array('select' => array('CNT'), 'filter' => WordTable::getFilterForInitData(array('TYPES' => Finder::getIndexedTypes(), 'LANGS' => Finder::getIndexedLanguages()))))->fetch(); $this->data['LOC_NAMES_2_INDEX_COUNT'] = intval($item['CNT']); } return $this->getSubPercentByTotalAndDone($this->data['LOC_NAMES_2_INDEX_COUNT'], $this->data['OFFSET']); }
public function convertTree() { $res = Location\Name\LocationTable::getList(array('select' => array('ID'), 'limit' => 1))->fetch(); if (!$res['ID']) { $this->grabTree(); $this->convertCountries(); $this->convertRegions(); $this->convertCities(); $this->resort(); $this->insertTreeInfo(); $this->insertNames(); } }
public function initializeData() { $res = Location\Name\LocationTable::getList(array('select' => array('NAME', 'LOCATION_ID'), 'filter' => static::getFilterForInitData(array('TYPES' => $this->procData['ALLOWED_TYPES'], 'LANGS' => $this->procData['ALLOWED_LANGS'])), 'order' => array('LOCATION_ID' => 'asc'), 'limit' => static::STEP_SIZE, 'offset' => $this->procData['OFFSET'])); $cnt = 0; while ($item = $res->fetch()) { if (strlen($item['NAME'])) { if ($this->procData['CURRENT_LOCATION'] != $item['LOCATION_ID']) { $this->procData['CURRENT_LOCATION_WORDS'] = array(); } $this->procData['CURRENT_LOCATION'] = $item['LOCATION_ID']; $words = static::parseString($item['NAME']); foreach ($words as $k => &$word) { $wordHash = md5($word); $wordId = false; if (isset($this->dictionaryIndex[$wordHash])) { $wordId = $this->dictionaryIndex[$wordHash]; } else { $wordId = static::getIdByWord($word); // check if the word was added previously } if ($wordId === false) { $wordId = $this->dictionaryInserter->insert(array('WORD' => $word)); $this->dictionaryIndex[$wordHash] = $wordId; } if ($wordId !== false && !isset($this->procData['CURRENT_LOCATION_WORDS'][$wordId])) { $this->procData['CURRENT_LOCATION_WORDS'][$wordId] = true; $this->word2LocationInserter->insert(array('LOCATION_ID' => intval($item['LOCATION_ID']), 'WORD_ID' => intval($wordId))); } } } $cnt++; } $this->procData['OFFSET'] += static::STEP_SIZE; $this->dictionaryInserter->flush(); $this->word2LocationInserter->flush(); return !$cnt; }
public function initializeData() { $dbConnection = Main\HttpApplication::getConnection(); $res = Location\LocationTable::getList(array('select' => array('ID', 'TYPE_ID', 'DEPTH_LEVEL', 'SORT'), 'order' => array('LEFT_MARGIN' => 'asc'), 'limit' => self::STEP_SIZE, 'offset' => $this->procData['OFFSET'])); $cnt = 0; while ($item = $res->fetch()) { $name = Location\Name\LocationTable::getList(array('select' => array('NAME'), 'filter' => array('=LOCATION_ID' => $item['ID'], '=LANGUAGE_ID' => 'ru')))->fetch(); if ($item['DEPTH_LEVEL'] < $this->procData['DEPTH']) { $newPC = array(); foreach ($this->procData['PATH'] as $dl => $id) { if ($dl >= $item['DEPTH_LEVEL']) { break; } $newPC[$dl] = $id; } $this->procData['PATH'] = $newPC; } $this->procData['PATH'][$item['DEPTH_LEVEL']] = array('TYPE' => $item['TYPE_ID'], 'ID' => $item['ID']); $this->procData['DEPTH'] = $item['DEPTH_LEVEL']; if (is_array($this->procData['ALLOWED_TYPES']) && in_array($item['TYPE_ID'], $this->procData['ALLOWED_TYPES'])) { $data = array('LOCATION_ID' => $item['ID'], 'RELEVANCY' => $this->procData['TYPE_SORT'][$item['TYPE_ID']]); $wordsAdded = array(); $k = 1; foreach ($this->procData['PATH'] as &$pathItem) { if (!isset($pathItem['WORDS'])) { $sql = "\n\t\t\t\t\t\t\tselect WS.POSITION from " . WordTable::getTableNameWord2Location() . " WL\n\t\t\t\t\t\t\t\tinner join " . WordTable::getTableName() . " WS on WL.WORD_ID = WS.ID\n\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\tWL.LOCATION_ID = '" . intval($pathItem['ID']) . "'\n\t\t\t\t\t\t"; $wordRes = $dbConnection->query($sql); $pathItem['WORDS'] = array(); while ($wordItem = $wordRes->fetch()) { $pathItem['WORDS'][] = $wordItem['POSITION']; } $pathItem['WORDS'] = array_unique($pathItem['WORDS']); } foreach ($pathItem['WORDS'] as $position) { if (!isset($wordsAdded[$position])) { $this->indexInserter->insert(array_merge(array('POSITION' => $position), $data)); $wordsAdded[$position] = true; } } } unset($pathItem); } $cnt++; } $this->indexInserter->flush(); $this->procData['OFFSET'] += self::STEP_SIZE; return !$cnt; }