Skip to content

Commit

Permalink
extract conditions
Browse files Browse the repository at this point in the history
Signed-off-by: mikhail-khludnev <[email protected]>
  • Loading branch information
mkhludnev authored and mikhail-khludnev committed Nov 14, 2024
1 parent 6eb18ba commit de335b9
Showing 1 changed file with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ public Query termQuery(Object value, @Nullable QueryShardContext context) {
true
);
}
return indexOrDvQuery(pointQuery, dvQuery);
}

private Query indexOrDvQuery(Query pointQuery, Query dvQuery) {
if (isSearchable() && hasDocValues()) {
return new IndexOrDocValuesQuery(pointQuery, dvQuery);
} else {
Expand Down Expand Up @@ -299,39 +302,25 @@ public Query termsQuery(List<?> values, QueryShardContext context) {
if (isSearchable()) {
pointQuery = InetAddressPoint.newSetQuery(name(), addresses);
}
if (isSearchable() && hasDocValues()) {
return new IndexOrDocValuesQuery(pointQuery, dvQuery);
} else {
if (isSearchable()) {
return pointQuery;
} else {
return dvQuery;
}
}
return indexOrDvQuery(pointQuery, dvQuery);
}

@Override
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, QueryShardContext context) {
failIfNotIndexedAndNoDocValues();
return rangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, (lower, upper) -> {
Query query = InetAddressPoint.newRangeQuery(name(), lower, upper);
PointRangeQuery pointQuery = (PointRangeQuery) InetAddressPoint.newRangeQuery(name(), lower, upper);
Query dvQuery = null;
if (hasDocValues()) {
dvQuery = SortedSetDocValuesField.newSlowRangeQuery(
((PointRangeQuery) query).getField(),
new BytesRef(((PointRangeQuery) query).getLowerPoint()),
new BytesRef(((PointRangeQuery) query).getUpperPoint()),
pointQuery.getField(),
new BytesRef(pointQuery.getLowerPoint()),
new BytesRef(pointQuery.getUpperPoint()),
true,
true
);
}
if (isSearchable() && hasDocValues()) {
return new IndexOrDocValuesQuery(query, dvQuery);
}
if (hasDocValues()) {
return dvQuery;
}
return query;
return indexOrDvQuery(pointQuery, dvQuery);
});
}

Expand Down

0 comments on commit de335b9

Please sign in to comment.