I have custom search page that is working perfectly and all the filters are applying properly except category filter.
Following is the code:
$indices = $this->searchResult->getIndices();
foreach ($indices as $index){
if($index->getIdentifier() === "catalogsearch_fulltext") {
$collection = $this->searchResult->getSearchCollection($index);
//Apply filters if required
$this->apiHelper->applyFilters($collection);
$categoryRepository = $objectManager->create("MagentoCatalogModelCategoryRepository");
$category = $categoryRepository->get(176,1);
$collection->addCategoryFilter($category);
if($this->request->getParam("category_id")) {
//code for applying category filter
$category_ids = [$this->request->getParam("category_id")];
$collection->addCategoriesFilter(['in' => $category_ids]);
}
$collection->setPageSize($perPage);
$collection->setCurPage($page);
$size += $collection->getSize();
foreach ($collection as $k => $product) {
$result["products"][] = $this->apiHelper->createListProduct($product, $listProduct);
}
}
}
where $this->searchResult
is the instance of MirasvitSearchBlockResult
after applying this code with category filter product collection return 0 items.
Any help, knowledge and experience sharing would be appreciated