Skip to content

Commit 81b7d3c

Browse files
authored
Merge pull request #331 from andrii-pukhalevych/andrii-pukhalevych-patch-1
Allow bool in where conditions
2 parents afe788b + 71bbfd4 commit 81b7d3c

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/QueryBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,11 @@ public function match(string $field, string $value): MatchQuery
496496
* }}}
497497
*
498498
* @param string $field The field to query by.
499-
* @param string $value The term to find in field.
499+
* @param string|float|int|bool $value The term to find in field.
500500
* @return \Elastica\Query\Term
501501
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
502502
*/
503-
public function term(string $field, string|int|float $value): Term
503+
public function term(string $field, string|float|int|bool $value): Term
504504
{
505505
return new Elastica\Query\Term([$field => $value]);
506506
}

tests/TestCase/QueryBuilderTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,24 @@ public function testTerm()
545545
'term' => ['user.name' => 'jose'],
546546
];
547547
$this->assertEquals($expected, $result->toArray());
548+
549+
$result = $builder->term('user.id', 1);
550+
$expected = [
551+
'term' => ['user.id' => 1],
552+
];
553+
$this->assertEquals($expected, $result->toArray());
554+
555+
$result = $builder->term('user.rate', 4.5);
556+
$expected = [
557+
'term' => ['user.rate' => 4.5],
558+
];
559+
$this->assertEquals($expected, $result->toArray());
560+
561+
$result = $builder->term('user.is_enabled', true);
562+
$expected = [
563+
'term' => ['user.is_enabled' => true],
564+
];
565+
$this->assertEquals($expected, $result->toArray());
548566
}
549567

550568
/**

0 commit comments

Comments
 (0)