Skip to content

Commit

Permalink
Merge pull request #735 from afoucret/es-6-fix-boolean-catalog-rule
Browse files Browse the repository at this point in the history
Es 6 fix boolean catalog rule
  • Loading branch information
afoucret authored Feb 7, 2018
2 parents 87c2f81 + bdfb552 commit 2088b3e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ public function getSearchQuery(ProductCondition $productCondition)

$query = $this->getSpecialAttributesSearchQuery($productCondition);

$this->prepareFieldValue($productCondition);

if ($query === null && !empty($productCondition->getValue())) {
$this->prepareFieldValue($productCondition);
$queryType = QueryInterface::TYPE_TERMS;
$queryParams = $this->getTermsQueryParams($productCondition);

Expand Down Expand Up @@ -197,13 +196,18 @@ private function getRangeQueryParams(ProductCondition $productCondition)
*/
private function getTermsQueryParams(ProductCondition $productCondition)
{
$field = $this->getSearchField($productCondition);
$fieldName = $this->getSearchFieldName($productCondition);
$values = $productCondition->getValue();

if (!is_array($values) && in_array($productCondition->getOperator(), ['()', '!()'])) {
$values = explode(',', $values);
}

if ($field->getType() == FieldInterface::FIELD_TYPE_BOOLEAN) {
$values = (bool) $values;
}

return ['field' => $fieldName, 'values' => $values];
}

Expand Down Expand Up @@ -237,7 +241,7 @@ private function applyNegation(QueryInterface $query)
*
* @param ProductCondition $productCondition Product condition.
*
* @return \Smile\ElasticsuiteCore\Model\Search\Request\RelevanceConfig\FieldInterface
* @return \Smile\ElasticsuiteCore\Api\Index\Mapping\FieldInterface
*/
private function getSearchField(ProductCondition $productCondition)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public function getAttributeCode()
*/
public function getSearchQuery()
{
$query = $this->queryFactory->create(QueryInterface::TYPE_MISSING, ['field' => 'image']);

return $this->queryFactory->create(QueryInterface::TYPE_NOT, ['query' => $query]);
return $this->queryFactory->create(QueryInterface::TYPE_EXISTS, ['field' => 'image']);
}

/**
Expand Down Expand Up @@ -102,7 +100,7 @@ public function getValueName()
*/
public function getValue()
{
return 1;
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getValueName()
*/
public function getValue()
{
return 1;
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getValueName()
*/
public function getValue()
{
return 1;
return true;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/module-elasticsuite-core/Search/Request/Query/Terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ class Terms extends Term
*/
public function __construct($values, $field, $name = null, $boost = QueryInterface::DEFAULT_BOOST_VALUE)
{
if (!is_array($values)) {
if (!is_array($values) && is_string($values)) {
$values = explode(',', $values);
} elseif (!is_array($values)) {
$values = [$values];
}

parent::__construct($values, $field, $name, $boost);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public function testAnonymousTermsQueryBuilder()
$termsQuery = new TermsQuery('value1,value2', 'field');
$query = $builder->buildQuery($termsQuery);
$this->assertEquals(['value1', 'value2'], $query['terms']['field']);

$termsQuery = new TermsQuery(true, 'field');
$query = $builder->buildQuery($termsQuery);
$this->assertEquals([true], $query['terms']['field']);
}

/**
Expand Down

0 comments on commit 2088b3e

Please sign in to comment.