Skip to content

Commit

Permalink
Adding yaml tests
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
  • Loading branch information
harshavamsi committed Aug 9, 2024
1 parent 6dc2b0b commit 6b0921a
Show file tree
Hide file tree
Showing 8 changed files with 568 additions and 12 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package org.opensearch.index.mapper;

import org.apache.lucene.search.Query;
import org.opensearch.common.Nullable;
import org.opensearch.common.geo.ShapeRelation;
import org.opensearch.common.time.DateMathParser;
import org.opensearch.index.query.QueryShardContext;
Expand Down Expand Up @@ -78,6 +79,27 @@ public final Query rangeQuery(
return rangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, context);
}

@Override
public final Query rangeQuery(
Object lowerTerm,
Object upperTerm,
boolean includeLower,
boolean includeUpper,
ShapeRelation relation,
ZoneId timeZone,
DateMathParser parser,
@Nullable RewriteOverride rewriteOverride,
QueryShardContext context
) {
if (relation == ShapeRelation.DISJOINT) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] does not support DISJOINT ranges");
}
// We do not fail on non-null time zones and date parsers
// The reasoning is that on query parsers, you might want to set a time zone or format for date fields
// but then the API has no way to know which fields are dates and which fields are not dates
return rangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, rewriteOverride, context);
}

/**
* Same as {@link #rangeQuery(Object, Object, boolean, boolean, ShapeRelation, ZoneId, DateMathParser, QueryShardContext)}
* but without the trouble of relations or date-specific options.
Expand All @@ -94,7 +116,7 @@ protected Query rangeQuery(
RewriteOverride rewriteOverride,
QueryShardContext context
) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] does not support range queries");
return rangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, context);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.automaton.Operations;
import org.opensearch.OpenSearchException;
import org.opensearch.common.Nullable;
import org.opensearch.common.lucene.BytesRefs;
import org.opensearch.common.lucene.search.AutomatonQueries;
import org.opensearch.common.unit.Fuzziness;
Expand Down Expand Up @@ -110,7 +111,7 @@ public Query fuzzyQuery(
int prefixLength,
int maxExpansions,
boolean transpositions,
MultiTermQuery.RewriteMethod method,
@Nullable MultiTermQuery.RewriteMethod method,
QueryShardContext context
) {
if (!context.allowExpensiveQueries()) {
Expand All @@ -132,6 +133,20 @@ public Query fuzzyQuery(
);
}

@Override
public Query fuzzyQuery(
Object value,
Fuzziness fuzziness,
int prefixLength,
int maxExpansions,
boolean transpositions,
@Nullable MultiTermQuery.RewriteMethod method,
@Nullable RewriteOverride rewriteOverride,
QueryShardContext context
) {
return fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, method, context);
}

@Override
public Query prefixQuery(String value, MultiTermQuery.RewriteMethod method, boolean caseInsensitive, QueryShardContext context) {
if (context.allowExpensiveQueries() == false) {
Expand Down Expand Up @@ -188,6 +203,17 @@ public Query wildcardQuery(String value, MultiTermQuery.RewriteMethod method, bo
return wildcardQuery(value, method, caseInsensitive, false, context);
}

@Override
public Query wildcardQuery(
String value,
MultiTermQuery.RewriteMethod method,
@Nullable RewriteOverride rewriteOverride,
boolean caseInsensitive,
QueryShardContext context
) {
return wildcardQuery(value, method, caseInsensitive, context);
}

/** always normalizes the wildcard pattern to lowercase */
@Override
public Query normalizedWildcardQuery(String value, MultiTermQuery.RewriteMethod method, QueryShardContext context) {
Expand Down Expand Up @@ -279,4 +305,16 @@ public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower
includeUpper
);
}

@Override
public Query rangeQuery(
Object lowerTerm,
Object upperTerm,
boolean includeLower,
boolean includeUpper,
@Nullable RewriteOverride rewriteOverride,
QueryShardContext context
) {
return rangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,14 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
throw new IllegalStateException("Rewrite first");
}
String rewrite = this.rewrite;
Query query = fieldType.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, null, context);
RewriteOverride rewriteOverride = QueryParsers.parseRewriteOverride(
rewrite_override,
RewriteOverride.DEFAULT,
LoggingDeprecationHandler.INSTANCE
);
Query query = fieldType.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, null, rewriteOverride, context);
if (query instanceof MultiTermQuery) {
MultiTermQuery.RewriteMethod rewriteMethod = QueryParsers.parseRewriteMethod(rewrite, null, LoggingDeprecationHandler.INSTANCE);
RewriteOverride rewriteOverride = QueryParsers.parseRewriteOverride(
rewrite_override,
RewriteOverride.DEFAULT,
LoggingDeprecationHandler.INSTANCE
);
query = fieldType.fuzzyQuery(
value,
fuzziness,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,12 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
if (fieldType == null) {
throw new IllegalStateException("Rewrite first");
}
return fieldType.prefixQuery(value, method, caseInsensitive, context);
RewriteOverride rewriteOverride = QueryParsers.parseRewriteOverride(
rewrite_override,
RewriteOverride.DEFAULT,
LoggingDeprecationHandler.INSTANCE
);
return fieldType.prefixQuery(value, method, rewriteOverride, caseInsensitive, context);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,12 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
}

MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(rewrite, null, LoggingDeprecationHandler.INSTANCE);
return fieldType.wildcardQuery(value, method, caseInsensitive, context);
RewriteOverride rewriteOverride = QueryParsers.parseRewriteOverride(
rewrite_override,
RewriteOverride.DEFAULT,
LoggingDeprecationHandler.INSTANCE
);
return fieldType.wildcardQuery(value, method, rewriteOverride, caseInsensitive, context);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public void testFromJson() throws IOException {
+ " \"include_lower\" : true,\n"
+ " \"include_upper\" : true,\n"
+ " \"time_zone\" : \"+01:00\",\n"
+ " \"boost\" : 1.0\n"
+ " \"boost\" : 1.0,\n"
+ " \"rewrite_override\" : \"index_only\"\n"
+ " }\n"
+ " }\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void testFromJson() throws IOException {
+ " \"flags_value\" : 7,\n"
+ " \"case_insensitive\" : true,\n"
+ " \"max_determinized_states\" : 20000,\n"
+ " \"boost\" : 1.0\n"
+ " \"boost\" : 1.0,\n"
+ " \"rewrite_override\" : \"index_only\"\n"
+ " }\n"
+ " }\n"
Expand Down

0 comments on commit 6b0921a

Please sign in to comment.