Skip to content

Commit 53b652a

Browse files
committed
Manage double wildcards in the terms
1 parent 89dc2fb commit 53b652a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

classes/query.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,10 @@ private function add_wildcards($q) {
149149
}
150150

151151
// Add wild card to start of word.
152-
if (substr($term, 0, 1) != '*') {
153-
$term = '*' . $term;
154-
}
152+
$term = '*' . trim($term, '*');
155153

156154
// Add wild card to end of word.
157-
if (substr($term, -1, 1) != '*') {
158-
$term = $term . '*';
159-
}
155+
$term = rtrim($term, '*') . '*';
160156

161157
$wildcardterms[] = $term;
162158
}

tests/query_test.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,18 @@ public function test_construct_wildcard() {
395395
$proxy = $method->invoke(new \search_elastic\query, $q);
396396
$this->assertEquals('*test*', $proxy);
397397

398+
$q = 'test**';
399+
$proxy = $method->invoke(new \search_elastic\query, $q);
400+
$this->assertEquals('*test*', $proxy);
401+
398402
$q = ' *test';
399403
$proxy = $method->invoke(new \search_elastic\query, $q);
400404
$this->assertEquals('*test*', $proxy);
401405

406+
$q = '***test';
407+
$proxy = $method->invoke(new \search_elastic\query, $q);
408+
$this->assertEquals('*test*', $proxy);
409+
402410
$q = '*test*';
403411
$proxy = $method->invoke(new \search_elastic\query, $q);
404412
$this->assertEquals('*test*', $proxy);

0 commit comments

Comments
 (0)