Rename field_masking_span to span_field_masking (#1606)
* Rename field_masking_span to span_field_masking Signed-off-by: Xue Zhou <xuezhou@amazon.com> * Update SearchModuleTests.java Signed-off-by: Xue Zhou <xuezhou@amazon.com> * Rename field_masking_span to span_field_masking Signed-off-by: Xue Zhou <xuezhou@amazon.com>
This commit is contained in:
parent
84772904be
commit
74943c43c6
|
@ -48,7 +48,7 @@ import java.io.IOException;
|
|||
import java.util.Objects;
|
||||
|
||||
public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMaskingSpanQueryBuilder> implements SpanQueryBuilder {
|
||||
public static final String NAME = "field_masking_span";
|
||||
public static final ParseField SPAN_FIELD_MASKING_FIELD = new ParseField("span_field_masking", "field_masking_span");
|
||||
|
||||
private static final ParseField FIELD_FIELD = new ParseField("field");
|
||||
private static final ParseField QUERY_FIELD = new ParseField("query");
|
||||
|
@ -105,7 +105,7 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
|||
|
||||
@Override
|
||||
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject(NAME);
|
||||
builder.startObject(SPAN_FIELD_MASKING_FIELD.getPreferredName());
|
||||
builder.field(QUERY_FIELD.getPreferredName());
|
||||
queryBuilder.toXContent(builder, params);
|
||||
builder.field(FIELD_FIELD.getPreferredName(), fieldName);
|
||||
|
@ -129,13 +129,16 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
|||
if (QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
|
||||
QueryBuilder query = parseInnerQueryBuilder(parser);
|
||||
if (query instanceof SpanQueryBuilder == false) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "[field_masking_span] query must be of type span query");
|
||||
throw new ParsingException(
|
||||
parser.getTokenLocation(),
|
||||
"[" + SPAN_FIELD_MASKING_FIELD.getPreferredName() + "] query must be of type span query"
|
||||
);
|
||||
}
|
||||
inner = (SpanQueryBuilder) query;
|
||||
} else {
|
||||
throw new ParsingException(
|
||||
parser.getTokenLocation(),
|
||||
"[field_masking_span] query does not support [" + currentFieldName + "]"
|
||||
"[" + SPAN_FIELD_MASKING_FIELD.getPreferredName() + "] query does not support [" + currentFieldName + "]"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
@ -148,16 +151,22 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
|||
} else {
|
||||
throw new ParsingException(
|
||||
parser.getTokenLocation(),
|
||||
"[field_masking_span] query does not support [" + currentFieldName + "]"
|
||||
"[" + SPAN_FIELD_MASKING_FIELD.getPreferredName() + "] query does not support [" + currentFieldName + "]"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inner == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "field_masking_span must have [query] span query clause");
|
||||
throw new ParsingException(
|
||||
parser.getTokenLocation(),
|
||||
SPAN_FIELD_MASKING_FIELD.getPreferredName() + " must have [query] span query clause"
|
||||
);
|
||||
}
|
||||
if (field == null) {
|
||||
throw new ParsingException(parser.getTokenLocation(), "field_masking_span must have [field] set for it");
|
||||
throw new ParsingException(
|
||||
parser.getTokenLocation(),
|
||||
SPAN_FIELD_MASKING_FIELD.getPreferredName() + " must have [field] set for it"
|
||||
);
|
||||
}
|
||||
|
||||
FieldMaskingSpanQueryBuilder queryBuilder = new FieldMaskingSpanQueryBuilder(inner, field);
|
||||
|
@ -190,6 +199,6 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder<FieldMask
|
|||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
return NAME;
|
||||
return SPAN_FIELD_MASKING_FIELD.getPreferredName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1172,7 +1172,7 @@ public class SearchModule {
|
|||
);
|
||||
registerQuery(
|
||||
new QuerySpec<>(
|
||||
FieldMaskingSpanQueryBuilder.NAME,
|
||||
FieldMaskingSpanQueryBuilder.SPAN_FIELD_MASKING_FIELD,
|
||||
FieldMaskingSpanQueryBuilder::new,
|
||||
FieldMaskingSpanQueryBuilder::fromXContent
|
||||
)
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.opensearch.test.AbstractQueryTestCase;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.opensearch.index.query.FieldMaskingSpanQueryBuilder.SPAN_FIELD_MASKING_FIELD;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
|
||||
|
@ -73,7 +74,9 @@ public class FieldMaskingSpanQueryBuilderTests extends AbstractQueryTestCase<Fie
|
|||
|
||||
public void testFromJson() throws IOException {
|
||||
String json = "{\n"
|
||||
+ " \"field_masking_span\" : {\n"
|
||||
+ " \""
|
||||
+ SPAN_FIELD_MASKING_FIELD.getPreferredName()
|
||||
+ "\" : {\n"
|
||||
+ " \"query\" : {\n"
|
||||
+ " \"span_term\" : {\n"
|
||||
+ " \"value\" : {\n"
|
||||
|
@ -92,4 +95,25 @@ public class FieldMaskingSpanQueryBuilderTests extends AbstractQueryTestCase<Fie
|
|||
assertEquals(json, 42.0, parsed.boost(), 0.00001);
|
||||
assertEquals(json, 0.23, parsed.innerQuery().boost(), 0.00001);
|
||||
}
|
||||
|
||||
public void testDeprecatedName() throws IOException {
|
||||
String json = "{\n"
|
||||
+ " \"field_masking_span\" : {\n"
|
||||
+ " \"query\" : {\n"
|
||||
+ " \"span_term\" : {\n"
|
||||
+ " \"value\" : {\n"
|
||||
+ " \"value\" : \"foo\"\n"
|
||||
+ " }\n"
|
||||
+ " }\n"
|
||||
+ " },\n"
|
||||
+ " \"field\" : \"mapped_geo_shape\",\n"
|
||||
+ " \"boost\" : 42.0,\n"
|
||||
+ " \"_name\" : \"KPI\"\n"
|
||||
+ " }\n"
|
||||
+ "}";
|
||||
FieldMaskingSpanQueryBuilder parsed = (FieldMaskingSpanQueryBuilder) parseQuery(json);
|
||||
assertWarnings(
|
||||
"Deprecated field [field_masking_span] used, expected [" + SPAN_FIELD_MASKING_FIELD.getPreferredName() + "] instead"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -337,7 +337,7 @@ public class SearchModuleTests extends OpenSearchTestCase {
|
|||
Set<String> registeredNonDeprecated = module.getNamedXContents()
|
||||
.stream()
|
||||
.filter(e -> e.categoryClass.equals(QueryBuilder.class))
|
||||
.filter(e -> e.name.getDeprecatedNames().length == 0)
|
||||
.filter(e -> e.name.getAllReplacedWith() == null)
|
||||
.map(e -> e.name.getPreferredName())
|
||||
.collect(toSet());
|
||||
Set<String> registeredAll = module.getNamedXContents()
|
||||
|
@ -422,7 +422,6 @@ public class SearchModuleTests extends OpenSearchTestCase {
|
|||
"constant_score",
|
||||
"dis_max",
|
||||
"exists",
|
||||
"field_masking_span",
|
||||
"function_score",
|
||||
"fuzzy",
|
||||
"geo_bounding_box",
|
||||
|
@ -448,6 +447,7 @@ public class SearchModuleTests extends OpenSearchTestCase {
|
|||
"script_score",
|
||||
"simple_query_string",
|
||||
"span_containing",
|
||||
"span_field_masking",
|
||||
"span_first",
|
||||
"span_gap",
|
||||
"span_multi",
|
||||
|
@ -465,7 +465,7 @@ public class SearchModuleTests extends OpenSearchTestCase {
|
|||
"distance_feature" };
|
||||
|
||||
// add here deprecated queries to make sure we log a deprecation warnings when they are used
|
||||
private static final String[] DEPRECATED_QUERIES = new String[] { "common" };
|
||||
private static final String[] DEPRECATED_QUERIES = new String[] { "common", "field_masking_span" };
|
||||
|
||||
/**
|
||||
* Dummy test {@link AggregationBuilder} used to test registering aggregation builders.
|
||||
|
|
Loading…
Reference in New Issue