Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit 1184fd6

Browse files
committed
Added highlighting ignore to engine count method
1 parent b1313b7 commit 1184fd6

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

src/ElasticEngine.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ public function buildSearchQueryPayloadCollection(Builder $builder, array $optio
101101

102102
if ($ruleEntity->isApplicable()) {
103103
$payload->setIfNotEmpty('body.query.bool', $ruleEntity->buildQueryPayload());
104-
$payload->setIfNotEmpty('body.highlight', $ruleEntity->buildHighlightPayload());
104+
105+
if ($options['highlight'] ?? true) {
106+
$payload->setIfNotEmpty('body.highlight', $ruleEntity->buildHighlightPayload());
107+
}
105108
} else {
106109
continue;
107110
}
@@ -226,7 +229,7 @@ public function count(Builder $builder)
226229
$count = 0;
227230

228231
$this
229-
->buildSearchQueryPayloadCollection($builder)
232+
->buildSearchQueryPayloadCollection($builder, ['highlight' => false])
230233
->each(function ($payload) use (&$count) {
231234
$result = ElasticClient::count($payload);
232235

tests/ElasticEngineTest.php

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ public function testBuildSearchQueryPayloadCollection()
102102
]
103103
],
104104
'collapse' => [
105-
'field' => 'brand'
106-
],
105+
'field' => 'brand'
106+
],
107107
'sort' => [
108-
[
109-
'id' => 'asc'
110-
]
111-
],
108+
[
109+
'id' => 'asc'
110+
]
111+
],
112112
'from' => 100,
113113
'size' => 10
114114
],
@@ -222,20 +222,14 @@ public function testCount()
222222
'index' => 'test',
223223
'type' => 'test',
224224
'body' => [
225+
'_source' => [
226+
'title',
227+
],
225228
'query' => [
226229
'bool' => [
227230
'must' => [
228-
'match_all' => new stdClass()
229-
],
230-
'filter' => [
231-
'bool' => [
232-
'must' => [
233-
[
234-
'term' => [
235-
'foo' => 'bar'
236-
]
237-
]
238-
]
231+
'query_string' => [
232+
'query' => 'foo'
239233
]
240234
]
241235
]
@@ -245,12 +239,13 @@ public function testCount()
245239

246240
$model = $this->mockModel();
247241

248-
$filterBuilder = (new FilterBuilder($model))
249-
->where('foo', 'bar');
242+
$searchBuilder = (new SearchBuilder($model, 'foo'))
243+
->rule(SearchRule::class)
244+
->select('title');
250245

251246
$this
252247
->engine
253-
->count($filterBuilder);
248+
->count($searchBuilder);
254249

255250
$this->addToAssertionCount(1);
256251
}
@@ -444,4 +439,4 @@ public function testGetTotalCount()
444439
$this->engine->getTotalCount($results)
445440
);
446441
}
447-
}
442+
}

0 commit comments

Comments
 (0)