Skip to content

Commit

Permalink
ENGCOM-4504: Make sure Yes/No attribute Layered Navigation filter use…
Browse files Browse the repository at this point in the history
…s index #21772
  • Loading branch information
sivaschenko authored Apr 23, 2019
2 parents 0f41361 + c294309 commit efd431e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\CatalogSearch\Model\Search\FilterMapper\VisibilityFilter;
use Magento\CatalogSearch\Model\Search\TableMapper;
use Magento\Customer\Model\Session;
use Magento\Eav\Model\Config;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ObjectManager;
Expand All @@ -20,10 +22,11 @@
use Magento\Framework\Search\Adapter\Mysql\Filter\PreprocessorInterface;
use Magento\Framework\Search\Request\FilterInterface;
use Magento\Store\Model\Store;
use Magento\Customer\Model\Session;
use Magento\CatalogSearch\Model\Search\FilterMapper\VisibilityFilter;

/**
* ElasticSearch search filter pre-processor.
*
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @deprecated
* @see \Magento\ElasticSearch
Expand Down Expand Up @@ -128,18 +131,21 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function process(FilterInterface $filter, $isNegation, $query)
{
return $this->processQueryWithField($filter, $isNegation, $query);
}

/**
* Process query with field.
*
* @param FilterInterface $filter
* @param bool $isNegation
* @param string $query
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function processQueryWithField(FilterInterface $filter, $isNegation, $query)
{
Expand Down Expand Up @@ -170,7 +176,7 @@ private function processQueryWithField(FilterInterface $filter, $isNegation, $qu
} elseif ($filter->getField() === VisibilityFilter::VISIBILITY_FILTER_FIELD) {
return '';
} elseif ($filter->getType() === FilterInterface::TYPE_TERM &&
in_array($attribute->getFrontendInput(), ['select', 'multiselect'], true)
in_array($attribute->getFrontendInput(), ['select', 'multiselect', 'boolean'], true)
) {
$resultQuery = $this->processTermSelect($filter, $isNegation);
} elseif ($filter->getType() === FilterInterface::TYPE_RANGE &&
Expand Down Expand Up @@ -204,19 +210,23 @@ private function processQueryWithField(FilterInterface $filter, $isNegation, $qu
->where('main_table.store_id = ?', Store::DEFAULT_STORE_ID)
->having($query);

$resultQuery = 'search_index.entity_id IN (
select entity_id from ' . $this->conditionManager->wrapBrackets($select) . ' as filter
)';
$resultQuery = 'search_index.entity_id IN ('
. 'select entity_id from '
. $this->conditionManager->wrapBrackets($select)
. ' as filter)';
}

return $resultQuery;
}

/**
* Process range numeric.
*
* @param FilterInterface $filter
* @param string $query
* @param Attribute $attribute
* @return string
* @throws \Exception
*/
private function processRangeNumeric(FilterInterface $filter, $query, $attribute)
{
Expand All @@ -238,14 +248,17 @@ private function processRangeNumeric(FilterInterface $filter, $query, $attribute
->where('main_table.store_id = ?', $currentStoreId)
->having($query);

$resultQuery = 'search_index.entity_id IN (
select entity_id from ' . $this->conditionManager->wrapBrackets($select) . ' as filter
)';
$resultQuery = 'search_index.entity_id IN ('
. 'select entity_id from '
. $this->conditionManager->wrapBrackets($select)
. ' as filter)';

return $resultQuery;
}

/**
* Process term select.
*
* @param FilterInterface $filter
* @param bool $isNegation
* @return string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function isCustom(FilterInterface $filter)

return $attribute
&& $filter->getType() === FilterInterface::TYPE_TERM
&& in_array($attribute->getFrontendInput(), ['select', 'multiselect'], true);
&& in_array($attribute->getFrontendInput(), ['select', 'multiselect', 'boolean'], true);
}

/**
Expand Down

0 comments on commit efd431e

Please sign in to comment.