public function getCategorySearchQuery($category, $excludedCategories = [])
{
if (!is_object($category)) {
$category = $this->categoryFactory->create()->setStoreId($this->getStoreId())->load($category);
}
$queryParams = ['cached' => true];
if ((bool) $category->getIsVirtualCategory() && $category->getIsActive()) {
$excludedCategories[] = $category->getId();
$queryParams['must'][] = $this->getVirtualCategoryQuery($category, $excludedCategories);
$parentCategory = $this->getVirtualRootCategory($category);
if ($parentCategory && $parentCategory->getId()) {
$queryParams['must'][] = $this->getCategorySearchQuery($parentCategory, $excludedCategories);
}
} elseif ($category->getId() && $category->getIsActive()) {
$queryParams['should'][] = $this->getStandardCategoryQuery($category);
foreach ($this->getChildrenVirtualCategories($category, $excludedCategories) as $childrenCategory) {
$queryParams['should'][] = $this->getVirtualCategoryQuery($childrenCategory, $excludedCategories);
}
}
return $this->queryFactory->create(QueryInterface::TYPE_BOOL, $queryParams);
}