Skip to content

Commit

Permalink
Spotless
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 5, 2024
1 parent 67425be commit 79ae3ef
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ protected BytesRef indexedValueForSearch(Object value) {
}

@Override
public Query termsQuery(List<?> values, RewriteOverride rewriteOverride, QueryShardContext context) {
public Query termsQuery(List<?> values, RewriteOverride rewriteOverride, QueryShardContext context) {
failIfNotIndexedAndNoDocValues();
if (rewriteOverride == null) {
rewriteOverride = RewriteOverride.DEFAULT;
Expand Down Expand Up @@ -461,17 +461,15 @@ public Query prefixQuery(
Query indexQuery = super.prefixQuery(value, method, caseInsensitive, context);
Query dvQuery = super.prefixQuery(value, MultiTermQuery.DOC_VALUES_REWRITE, caseInsensitive, context);
query = new IndexOrDocValuesQuery(indexQuery, dvQuery);
}
else if (hasDocValues()) {
} else if (hasDocValues()) {
if (caseInsensitive) {
return AutomatonQueries.caseInsensitivePrefixQuery(
(new Term(name(), indexedValueForSearch(value))),
MultiTermQuery.DOC_VALUES_REWRITE
(new Term(name(), indexedValueForSearch(value))),
MultiTermQuery.DOC_VALUES_REWRITE
);
}
query = new PrefixQuery(new Term(name(), indexedValueForSearch(value)), MultiTermQuery.DOC_VALUES_REWRITE);
}
else{
} else {
query = super.prefixQuery(value, method, caseInsensitive, context);
}
break;
Expand All @@ -482,12 +480,11 @@ else if (hasDocValues()) {
case DOC_VALUES_ONLY:
failIfNoDocValues();
if (caseInsensitive) {
query = AutomatonQueries.caseInsensitivePrefixQuery(
(new Term(name(), indexedValueForSearch(value))),
MultiTermQuery.DOC_VALUES_REWRITE
query = AutomatonQueries.caseInsensitivePrefixQuery(
(new Term(name(), indexedValueForSearch(value))),
MultiTermQuery.DOC_VALUES_REWRITE
);
}
else {
} else {
query = new PrefixQuery(new Term(name(), indexedValueForSearch(value)), MultiTermQuery.DOC_VALUES_REWRITE);
}
break;
Expand Down Expand Up @@ -516,32 +513,30 @@ public Query regexpQuery(
rewriteOverride = RewriteOverride.DEFAULT;
}
Query query = null;
switch(rewriteOverride) {
switch (rewriteOverride) {
case DEFAULT:
if (isSearchable() && hasDocValues()) {
Query indexQuery = super.regexpQuery(value, syntaxFlags, matchFlags, maxDeterminizedStates, method, context);
Query dvQuery = super.regexpQuery(
value,
syntaxFlags,
matchFlags,
maxDeterminizedStates,
MultiTermQuery.DOC_VALUES_REWRITE,
context
value,
syntaxFlags,
matchFlags,
maxDeterminizedStates,
MultiTermQuery.DOC_VALUES_REWRITE,
context
);
query = new IndexOrDocValuesQuery(indexQuery, dvQuery);
}
else if (hasDocValues()) {
query = new RegexpQuery(
new Term(name(), indexedValueForSearch(value)),
syntaxFlags,
matchFlags,
RegexpQuery.DEFAULT_PROVIDER,
maxDeterminizedStates,
MultiTermQuery.DOC_VALUES_REWRITE
query = new IndexOrDocValuesQuery(indexQuery, dvQuery);
} else if (hasDocValues()) {
query = new RegexpQuery(
new Term(name(), indexedValueForSearch(value)),
syntaxFlags,
matchFlags,
RegexpQuery.DEFAULT_PROVIDER,
maxDeterminizedStates,
MultiTermQuery.DOC_VALUES_REWRITE
);
}
else {
query = super.regexpQuery(value, syntaxFlags, matchFlags, maxDeterminizedStates, method, context);
} else {
query = super.regexpQuery(value, syntaxFlags, matchFlags, maxDeterminizedStates, method, context);
}
break;
case INDEX_ONLY:
Expand All @@ -551,20 +546,27 @@ else if (hasDocValues()) {
case DOC_VALUES_ONLY:
failIfNoDocValues();
query = new RegexpQuery(
new Term(name(), indexedValueForSearch(value)),
syntaxFlags,
matchFlags,
RegexpQuery.DEFAULT_PROVIDER,
maxDeterminizedStates,
MultiTermQuery.DOC_VALUES_REWRITE
new Term(name(), indexedValueForSearch(value)),
syntaxFlags,
matchFlags,
RegexpQuery.DEFAULT_PROVIDER,
maxDeterminizedStates,
MultiTermQuery.DOC_VALUES_REWRITE
);
break;
}
return query;
return query;
}

@Override
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, RewriteOverride rewriteOverride, QueryShardContext context) {
public Query rangeQuery(
Object lowerTerm,
Object upperTerm,
boolean includeLower,
boolean includeUpper,
RewriteOverride rewriteOverride,
QueryShardContext context
) {
if (context.allowExpensiveQueries() == false) {
throw new OpenSearchException(
"[range] queries on [text] or [keyword] fields cannot be executed when '"
Expand All @@ -581,55 +583,53 @@ public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower
case DEFAULT:
if (isSearchable() && hasDocValues()) {
Query indexQuery = new TermRangeQuery(
name(),
lowerTerm == null ? null : indexedValueForSearch(lowerTerm),
upperTerm == null ? null : indexedValueForSearch(upperTerm),
includeLower,
includeUpper
name(),
lowerTerm == null ? null : indexedValueForSearch(lowerTerm),
upperTerm == null ? null : indexedValueForSearch(upperTerm),
includeLower,
includeUpper
);
Query dvQuery = new TermRangeQuery(
name(),
lowerTerm == null ? null : indexedValueForSearch(lowerTerm),
upperTerm == null ? null : indexedValueForSearch(upperTerm),
includeLower,
includeUpper,
MultiTermQuery.DOC_VALUES_REWRITE
name(),
lowerTerm == null ? null : indexedValueForSearch(lowerTerm),
upperTerm == null ? null : indexedValueForSearch(upperTerm),
includeLower,
includeUpper,
MultiTermQuery.DOC_VALUES_REWRITE
);
query = new IndexOrDocValuesQuery(indexQuery, dvQuery);
}
else if (hasDocValues()) {
} else if (hasDocValues()) {
query = new TermRangeQuery(
name(),
lowerTerm == null ? null : indexedValueForSearch(lowerTerm),
upperTerm == null ? null : indexedValueForSearch(upperTerm),
includeLower,
includeUpper,
MultiTermQuery.DOC_VALUES_REWRITE
name(),
lowerTerm == null ? null : indexedValueForSearch(lowerTerm),
upperTerm == null ? null : indexedValueForSearch(upperTerm),
includeLower,
includeUpper,
MultiTermQuery.DOC_VALUES_REWRITE
);
}
else {
} else {
query = super.rangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, context);
}
break;
case INDEX_ONLY:
failIfNotIndexed();
query = new TermRangeQuery(
name(),
lowerTerm == null ? null : indexedValueForSearch(lowerTerm),
upperTerm == null ? null : indexedValueForSearch(upperTerm),
includeLower,
includeUpper
name(),
lowerTerm == null ? null : indexedValueForSearch(lowerTerm),
upperTerm == null ? null : indexedValueForSearch(upperTerm),
includeLower,
includeUpper
);
break;
case DOC_VALUES_ONLY:
failIfNoDocValues();
query = new TermRangeQuery(
name(),
lowerTerm == null ? null : indexedValueForSearch(lowerTerm),
upperTerm == null ? null : indexedValueForSearch(upperTerm),
includeLower,
includeUpper,
MultiTermQuery.DOC_VALUES_REWRITE
name(),
lowerTerm == null ? null : indexedValueForSearch(lowerTerm),
upperTerm == null ? null : indexedValueForSearch(upperTerm),
includeLower,
includeUpper,
MultiTermQuery.DOC_VALUES_REWRITE
);
break;
}
Expand Down Expand Up @@ -671,8 +671,7 @@ public Query fuzzyQuery(
context
);
query = new IndexOrDocValuesQuery(indexQuery, dvQuery);
}
else if (hasDocValues()) {
} else if (hasDocValues()) {
query = new FuzzyQuery(
new Term(name(), indexedValueForSearch(value)),
fuzziness.asDistance(BytesRefs.toString(value)),
Expand All @@ -681,8 +680,7 @@ else if (hasDocValues()) {
transpositions,
MultiTermQuery.DOC_VALUES_REWRITE
);
}
else {
} else {
query = super.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, method, context);
}
break;
Expand All @@ -702,7 +700,7 @@ else if (hasDocValues()) {
);
break;
}
return query;
return query;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,30 +295,30 @@ public Query fuzzyQuery(
}

public Query fuzzyQuery(
Object value,
Fuzziness fuzziness,
int prefixLength,
int maxExpansions,
boolean transpositions,
@Nullable MultiTermQuery.RewriteMethod method,
@Nullable RewriteOverride rewriteOverride,
QueryShardContext context
Object value,
Fuzziness fuzziness,
int prefixLength,
int maxExpansions,
boolean transpositions,
@Nullable MultiTermQuery.RewriteMethod method,
@Nullable RewriteOverride rewriteOverride,
QueryShardContext context
) {
throw new IllegalArgumentException(
"Can only use fuzzy queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]"
"Can only use fuzzy queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]"
);
}

public Query prefixQuery(
String value,
@Nullable MultiTermQuery.RewriteMethod method,
@Nullable RewriteOverride rewriteOverride,
boolean caseInsensitve,
QueryShardContext context
String value,
@Nullable MultiTermQuery.RewriteMethod method,
@Nullable RewriteOverride rewriteOverride,
boolean caseInsensitve,
QueryShardContext context
) {
throw new QueryShardException(
context,
"Can only use prefix queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]"
context,
"Can only use prefix queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]"
);
}

Expand Down Expand Up @@ -356,16 +356,17 @@ public Query wildcardQuery(
"Can only use wildcard queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]"
);
}

public Query wildcardQuery(
String value,
@Nullable MultiTermQuery.RewriteMethod method,
@Nullable RewriteOverride rewriteOverride,
boolean caseInsensitve,
QueryShardContext context
String value,
@Nullable MultiTermQuery.RewriteMethod method,
@Nullable RewriteOverride rewriteOverride,
boolean caseInsensitve,
QueryShardContext context
) {
throw new QueryShardException(
context,
"Can only use wildcard queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]"
context,
"Can only use wildcard queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]"
);
}

Expand All @@ -392,17 +393,17 @@ public Query regexpQuery(
}

public Query regexpQuery(
String value,
int syntaxFlags,
int matchFlags,
int maxDeterminizedStates,
@Nullable MultiTermQuery.RewriteMethod method,
@Nullable RewriteOverride rewriteOverride,
QueryShardContext context
String value,
int syntaxFlags,
int matchFlags,
int maxDeterminizedStates,
@Nullable MultiTermQuery.RewriteMethod method,
@Nullable RewriteOverride rewriteOverride,
QueryShardContext context
) {
throw new QueryShardException(
context,
"Can only use regexp queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]"
context,
"Can only use regexp queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]"
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ protected Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLo
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] does not support range queries");
}

protected Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper,RewriteOverride rewriteOverride, QueryShardContext context) {
protected Query rangeQuery(
Object lowerTerm,
Object upperTerm,
boolean includeLower,
boolean includeUpper,
RewriteOverride rewriteOverride,
QueryShardContext context
) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] does not support range queries");
}

Expand Down
Loading

0 comments on commit 79ae3ef

Please sign in to comment.