/** * List of enabled indexes * * @return \Mirasvit\Search\Model\Index[] */ public function getIndexes() { if ($this->indexes == null) { $result = []; $collection = $this->indexCollectionFactory->create()->addFieldToFilter('is_active', 1)->setOrder('position', 'asc'); /** @var \Mirasvit\Search\Model\Index $index */ foreach ($collection as $index) { if ($this->config->isMultiStoreModeEnabled() && $index->getCode() == 'catalogsearch_fulltext') { foreach ($this->_storeManager->getStores(false, true) as $code => $store) { if (in_array($store->getId(), $this->config->getEnabledMultiStores())) { $clone = clone $index; $clone->setData('store_id', $store->getId()); $clone->setData('store_code', $code); if ($this->_storeManager->getStore()->getId() != $store->getId()) { $clone->setData('title', $store->getName()); } $result[] = $clone; } } } else { $result[] = $index; } } $this->indexes = $result; } return $this->indexes; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { // $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // // /** @var \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory */ // $eavSetupFactory = $objectManager->get('Magento\Eav\Setup\EavSetupFactory'); // // $setup = $objectManager->get('Magento\Framework\Setup\ModuleDataSetupInterface'); // // $eavSetup = $eavSetupFactory->create(['setup' => $setup]); // // for ($i = 1; $i < 400; $i++) { // $eavSetup->addAttribute( // \Magento\Catalog\Model\Product::ENTITY, // substr(md5($i), 0, 5) . '_sample_attribute_' . $i, // [ // 'type' => 'int', // 'backend' => '', // 'frontend' => '', // 'label' => 'Sample Atrribute ' . $i, // 'input' => '', // 'class' => '', // 'source' => '', // 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, // 'visible' => true, // 'required' => false, // 'user_defined' => true, // 'default' => '', // 'searchable' => true, // 'filterable' => true, // 'comparable' => true, // 'visible_on_front' => true, // 'used_in_product_listing' => true, // 'unique' => false, // 'apply_to' => '' // ] // ); // // echo $i . PHP_EOL; // } // // die(); try { $this->appState->setAreaCode('frontend'); } catch (\Exception $e) { } $collection = $this->indexCollectionFactory->create()->addFieldToFilter('is_active', 1); /** @var \Mirasvit\Search\Model\Index $index */ foreach ($collection as $index) { $output->write($index->getTitle() . ' [' . $index->getCode() . ']....'); try { $index->getIndexInstance()->reindexAll(); $output->writeln("<info>Done</info>"); } catch (\Exception $e) { $output->writeln("Error"); $output->writeln($e->getMessage()); } } }
/** * @return string Path to config file * @throws \Exception */ public function makeConfig() { if (!$this->directory->isExist($this->basePath)) { //$this->directory->delete($this->basePath); $this->directory->create($this->basePath); $this->directory->changePermissions($this->basePath, 0777); } $jsonData = []; $sphinxData = ['time' => date('d.m.Y H:i:s'), 'host' => $this->host, 'port' => $this->port, 'fallback_port' => $this->port - 1, 'logdir' => $this->directory->getAbsolutePath($this->basePath), 'sphinxdir' => $this->directory->getAbsolutePath($this->basePath), 'indexes' => '', 'localdir' => dirname(dirname(__FILE__)), 'custom' => $this->config->getAdditionalSearchdConfig()]; $sphinxTemplate = $this->config->getSphinxConfigurationTemplate(); $indexTemplate = $this->config->getSphinxIndexConfigurationTemplate(); /** @var \Mirasvit\Search\Model\Index $index */ foreach ($this->indexCollectionFactory->create() as $index) { foreach (array_keys($this->storeManager->getStores()) as $storeId) { $indexName = $index->getIndexInstance()->getIndexer()->getIndexName($storeId); $data = ['name' => $indexName, 'min_word_len' => 1, 'path' => $this->directory->getAbsolutePath($this->basePath) . '/' . $indexName, 'custom' => $this->config->getAdditionalIndexConfig()]; $jsonAttributes = []; $attributes = []; foreach (array_keys($index->getIndexInstance()->getAttributes(true)) as $attribute) { $attributes[] = " rt_field = {$attribute}"; $jsonAttributes[] = $attribute; if (count($attributes) > 250) { break; } } $attributes[] = " rt_field = options"; $jsonAttributes[] = "options"; $data['attributes'] = implode(PHP_EOL, $attributes); $sphinxData['indexes'] .= $this->helper->filterTemplate($indexTemplate, $data); $jsonData[$indexName] = $jsonAttributes; } } $config = $this->helper->filterTemplate($sphinxTemplate, $sphinxData); if ($this->directory->isWritable($this->basePath)) { $this->directory->writeFile($this->configFilePath, $config); $this->directory->writeFile($this->configFilePath . '.attr', json_encode($jsonData)); } else { if ($this->directory->isExist($this->configFilePath)) { throw new \Exception(__('File %1 does not writable', $this->configFilePath)); } else { throw new \Exception(__('Directory %1 does not writable', $this->basePath)); } } return $this->directory->getAbsolutePath($this->configFilePath); }
/** * Constructor * * @param Pool $pool * @param IndexCollectionFactory $indexCollectionFactory */ public function __construct(Pool $pool, IndexCollectionFactory $indexCollectionFactory) { $this->pool = $pool; $this->indexCollection = $indexCollectionFactory->create(); }