Exemplo n.º 1
0
 /**
  * Rebuild store index
  *
  * @param int        $storeId
  * @param null|array $ids
  * @return void
  */
 public function rebuildStoreIndex($storeId, $ids = null)
 {
     if (!is_array($ids) && $ids != null) {
         $ids = [$ids];
     }
     $pk = $this->index->getPrimaryKey();
     $attributes = array_keys($this->index->getAttributeWeights());
     $lastEntityId = 0;
     while (true) {
         $collection = $this->index->getSearchableEntities($storeId, $ids, $lastEntityId);
         if ($collection->count() == 0) {
             break;
         }
         /** @var DataObject $entity */
         foreach ($collection as $entity) {
             $document = [];
             foreach ($attributes as $attribute) {
                 $attributeId = $this->index->getAttributeId($attribute);
                 $attributeValue = $entity->getData($attribute);
                 $document[$attributeId] = $this->searchHelper->prepareDataIndex($attributeValue);
             }
             (yield $entity->getData($pk) => $document);
             $lastEntityId = $entity->getData($pk);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function query(RequestInterface $request)
 {
     $query = $this->mapper->buildQuery($request);
     if ($request->getName() == 'quick_search_container') {
         $query->limit($this->searchConfig->getResultsLimit());
     }
     if (isset($_GET) && isset($_GET['debug'])) {
         echo '<hr>' . $query . '<hr>';
     }
     $temporaryStorage = $this->temporaryStorageFactory->create();
     $table = $temporaryStorage->storeDocumentsFromSelect($query);
     $this->searchHelper->prepareTemporaryTable($table);
     $documents = $this->getDocuments($table);
     $aggregations = $this->aggregationBuilder->build($request, $table);
     $response = ['documents' => $documents, 'aggregations' => $aggregations];
     return $this->responseFactory->create($response);
 }
Exemplo n.º 3
0
 /**
  * @param RequestInterface $request
  * @return \Magento\Framework\Search\Response\QueryResponse
  */
 public function query(RequestInterface $request)
 {
     try {
         $query = $this->mapper->buildQuery($request);
         $query->limit($this->searchConfig->getResultsLimit());
     } catch (\Exception $e) {
         // fallback engine
         $objectManager = ObjectManager::getInstance();
         return $objectManager->create('Mirasvit\\SearchMysql\\Model\\Adapter')->query($request);
     }
     $temporaryStorage = $this->temporaryStorageFactory->create();
     $table = $temporaryStorage->storeDocumentsFromSelect($query);
     $this->searchHelper->prepareTemporaryTable($table);
     $documents = $this->getDocuments($table);
     $aggregations = $this->aggregationBuilder->build($request, $table);
     $response = ['documents' => $documents, 'aggregations' => $aggregations];
     return $this->responseFactory->create($response);
 }