Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.13.3</version>
<version>8.19.10</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ public enum CQLFields implements CQLFieldsInterface {
(order) -> new SortOptions.Builder().script(s -> s
.type(ScriptSortType.Number)
.nested(NestedSortValue.of(p -> p.path(StacSummeries.Temporal.sortField)))
.script(script -> script.inline(line -> line
.script(script -> script
.lang("painless")
.source("if (doc['" + StacSummeries.TemporalEnd.searchField + "'].size() == 0) {" +
" return Long.MAX_VALUE; " +
" return Long.MAX_VALUE; " +
" } " +
" else {" +
" return doc['" + StacSummeries.TemporalEnd.searchField + "'].stream()" +
" .mapToLong(f -> f.toEpochMilli())" +
" .max()" +
" .getAsLong()" +
" }"
))
)
).order(order)
)
),
Expand Down Expand Up @@ -312,22 +312,23 @@ public enum CQLFields implements CQLFieldsInterface {

@Override
public Query getPropertyEqualToQuery(String literal) {
if(getOverridePropertyEqualsToQuery() == null) {
if (getOverridePropertyEqualsToQuery() == null) {
return MatchPhraseQuery.of(builder -> builder
.field(this.searchField)
.query(literal)
)._toQuery();
}
else {
} else {
return getOverridePropertyEqualsToQuery().apply(literal);
}
}

@Override
public Query getPropertyGreaterThanOrEqualsToQuery(String literal) {
return RangeQuery.of(builder -> builder
.field(this.searchField)
.gte(JsonData.of(literal))
return RangeQuery.of(builder -> builder
// set as untyped because the property type is uncertain
.untyped(u -> u
.field(this.searchField)
.gte(JsonData.of(literal)))
)._toQuery();
}

Expand All @@ -354,7 +355,7 @@ public Query getBoundingBoxQuery(TopLeftBottomRightGeoBounds tlbr) {
@Override
public Query getIsNullQuery() {
Query fieldExist = ExistsQuery.of(f -> f
.field(this.searchField))._toQuery();
.field(this.searchField))._toQuery();

return BoolQuery.of(b -> b
.mustNot(fieldExist))._toQuery();
Expand All @@ -368,8 +369,10 @@ public Query getLikeQuery(String literal) {
.flags("ALL")
.value(literal))._toQuery();
}

/**
* Given param, find any of those is not a valid CQLCollectionsField
*
* @param args -
* @return Invalid enum
*/
Expand All @@ -379,8 +382,7 @@ public static List<String> findInvalidEnum(List<String> args) {
try {
CQLFields.valueOf(str);
return false;
}
catch (IllegalArgumentException e) {
} catch (IllegalArgumentException e) {
return true;
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFields;
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFieldsInterface;
import au.org.aodn.ogcapi.server.core.model.enumeration.StacSummeries;
import co.elastic.clients.json.JsonData;
import org.geotools.filter.AttributeExpressionImpl;
import org.geotools.filter.LiteralExpressionImpl;
import org.geotools.filter.text.cql2.CQLException;
Expand Down Expand Up @@ -42,9 +41,10 @@ public AfterImpl(Expression expression1, Expression expression2, Class<T> enumTy
.path(StacSummeries.Temporal.searchField)
.query(q1 -> q1
.range(r -> r
.field(StacSummeries.TemporalStart.searchField)
.gte(JsonData.of(dateFormatter.format(literal.getValue())))
.format("strict_date_optional_time")
.date(d -> d
.field(StacSummeries.TemporalStart.searchField)
.gte(dateFormatter.format(literal.getValue()))
.format("strict_date_optional_time"))
)
)
)._toQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import au.org.aodn.ogcapi.server.core.model.enumeration.CQLFieldsInterface;
import au.org.aodn.ogcapi.server.core.model.enumeration.StacSummeries;
import co.elastic.clients.elasticsearch._types.query_dsl.NestedQuery;
import co.elastic.clients.json.JsonData;
import org.geotools.filter.AttributeExpressionImpl;
import org.geotools.filter.LiteralExpressionImpl;
import org.geotools.filter.text.cql2.CQLException;
Expand Down Expand Up @@ -42,9 +41,10 @@ public BeforeImpl(Expression expression1, Expression expression2, Class<T> enumT
.path(StacSummeries.Temporal.searchField)
.query(q1 -> q1
.range(r -> r
.field(StacSummeries.TemporalEnd.searchField)
.lte(JsonData.of(dateFormatter.format(literal.getValue())))
.format("strict_date_optional_time")
.date(d -> d
.field(StacSummeries.TemporalEnd.searchField)
.lte(dateFormatter.format(literal.getValue()))
.format("strict_date_optional_time"))
)
)
)._toQuery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import co.elastic.clients.elasticsearch._types.query_dsl.NestedQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import co.elastic.clients.elasticsearch._types.query_dsl.RangeQuery;
import co.elastic.clients.json.JsonData;
import org.geotools.filter.AttributeExpressionImpl;
import org.geotools.filter.LiteralExpressionImpl;
import org.geotools.filter.text.cql2.CQLException;
Expand Down Expand Up @@ -69,20 +68,22 @@ public DuringImpl(Expression expression1, Expression expression2, Class<T> enumT
&& cqlFields == CQLFields.temporal) {

Query gte = RangeQuery.of(r -> r
.date(d -> d
.field(StacSummeries.TemporalStart.searchField)
.gte(JsonData.of(dateFormatter.format(period.getBeginning().getPosition().getDate())))
.format("strict_date_optional_time"))._toQuery();
.gte(dateFormatter.format(period.getBeginning().getPosition().getDate()))
.format("strict_date_optional_time")))._toQuery();

Query lte = RangeQuery.of(r -> r
.date(d -> d
.field(StacSummeries.TemporalEnd.searchField)
.lte(JsonData.of(dateFormatter.format(period.getEnding().getPosition().getDate())))
.format("strict_date_optional_time"))._toQuery();
.lte(dateFormatter.format(period.getEnding().getPosition().getDate()))
.format("strict_date_optional_time")))._toQuery();


this.query = NestedQuery.of(n -> n
.path(StacSummeries.Temporal.searchField)
.query(BoolQuery.of(q -> q
.must(gte, lte))._toQuery()
.query(BoolQuery.of(q -> q
.must(gte, lte))._toQuery()
)
)._toQuery();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected SearchResult<StacCollectionModel> searchCollectionBy(final List<Query>
builder.query(q -> q.scriptScore(ss -> ss
// to get the original _score from ELasticsearch
.query(bq -> bq.bool(createBoolQueryForProperties(queries, should, filters)))
.script(s -> s.inline(i -> i
.script(s -> s
.lang("painless")
.source(
// Step 1: Retrieve internal quality score from summaries.score field
Expand All @@ -197,7 +197,6 @@ protected SearchResult<StacCollectionModel> searchCollectionBy(final List<Query>
// Final score = Elasticsearch relevance * normalized quality
"return _score * multiplier;"
)
)
))
);
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ogcapi:
docker:
elasticVersion: "8.13.3"
elasticVersion: "8.19.10"

elasticsearch:
index:
Expand Down
Loading