Example #1
0
 /**
  * Search the text and return result collection
  *
  * @param string $text
  * @return \Magento\Catalog\Model\Product[]
  */
 protected function search($text)
 {
     $this->resourceFulltext->resetSearchResults();
     $query = $this->queryFactory->create();
     $query->setQueryText($text)->prepare();
     $this->resourceFulltext->prepareResult($this->fulltext, $text, $query);
     $query->getResultCollection();
     $products = [];
     foreach ($query->getResultCollection() as $product) {
         $products[] = $product;
     }
     return $products;
 }
Example #2
0
 /**
  * Retrieve query model object
  *
  * @return Query
  */
 public function getQuery()
 {
     if (!$this->_query) {
         $this->_query = $this->_queryFactory->create()->loadByQuery($this->getQueryText());
         if (!$this->_query->getId()) {
             $this->_query->setQueryText($this->getQueryText());
         }
     }
     return $this->_query;
 }