From 0794ef2c692f8b6a61e3bd8a945616fee0c911a7 Mon Sep 17 00:00:00 2001 From: Yuriy Potemkin Date: Mon, 3 Sep 2018 17:02:24 +0300 Subject: [PATCH] add highlight documentation --- readme.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/readme.md b/readme.md index 2dcdb9b..6a40bfa 100644 --- a/readme.md +++ b/readme.md @@ -35,6 +35,7 @@ This will create a config file at `config/plastic.php` and a mapping directory a - [Searching](#searching) - [Aggregation](#aggregation) - [Suggestions](#suggestions) +- [Highlighting](#highlighting) - [Mappings](#mappings) - [Populate An Index](#populate-an-index) - [Access The Client](#access-client) @@ -240,6 +241,23 @@ The suggestions query builder can also be accessed directly from the model as we Tag::suggest()->term('tag_term','admin')->get(); ``` +## [Highlighting]() + +```php +$highlight = new Highlight(); +$highlight->setTags([''], ['']); +$highlight->addField('title', ['matched_fields' => ['title']]); +$highlight->addField('content', ['matched_fields' => ['content']]); + +$highlight->setParameters([ + 'require_field_match' => false, + 'force_source' => true, +]); + + +$search->query->addHighlight($highlight); +``` + ## [Model Mapping]() Mappings are an important aspect of Elasticsearch. You can compare them to indexing in SQL databases. Mapping your models yields better and more efficient search results, and allows us to use some special query functions like nested fields and suggestions.