|
38 | 38 | import org.apache.lucene.search.RegexpQuery; |
39 | 39 | import org.apache.lucene.util.automaton.Operations; |
40 | 40 | import org.apache.lucene.util.automaton.RegExp; |
| 41 | +import org.opensearch.common.logging.DeprecationLogger; |
41 | 42 | import org.opensearch.common.lucene.BytesRefs; |
42 | 43 | import org.opensearch.common.xcontent.LoggingDeprecationHandler; |
43 | 44 | import org.opensearch.core.ParseField; |
|
60 | 61 | * @opensearch.internal |
61 | 62 | */ |
62 | 63 | public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder> implements MultiTermQueryBuilder { |
| 64 | + |
| 65 | + private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RegexpQueryBuilder.class); |
| 66 | + |
63 | 67 | public static final String NAME = "regexp"; |
64 | 68 |
|
65 | 69 | public static final int DEFAULT_FLAGS_VALUE = RegexpFlag.ALL.value(); |
@@ -294,6 +298,18 @@ protected Query doToQuery(QueryShardContext context) throws QueryShardException, |
294 | 298 | + "] index level setting." |
295 | 299 | ); |
296 | 300 | } |
| 301 | + |
| 302 | + // Check if COMPLEMENT flag is being used |
| 303 | + // The COMPLEMENT flag maps to Lucene's DEPRECATED_COMPLEMENT which is marked for removal in Lucene 11 |
| 304 | + // This deprecation warning helps users migrate their queries before the feature is completely removed |
| 305 | + if ((syntaxFlagsValue & RegexpFlag.COMPLEMENT.value()) != 0) { |
| 306 | + deprecationLogger.deprecate( |
| 307 | + "regexp_complement_operator", |
| 308 | + "The complement operator (~) for arbitrary patterns in regexp queries is deprecated and will be removed in a future version. " |
| 309 | + + "Consider rewriting your query to use character class negation [^...] or other query types." |
| 310 | + ); |
| 311 | + } |
| 312 | + |
297 | 313 | MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(rewrite, null, LoggingDeprecationHandler.INSTANCE); |
298 | 314 |
|
299 | 315 | int matchFlagsValue = caseInsensitive ? RegExp.ASCII_CASE_INSENSITIVE : 0; |
|
0 commit comments