laravel-scout-tntsearch-driver
laravel-scout-tntsearch-driver copied to clipboard
How to get highlighted match result ?
I want to apply this to my website api but can not figure out how to get highlighted match result ,
How should I do to do result highlight?
Thanks a lot!
Here's an example on how to use the highlighter
https://github.com/teamtnt/tntsearch-demo/blob/51e6ccc11168dc06f8cd837be1b5cda3e0518a1b/app/Http/Controllers/SearchController.php
lines 89 and 93
Hi @nticaric, thanks a lot for your reply, I make it after refer to the link you gave me and the source code of tntsearch.
I think is good to give the code below as reference to others(actually from source code tntsearch\tests\support\HighlighterTest.php):
use TeamTNT\TNTSearch\Support\Highlighter; $hl = new Highlighter; $text = "This is some text"; $output = $hl->highlight($text, "is text", 'em', ['wholeWord' => false]); $this->assertEquals("Th<em>is</em> <em>is</em> some <em>text</em>", $output); $output = $hl->highlight($text, "is text", 'em', ['wholeWord' => true]); $this->assertEquals("This <em>is</em> some <em>text</em>", $output); $output = $hl->highlight($text, "this text", 'em', ['caseSensitive' => true]); $this->assertEquals("This is some <em>text</em>", $output); $output = $hl->highlight($text, "this text", 'em', ['caseSensitive' => false]); $this->assertEquals("<em>This</em> is some <em>text</em>", $output); $output = $hl->highlight($text, "text", 'em'); $this->assertEquals("This is some <em>text</em>", $output); $output = $hl->highlight($text, "text", 'b'); $this->assertEquals("This is some <b>text</b>", $output);
Thanks again!