示例#1
0
 public function testResetSearchResult()
 {
     $this->resource->expects($this->once())->method('getTableName')->with('search_query', ResourceConnection::DEFAULT_CONNECTION)->willReturn('table_name_search_query');
     $this->connection->expects($this->once())->method('update')->with('table_name_search_query', ['is_processed' => 0], ['is_processed != 0'])->willReturn(10);
     $result = $this->target->resetSearchResults();
     $this->assertEquals($this->target, $result);
 }
 public function testExecuteFull()
 {
     $stores = [0 => 'Store 1', 1 => 'Store 2'];
     $indexData = new \ArrayObject([]);
     $this->storeManager->expects($this->once())->method('getStores')->willReturn($stores);
     $this->saveHandler->expects($this->exactly(count($stores)))->method('cleanIndex');
     $this->saveHandler->expects($this->exactly(count($stores)))->method('saveIndex');
     $this->fullAction->expects($this->exactly(count($stores)))->method('rebuildStoreIndex')->willReturn($indexData);
     $this->fulltextResource->expects($this->once())->method('resetSearchResults');
     $this->searchRequestConfig->expects($this->once())->method('reset');
     $this->model->executeFull();
 }
示例#3
0
 /**
  * Execute full indexation
  *
  * @return void
  */
 public function executeFull()
 {
     $storeIds = array_keys($this->storeManager->getStores());
     /** @var IndexerHandler $saveHandler */
     $saveHandler = $this->indexerHandlerFactory->create(['data' => $this->data]);
     foreach ($storeIds as $storeId) {
         $dimension = $this->dimensionFactory->create(['name' => 'scope', 'value' => $storeId]);
         $saveHandler->cleanIndex([$dimension]);
         $saveHandler->saveIndex([$dimension], $this->fullAction->rebuildStoreIndex($storeId));
     }
     $this->fulltextResource->resetSearchResults();
     $this->searchRequestConfig->reset();
 }
 /**
  * Search the text and return result collection
  *
  * @param string $text
  * @return Product[]
  */
 protected function search($text)
 {
     $this->resourceFulltext->resetSearchResults();
     $query = $this->queryFactory->get();
     $query->unsetData();
     $query->setQueryText($text);
     $query->saveIncrementalPopularity();
     $products = [];
     $collection = Bootstrap::getObjectManager()->create(Collection::class, ['searchRequestName' => 'quick_search_container']);
     $collection->addSearchFilter($text);
     foreach ($collection as $product) {
         $products[] = $product;
     }
     return $products;
 }
示例#5
0
文件: Full.php 项目: koliaGI/magento2
 /**
  * Regenerate search index for all stores
  *
  * @param int|array|null $productIds
  * @return void
  */
 protected function rebuildIndex($productIds = null)
 {
     $storeIds = array_keys($this->storeManager->getStores());
     foreach ($storeIds as $storeId) {
         $dimension = $this->dimensionFactory->create(['name' => self::SCOPE_FIELD_NAME, 'value' => $storeId]);
         $this->indexHandler->deleteIndex([$dimension], $this->getIterator($productIds));
         $this->indexHandler->saveIndex([$dimension], $this->rebuildStoreIndex($storeId, $productIds));
     }
     $this->fulltextResource->resetSearchResults();
     $this->searchRequestConfig->reset();
 }