/** * Perform full text search and find IDs of matching products. * * @param string * @return int[] */ private function searchProductsFullText($query) { $searchCriteria = $this->fullTextSearchCriteriaFactory->create(); /** To get list of available request names see Magento/CatalogSearch/etc/search_request.xml */ $searchCriteria->setRequestName('quick_search_container'); $filter = $this->filterBuilder->setField('search_term')->setValue($query)->setConditionType('like')->create(); $filterGroup = $this->searchFilterGroupBuilder->addFilter($filter)->create(); $currentPage = 1; $searchCriteria->setFilterGroups([$filterGroup])->setCurrentPage($currentPage)->setPageSize(self::PRODUCTS_NUMBER_IN_SUGGEST); $searchResults = $this->fullTextSearchApi->search($searchCriteria); $productIds = []; /** * Full text search returns document IDs (in this case product IDs), * so to get products information we need to load them using filtration by these IDs */ foreach ($searchResults->getItems() as $searchDocument) { $productIds[] = $searchDocument->getId(); } return $productIds; }
/** * Create a filter group based on the filter array provided and add to the filter groups * * @param \Magento\Framework\Api\Filter[] $filter * @return $this */ public function addFilter(array $filter) { $this->data[SearchCriteria::FILTER_GROUPS][] = $this->_filterGroupBuilder->setFilters($filter)->create(); return $this; }
/** * Create a filter group based on the filter array provided and add to the filter groups * * @param \Magento\Framework\Api\Filter $filter * @return $this */ public function addFilter(\Magento\Framework\Api\Filter $filter) { $this->filterGroupBuilder->addFilter($filter); return $this; }