Skip to content

Commit 35593ff

Browse files
author
barton
committed
implemented match,match_pharse in Query::where()
1 parent cac21c9 commit 35593ff

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

QueryBuilder.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ public function buildCondition($condition)
205205
'>' => 'buildHalfBoundedRangeCondition',
206206
'gte' => 'buildHalfBoundedRangeCondition',
207207
'>=' => 'buildHalfBoundedRangeCondition',
208+
'match' => 'buildMatchCondition',
209+
'match_phrase' => 'buildMatchCondition',
208210
];
209211

210212
if (empty($condition)) {
@@ -462,4 +464,11 @@ private function buildLikeCondition($operator, $operands)
462464
{
463465
throw new NotSupportedException('like conditions are not supported by Elasticsearch.');
464466
}
467+
468+
private function buildMatchCondition($operator, $operands)
469+
{
470+
return [
471+
$operator => [ $operands[0] => $operands[1] ]
472+
];
473+
}
465474
}

tests/QueryBuilderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,14 @@ public function testBuildInCondition()
280280
]);
281281
$this->assertEquals($expected, $result);
282282
}
283+
284+
public function testBuildMatchCondition()
285+
{
286+
$result = (new Query())
287+
->from('builder-test', 'article')
288+
->where(['match', 'title', 'yii'])
289+
->search($this->getConnection());
290+
$total = is_array($result['hits']['total']) ? $result['hits']['total']['value'] : $result['hits']['total'];
291+
$this->assertEquals(2, $total);
292+
}
283293
}

0 commit comments

Comments
 (0)