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

IBX-7236: Added support of % on both sides of a 'like' statement in fulltext criterion #298

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,20 @@ protected function tokenizeString($string)
*/
protected function getWordExpression(QueryBuilder $query, string $token): string
{
if ($this->configuration['enableWildcards'] && $token[0] === '*') {
return $query->expr()->like(
'word',
$query->createNamedParameter('%' . substr($token, 1))
);
}
$hasLeadingWildcard = str_starts_with($token, '*');
$hasTrailingWildcard = str_ends_with($token, '*');
if ($this->configuration['enableWildcards'] && ($hasLeadingWildcard || $hasTrailingWildcard)) {
$token = $hasLeadingWildcard ? substr($token, 1) : $token;
$token = $hasTrailingWildcard ? substr($token, 0, -1) : $token;

$token = str_replace('%', '\\%', $token);

$token = $hasLeadingWildcard ? '%' . $token : $token;
$token = $hasTrailingWildcard ? $token . '%' : $token;

if ($this->configuration['enableWildcards'] && $token[strlen($token) - 1] === '*') {
return $query->expr()->like(
'word',
$query->createNamedParameter(substr($token, 0, -1) . '%')
$query->createNamedParameter($token)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public function providerForTestFulltextSearchSolr7(): array
'qui*',
[[1, 5, 6, 7, 11, 12, 13, 15]],
],
[
'*row*',
[[2, 5, 8, 9, 11, 12, 14, 15]],
],
Comment on lines +168 to +171
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a closer look this test doesn't test anything related to the changes. See that this entire test case is meant for advanced search capabilities. LSE does not offer them so the test gets skipped.

The test can stay to ensure feature parity (we want this to work on Solr and it seems it's doing that OOTB), but we need dedicated test testing that FullText criterion used on LSE is working too, since you're changing LSE behavior.

Prepare a content with some TextLine (ezstring) containing phrases and add several cases (negative and positive ones). Think it through - what you expect from this feature, what is not desired?

[
'+qui* +fox',
[6, [11, 13], 15],
Expand Down
Loading