Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight stop words if they appear in the query #132

Merged
merged 11 commits into from
Dec 16, 2024
Prev Previous commit
Next Next commit
Add test for stopword match positions
Signed-off-by: Philipp Daun <[email protected]>
  • Loading branch information
daun committed Dec 7, 2024
commit 9d82d6bc381add1625a944c2b84a6730285ed46b
67 changes: 60 additions & 7 deletions tests/Functional/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,12 @@ public static function highlightingProvider(): \Generator
[
'start' => 3,
'length' => 8,
'stopword' => false,
],
[
'start' => 79,
'length' => 13,
'stopword' => false,
],
],
],
Expand Down Expand Up @@ -296,10 +298,12 @@ public static function highlightingProvider(): \Generator
[
'start' => 3,
'length' => 8,
'stopword' => false,
],
[
'start' => 79,
'length' => 13,
'stopword' => false,
],
],
],
Expand All @@ -313,6 +317,53 @@ public static function highlightingProvider(): \Generator
],
];

yield 'Highlight with matches position of stopwords' => [
'her assassin',
['title', 'overview'],
[],
true,
[
'hits' => [
[
'id' => 24,
'title' => 'Kill Bill: Vol. 1',
'overview' => 'An assassin is shot by her ruthless employer, Bill, and other members of their assassination circle – but she lives to plot her vengeance.',
'genres' => ['Action', 'Crime'],
'_matchesPosition' => [
'overview' => [
[
'start' => 3,
'length' => 8,
'stopword' => false,
],
[
'start' => 23,
'length' => 3,
'stopword' => true,
],
[
'start' => 79,
'length' => 13,
'stopword' => false,
],
[
'start' => 124,
'length' => 3,
'stopword' => true,
],
],
],
],
],
'query' => 'her assassin',
'hitsPerPage' => 20,
'page' => 1,
'totalPages' => 1,
'totalHits' => 1,
],
['her'],
];

yield 'Highlight with typo' => [
'assasin',
['title', 'overview'],
Expand Down Expand Up @@ -439,12 +490,12 @@ public static function highlightingProvider(): \Generator
'id' => 6,
'title' => 'Judgment Night',
'overview' => 'While racing to a boxing match, Frank, Mike, John and Rey get more than they bargained for. A wrong turn lands them directly in the path of Fallon, a vicious, wise-cracking drug lord. After accidentally witnessing Fallon murder a disloyal henchman, the four become his unwilling prey in a savage game of cat & mouse as they are mercilessly stalked through the urban jungle in this taut suspense drama',
'genres' => ["Action","Thriller","Crime"],
'genres' => ['Action', 'Thriller', 'Crime'],
'_formatted' => [
'id' => 6,
'title' => 'Judgment Night',
'overview' => "While <em>racing to a boxing match</em>, Frank, Mike, John and Rey get more than they bargained for. A wrong turn lands them directly in the path of Fallon, a vicious, wise-cracking drug lord. After accidentally witnessing Fallon murder a disloyal henchman, the four become his unwilling prey in a savage game of cat & mouse as they are mercilessly stalked through the urban jungle in this taut suspense drama",
'genres' => ["Action","Thriller","Crime"],
'overview' => 'While <em>racing to a boxing match</em>, Frank, Mike, John and Rey get more than they bargained for. A wrong turn lands them directly in the path of Fallon, a vicious, wise-cracking drug lord. After accidentally witnessing Fallon murder a disloyal henchman, the four become his unwilling prey in a savage game of cat & mouse as they are mercilessly stalked through the urban jungle in this taut suspense drama',
'genres' => ['Action', 'Thriller', 'Crime'],
],
],
],
Expand All @@ -454,7 +505,7 @@ public static function highlightingProvider(): \Generator
'totalPages' => 1,
'totalHits' => 1,
],
['of', 'the', 'an', 'but', 'to', 'a']
['of', 'the', 'an', 'but', 'to', 'a'],
];

yield 'Highlight literal match including stopwords' => [
Expand All @@ -468,12 +519,12 @@ public static function highlightingProvider(): \Generator
'id' => 22,
'title' => 'Pirates of the Caribbean: The Curse of the Black Pearl',
'overview' => "Jack Sparrow, a freewheeling 18th-century pirate, quarrels with a rival pirate bent on pillaging Port Royal. When the governor's daughter is kidnapped, Sparrow decides to help the girl's love save her.",
'genres' => ["Adventure","Fantasy","Action"],
'genres' => ['Adventure', 'Fantasy', 'Action'],
'_formatted' => [
'id' => 22,
'title' => '<em>Pirates of the Caribbean</em>: <em>The Curse of the Black Pearl</em>',
'overview' => "Jack Sparrow, a freewheeling 18th-century pirate, quarrels with a rival pirate bent on pillaging Port Royal. When the governor's daughter is kidnapped, Sparrow decides to help the girl's love save her.",
'genres' => ["Adventure","Fantasy","Action"],
'genres' => ['Adventure', 'Fantasy', 'Action'],
],
],
],
Expand All @@ -483,7 +534,7 @@ public static function highlightingProvider(): \Generator
'totalPages' => 1,
'totalHits' => 1,
],
['of', 'the', 'an', 'but', 'to', 'a', 'back']
['of', 'the', 'an', 'but', 'to', 'a', 'back'],
];

yield 'Highlight with match at the end' => [
Expand Down Expand Up @@ -566,6 +617,7 @@ public static function highlightingProvider(): \Generator
[
'start' => 0,
'length' => 6,
'stopword' => false,
],
],
],
Expand All @@ -587,6 +639,7 @@ public static function highlightingProvider(): \Generator
0 => [
'start' => 127,
'length' => 6,
'stopword' => false,
],
],
],
Expand Down