Skip to content

Commit

Permalink
Fixing mapper tests
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
  • Loading branch information
harshavamsi committed Dec 19, 2023
1 parent e950ee1 commit ebeea24
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -457,22 +457,31 @@ public Query rangeQuery(
@Nullable DateMathParser forcedDateParser,
QueryShardContext context
) {
failIfNotIndexed();
failIfNotIndexedAndNoDocValues();
if (relation == ShapeRelation.DISJOINT) {
throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] does not support DISJOINT ranges");
}
DateMathParser parser = forcedDateParser == null ? dateMathParser : forcedDateParser;
return dateRangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, timeZone, parser, context, resolution, (l, u) -> {
if(isSearchable() && hasDocValues()){
Query query = LongPoint.newRangeQuery(name(), l, u);
Query dvQuery = SortedNumericDocValuesField.newSlowRangeQuery(name(), l, u);
query = new IndexOrDocValuesQuery(query, dvQuery);

if (context.indexSortedOnField(name())) {
query = new IndexSortSortedNumericDocValuesRangeQuery(name(), l, u, query);
}
return query;
}
if (hasDocValues()) {
Query dvQuery = SortedNumericDocValuesField.newSlowRangeQuery(name(), l, u);
query = new IndexOrDocValuesQuery(query, dvQuery);
Query query = SortedNumericDocValuesField.newSlowRangeQuery(name(), l, u);

if (context.indexSortedOnField(name())) {
query = new IndexSortSortedNumericDocValuesRangeQuery(name(), l, u, query);
}
return query;
}
return query;
return LongPoint.newRangeQuery(name(), l, u);
});
}

Expand Down Expand Up @@ -543,6 +552,7 @@ public static long parseToLong(

@Override
public Query distanceFeatureQuery(Object origin, String pivot, float boost, QueryShardContext context) {
failIfNotIndexedAndNoDocValues();
long originLong = parseToLong(origin, true, null, null, context::nowInMillis);
TimeValue pivotTime = TimeValue.parseTimeValue(pivot, "distance_feature.pivot");
return resolution.distanceFeatureQuery(name(), boost, originLong, pivotTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,21 @@ public void testTermQuery() {

public void testTermsQuery() {
MappedFieldType ft = new BooleanFieldMapper.BooleanFieldType("field");
<<<<<<< Updated upstream
BooleanFieldMapper.BooleanFieldType booleanFieldType = new BooleanFieldMapper.BooleanFieldType("field");
=======
>>>>>>> Stashed changes
List<BytesRef> terms = new ArrayList<>();
terms.add(new BytesRef("true"));
terms.add(new BytesRef("false"));
assertEquals(new IndexOrDocValuesQuery(
<<<<<<< Updated upstream
new TermInSetQuery("field", terms.stream().map(booleanFieldType::indexedValueForSearch).toArray(BytesRef[]::new)),
new TermInSetQuery(MultiTermQuery.DOC_VALUES_REWRITE, "field", terms.stream().map(booleanFieldType::indexedValueForSearch).toArray(BytesRef[]::new))
=======
new TermInSetQuery("field", terms),
new TermInSetQuery(MultiTermQuery.DOC_VALUES_REWRITE, "field", terms)
>>>>>>> Stashed changes
), ft.termsQuery(terms, null));

MappedFieldType unsearchable = new BooleanFieldMapper.BooleanFieldType("field", false, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ public void testTermQuery() {
"field",
false,
false,
true,
false,
DateFieldMapper.getDefaultDateTimeFormatter(),
Resolution.MILLISECONDS,
null,
Collections.emptyMap()
);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> unsearchable.termQuery(date, context));
assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
assertEquals("Cannot search on field [field] since it is both not indexed, and does not have doc_values enabled.", e.getMessage());
}

public void testRangeQuery() throws IOException {
Expand Down Expand Up @@ -279,7 +279,7 @@ public void testRangeQuery() throws IOException {
"field",
false,
false,
true,
false,
DateFieldMapper.getDefaultDateTimeFormatter(),
Resolution.MILLISECONDS,
null,
Expand All @@ -289,7 +289,7 @@ public void testRangeQuery() throws IOException {
IllegalArgumentException.class,
() -> unsearchable.rangeQuery(date1, date2, true, true, null, null, null, context)
);
assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
assertEquals("Cannot search on field [field] since it is both not indexed, and does not have doc_values enabled.", e.getMessage());
}

public void testRangeQueryWithIndexSort() {
Expand Down

0 comments on commit ebeea24

Please sign in to comment.