Fix some query methods in runtime fields

We were missing a few `@Override` annotations in runtime fields which
let us drift from the methods we were supposed to override. Oops. This
adds them and links the methods.
This commit is contained in:
Nik Everett 2020-09-10 16:26:47 -04:00
parent e0a81f7d14
commit ac23380560
4 changed files with 26 additions and 6 deletions

View File

@ -91,6 +91,7 @@ abstract class AbstractScriptMappedFieldType extends MappedFieldType {
QueryShardContext context
);
@Override
public Query fuzzyQuery(
Object value,
Fuzziness fuzziness,
@ -102,17 +103,21 @@ abstract class AbstractScriptMappedFieldType extends MappedFieldType {
throw new IllegalArgumentException(unsupported("fuzzy", "keyword and text"));
}
@Override
public Query prefixQuery(String value, MultiTermQuery.RewriteMethod method, QueryShardContext context) {
throw new IllegalArgumentException(unsupported("prefix", "keyword, text and wildcard"));
}
@Override
public Query wildcardQuery(String value, MultiTermQuery.RewriteMethod method, QueryShardContext context) {
throw new IllegalArgumentException(unsupported("wildcard", "keyword, text and wildcard"));
}
@Override
public Query regexpQuery(
String value,
int flags,
int syntaxFlags,
int matchFlags,
int maxDeterminizedStates,
MultiTermQuery.RewriteMethod method,
QueryShardContext context
@ -120,20 +125,25 @@ abstract class AbstractScriptMappedFieldType extends MappedFieldType {
throw new IllegalArgumentException(unsupported("regexp", "keyword and text"));
}
@Override
public abstract Query existsQuery(QueryShardContext context);
@Override
public Query phraseQuery(TokenStream stream, int slop, boolean enablePositionIncrements) throws IOException {
throw new IllegalArgumentException(unsupported("phrase", "text"));
}
@Override
public Query multiPhraseQuery(TokenStream stream, int slop, boolean enablePositionIncrements) throws IOException {
throw new IllegalArgumentException(unsupported("phrase", "text"));
}
@Override
public Query phrasePrefixQuery(TokenStream stream, int slop, int maxExpansions) throws IOException {
throw new IllegalArgumentException(unsupported("phrase prefix", "text"));
}
@Override
public SpanQuery spanPrefixQuery(String value, SpanMultiTermQueryWrapper.SpanRewriteMethod method, QueryShardContext context) {
throw new IllegalArgumentException(unsupported("span prefix", "text"));
}

View File

@ -127,9 +127,19 @@ public final class ScriptKeywordMappedFieldType extends AbstractScriptMappedFiel
}
@Override
public Query regexpQuery(String value, int flags, int maxDeterminizedStates, RewriteMethod method, QueryShardContext context) {
public Query regexpQuery(
String value,
int syntaxFlags,
int matchFlags,
int maxDeterminizedStates,
RewriteMethod method,
QueryShardContext context
) {
checkAllowExpensiveQueries(context);
return new StringScriptFieldRegexpQuery(script, leafFactory(context.lookup()), name(), value, flags, maxDeterminizedStates);
if (matchFlags != 0) {
throw new IllegalArgumentException("Match flags not yet implemented [" + matchFlags + "]");
}
return new StringScriptFieldRegexpQuery(script, leafFactory(context.lookup()), name(), value, syntaxFlags, maxDeterminizedStates);
}
@Override

View File

@ -28,7 +28,7 @@ abstract class AbstractNonTextScriptMappedFieldTypeTestCase extends AbstractScri
public void testRegexpQueryIsError() throws IOException {
assertQueryOnlyOnTextAndKeyword(
"regexp",
() -> simpleMappedFieldType().regexpQuery("cat", 0, Operations.DEFAULT_MAX_DETERMINIZED_STATES, null, mockContext())
() -> simpleMappedFieldType().regexpQuery("cat", 0, 0, Operations.DEFAULT_MAX_DETERMINIZED_STATES, null, mockContext())
);
}

View File

@ -254,7 +254,7 @@ public class ScriptKeywordMappedFieldTypeTests extends AbstractScriptMappedField
IndexSearcher searcher = newSearcher(reader);
assertThat(
searcher.count(
simpleMappedFieldType().regexpQuery("ca.+", 0, Operations.DEFAULT_MAX_DETERMINIZED_STATES, null, mockContext())
simpleMappedFieldType().regexpQuery("ca.+", 0, 0, Operations.DEFAULT_MAX_DETERMINIZED_STATES, null, mockContext())
),
equalTo(2)
);
@ -263,7 +263,7 @@ public class ScriptKeywordMappedFieldTypeTests extends AbstractScriptMappedField
}
public void testRegexpQueryIsExpensive() throws IOException {
checkExpensiveQuery((ft, ctx) -> ft.regexpQuery(randomAlphaOfLengthBetween(1, 1000), randomInt(0xFFFF), randomInt(), null, ctx));
checkExpensiveQuery((ft, ctx) -> ft.regexpQuery(randomAlphaOfLengthBetween(1, 1000), randomInt(0xFFFF), 0, randomInt(), null, ctx));
}
@Override