You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 4, 2021. It is now read-only.
:coffee: If you like my package, it'd be nice of you [to buy me a cup of coffee](https://www.paypal.me/ivanbabenko).
8
+
:beer: If you like my package, it'd be nice of you [to buy me a beer](https://www.paypal.me/ivanbabenko).
9
9
10
10
:octocat: The project has a [chat room on Gitter](https://gitter.im/scout-elasticsearch-driver/Lobby)!
11
11
@@ -304,7 +304,20 @@ use ScoutElastic\SearchRule;
304
304
305
305
class MySearch extends SearchRule
306
306
{
307
-
// This method returns an array that represents a content of bool query.
307
+
// This method returns an array, describes how to highlight the results.
308
+
// If null is returned, no highlighting will be used.
309
+
public function buildHighlightPayload()
310
+
{
311
+
return [
312
+
'fields' => [
313
+
'name' => [
314
+
'type' => 'plain'
315
+
]
316
+
]
317
+
];
318
+
}
319
+
320
+
// This method returns an array, that represents bool query.
308
321
public function buildQueryPayload()
309
322
{
310
323
return [
@@ -318,7 +331,8 @@ class MySearch extends SearchRule
318
331
}
319
332
```
320
333
321
-
You can read more about bool queries [here](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-bool-query.html).
334
+
You can read more about bool queries [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html)
335
+
and about highlighting [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html#search-request-highlighting).
322
336
323
337
The default search rule returns the following payload:
To retrieve highlight, use model `highlight` attribute:
395
+
396
+
```php
397
+
// Let's say we highlight field `name` of `MyModel`.
398
+
$model = App\MyModel::search('Brazil')
399
+
->rule(App\MySearchRule::class)
400
+
->first();
401
+
402
+
// Now you can get raw highlighted value:
403
+
$model->highlight->name;
404
+
405
+
// or string value:
406
+
$model->highlight->nameAsString;
407
+
```
408
+
380
409
## Available filters
381
410
382
411
You can use different types of filters:
@@ -391,7 +420,7 @@ whereBetween($field, $value) | whereBetween('price', [100, 200]) | Checks if a v
391
420
whereNotBetween($field, $value) | whereNotBetween('price', [100, 200]) | Checks if a value isn't in a range.
392
421
whereExists($field) | whereExists('unemployed') | Checks if a value is defined.
393
422
whereNotExists($field) | whereNotExists('unemployed') | Checks if a value isn't defined.
394
-
whereRegexp($field, $value, $flags = 'ALL') | whereRegexp('name.raw', 'A.+') | Filters records according to a given regular expression. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-regexp-query.html#regexp-syntax) you can find more about syntax.
423
+
whereRegexp($field, $value, $flags = 'ALL') | whereRegexp('name.raw', 'A.+') | Filters records according to a given regular expression. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html#regexp-syntax) you can find more about syntax.
395
424
whereGeoDistance($field, $value, $distance) | whereGeoDistance('location', [-70, 40], '1000m') | Filters records according to given point and distance from it. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html) you can find more about syntax.
396
425
whereGeoBoundingBox($field, array $value) | whereGeoBoundingBox('location', ['top_left' => [-74.1, 40.73], 'bottom_right' => [-71.12, 40.01]]) | Filters records within given boundings. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html) you can find more about syntax.
397
426
whereGeoPolygon($field, array $points) | whereGeoPolygon('location', [[-70, 40],[-80, 30],[-90, 20]]) | Filters records within given polygon. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html) you can find more about syntax.
0 commit comments