Skip to content

Commit

Permalink
Merge pull request #15 from swisnl/JaZo-patch-1
Browse files Browse the repository at this point in the history
Remove leading spaces to prevent empty terms
  • Loading branch information
bbrala authored Jan 28, 2019
2 parents 6d467c4 + 264b537 commit 122d4d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/TermBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static function terms($search)

// Remove every boolean operator (+, -, > <, ( ), ~, *, ", @distance) from the search query
// else we will break the MySQL query.
$search = rtrim(preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $search));
$search = trim(preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $search));

$terms = collect(preg_split('/[\s,]+/', $search));

Expand Down
12 changes: 12 additions & 0 deletions tests/TermBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ public function test_termbuilder_builds_terms_array()
$this->assertCount(0, $diff);
}

public function test_termbuilder_does_not_build_empty_terms()
{
global $configReturn;
$configReturn = false;

$termsResult = ['<hi', 'im', 'a', 'few', 'terms>'];
$terms = TermBuilder::terms(implode(' ', $termsResult));
$termsResultWithoutSpecialChars = ['hi', 'im', 'a', 'few', 'terms'];
$diff = $terms->diff($termsResultWithoutSpecialChars);
$this->assertCount(0, $diff);
}

public function test_termbuilder_builds_terms_array_with_wildcard()
{
global $configReturn;
Expand Down

0 comments on commit 122d4d6

Please sign in to comment.