Skip to content

Commit

Permalink
fix(ecl): make sure wild only regex queries do not produce an...
Browse files Browse the repository at this point in the history
...actual low-level query clause
  • Loading branch information
cmark committed May 8, 2024
1 parent d26349f commit 8391852
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.regex.Pattern;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -57,6 +58,9 @@
public abstract class EclEvaluationRequest<C extends ServiceProvider> implements Request<C, Promise<Expression>> {

private static final long serialVersionUID = 1L;

private static final Pattern WILD_ANY = Pattern.compile("(\\*)+");
private static final Pattern REGEX_ANY = Pattern.compile("(\\.\\*)+");

private final PolymorphicDispatcher<Promise<Expression>> dispatcher = PolymorphicDispatcher.createForSingleTarget("eval", 2, 2, this);

Expand Down Expand Up @@ -505,10 +509,18 @@ protected Expression toExpression(final TypedSearchTermClause clause) {
.synonyms(false)
.build());
case WILD:
final String regex = term.replace("*", ".*");
return termRegexExpression(regex, true);
if (WILD_ANY.matcher(term).matches()) {
return Expressions.matchAll();
} else {
final String regex = term.replace("*", ".*");
return termRegexExpression(regex, true);
}
case REGEX:
return termRegexExpression(term, false);
if (REGEX_ANY.matcher(term).matches()) {
return Expressions.matchAll();
} else {
return termRegexExpression(term, false);
}
case EXACT:
return termCaseInsensitiveExpression(term);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.b2international.snowowl.snomed.core.ecl;

import static com.b2international.snowowl.test.commons.snomed.RandomSnomedIdentiferGenerator.generateDescriptionId;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;

import java.util.*;

Expand Down Expand Up @@ -271,6 +271,26 @@ public void termWildElasticsearchOptionalFlagsShouldNotInterfere() throws Except
assertEquals(expected, actual);
}

@Test
public void termWildAnyCharacterShouldNotCreateQueryClause() throws Exception {
final Expression actualTwo = eval("* {{ term = wild:\"**\" }}");
final Expression actualThree = eval("* {{ term = wild:\"***\" }}");
Expression expected = Expressions.matchAll();
assertEquals(expected, actualTwo);
assertEquals(expected, actualThree);
}

@Test
public void termRegexAnyCharacterShouldNotCreateQueryClause() throws Exception {
final Expression actualOne = eval("* {{ term = regex:\".*\" }}");
final Expression actualTwo = eval("* {{ term = regex:\".*.*\" }}");
final Expression actualThree = eval("* {{ term = regex:\".*.*.*\" }}");
Expression expected = Expressions.matchAll();
assertEquals(expected, actualOne);
assertEquals(expected, actualTwo);
assertEquals(expected, actualThree);
}

@Test
public void disjunctionActiveAndModuleId() throws Exception {
final Expression actual = eval("* {{ c active = true OR moduleId = " + Concepts.MODULE_SCT_CORE + " }}");
Expand Down

0 comments on commit 8391852

Please sign in to comment.