diff --git a/README.md b/README.md index 05b9f83d8..0c70c802c 100644 --- a/README.md +++ b/README.md @@ -366,7 +366,7 @@ if it is defined but doesn't match. | `statusId` | term | `statusId == "123"` | Matches instances with the `123` status | | `instanceFormatIds` | term | `instanceFormatIds == "123"` | Matches instances with the `123` format id | | `languages` | term | `languages == "eng"` | Matches instances that have `eng` language | -| `metadata.createdDate` | term | `metadata.createdDate > "2020-12-12"` | Matches instances that were created after `2020-12-12` | +| `metadata.createdDate` | term | `metadata.createdDate > "2021-03-01T00:00:00.000+00:00"` | Matches instances that were created after `2020-12-12` | | `metadata.updatedDate` | term | `metadata.updatedDate > "2020-12-12"` | Matches instances that were updated after `2020-12-12` | | `modeOfIssuanceId` | term | `modeOfIssuanceId=="123"` | Matches instances that have `123` mode of issuance | | `natureOfContentTermIds` | term | `natureOfContentTermIds=="123"` | Matches instances that have `123` nature of content | diff --git a/src/main/java/org/folio/search/cql/CqlTermQueryConverter.java b/src/main/java/org/folio/search/cql/CqlTermQueryConverter.java index 38e65b14c..6ba6ad0d3 100644 --- a/src/main/java/org/folio/search/cql/CqlTermQueryConverter.java +++ b/src/main/java/org/folio/search/cql/CqlTermQueryConverter.java @@ -3,10 +3,10 @@ import static java.util.Collections.unmodifiableMap; import static java.util.stream.Collectors.joining; import static org.apache.commons.lang3.StringUtils.lowerCase; -import static org.apache.commons.validator.GenericValidator.isDate; import static org.folio.search.utils.SearchUtils.ASTERISKS_SIGN; import static org.opensearch.index.query.QueryBuilders.matchAllQuery; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -34,7 +34,16 @@ public class CqlTermQueryConverter { public static final String WILDCARD_OPERATOR = "wildcard"; private static final String MATCH_ALL_CQL_QUERY = "cql.allRecords = 1"; private static final String KEYWORD_ALL_CQL_QUERY = "keyword = *"; - private static final String STRICT_DATE_PATTERN = "yyyy-MM-dd"; + + private static final List SUPPORTED_DATE_FORMATS = List.of( + DateTimeFormatter.ISO_DATE, + DateTimeFormatter.ISO_DATE_TIME, + DateTimeFormatter.ISO_LOCAL_DATE, + DateTimeFormatter.ISO_LOCAL_DATE_TIME, + DateTimeFormatter.ISO_OFFSET_DATE, + DateTimeFormatter.ISO_OFFSET_DATE_TIME, + DateTimeFormatter.ISO_INSTANT + ); private final SearchFieldProvider searchFieldProvider; private final Map termQueryBuilders; @@ -143,11 +152,23 @@ private static Map getTermQueryProvidersAsMap(List filteredSearchQueriesProvider() { arguments("(subjectHeadings==\"n\")", List.of(IDS[11], IDS[12])), arguments("(metadata.createdDate >= 2021-03-01) ", List.of(IDS[0], IDS[1], IDS[2], IDS[3])), + arguments("(metadata.createdDate >= 2021-03-01T00:00:00.000) ", List.of(IDS[0], IDS[1], IDS[2], IDS[3])), + arguments("(metadata.createdDate >= 2021-03-01T00:00:00.000Z) ", List.of(IDS[0], IDS[1], IDS[2], IDS[3])), + arguments("(metadata.createdDate >= 2021-03-01T00:00:00.000+00:00) ", List.of(IDS[0], IDS[1], IDS[2], IDS[3])), arguments("(metadata.createdDate > 2021-03-01) ", List.of(IDS[1], IDS[2], IDS[3])), arguments("(metadata.createdDate >= 2021-03-01 and metadata.createdDate < 2021-03-10) ", List.of(IDS[0], IDS[2])), @@ -158,8 +161,7 @@ private static Stream invalidDateSearchQueriesProvider() { arguments("metadata.createdDate", "2022-06-1"), arguments("metadata.createdDate", "2022-06-40"), arguments("metadata.updatedDate", "2022-15-01"), - arguments("metadata.updatedDate", "invalidDate"), - arguments("metadata.updatedDate", "2022-11-15T15:00:00.000") + arguments("metadata.updatedDate", "invalidDate") ); } diff --git a/src/test/java/org/folio/search/controller/SearchInstanceFilterIT.java b/src/test/java/org/folio/search/controller/SearchInstanceFilterIT.java index 9f9f791c8..749ff9988 100644 --- a/src/test/java/org/folio/search/controller/SearchInstanceFilterIT.java +++ b/src/test/java/org/folio/search/controller/SearchInstanceFilterIT.java @@ -316,8 +316,7 @@ private static Stream invalidDateSearchQueriesProvider() { arguments("holdings.metadata.createdDate", "2022-15-01"), arguments("holdings.metadata.updatedDate", "2022-06-40"), - arguments("item.metadata.updatedDate", "invalidDate"), - arguments("item.metadata.createdDate", "2022-06-15T15:00:00.000") + arguments("item.metadata.updatedDate", "invalidDate") ); }