diff --git a/README.md b/README.md index f0587c91..1e7a304a 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,9 @@ External dependencies can not be covered by the annotations. Documentation about | `@indexable` | marks the type as indexable if the core schema is used to put data into a database/key-value store | | | `@integer` | number field is interpreted as integer | | | `@keyword` | string field is interpreted as keyword | | -| `@sortable` | field is sortable if the core schema is used to put data into a database/key-value store | sort method to be used: `ducet`, `price`, `distance` | +| `@sortable` | field is sortable if the core schema is used to put data into a database/key-value store. Fields are always sortable through generic sort, even without annotation. | sort method to be used: `ducet`, `price`, `distance` | | `@text` | string field is interpreted as text | | +| `@date` | string field is interpreted as a date field | | | `@validatable` | marks the type as validatable if the core schema is used to put data into a database/key-value store | | | `@filterable` | non-object/nested field is filterable if the core schema is used to put data into a database/key-value store | | | `@inheritTags` | inherit all tags from another field | `[SCThingType]::[field]` | diff --git a/src/general/time.ts b/src/general/time.ts index 24f70c59..4e72fe82 100644 --- a/src/general/time.ts +++ b/src/general/time.ts @@ -18,6 +18,8 @@ * * @pattern ^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$ * @see https://gist.github.com/philipashlock/8830168 + * + * @date */ export type SCISO8601Date = string; /* tslint:enable */ diff --git a/src/protocol/search/filter.ts b/src/protocol/search/filter.ts index 82beb884..b5808d13 100644 --- a/src/protocol/search/filter.ts +++ b/src/protocol/search/filter.ts @@ -28,7 +28,9 @@ export type SCSearchFilterType = 'availability' | 'boolean' | 'distance' - | 'value'; + | 'value' + | 'date range' + | 'numeric range'; /** * Structure of a filter instruction diff --git a/src/protocol/search/filters/range.ts b/src/protocol/search/filters/range.ts new file mode 100644 index 00000000..cee3360c --- /dev/null +++ b/src/protocol/search/filters/range.ts @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2020 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +import {SCThingsField} from '../../../meta'; +import {SCSearchAbstractFilter, SCSearchAbstractFilterArguments} from '../filter'; + +/** + * A date range filter + * + * Filter for documents with a date field that satisfies the given constraints + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-range-query.html#_date_format_in_range_queries + */ +export interface SCSearchDateRangeFilter extends SCSearchAbstractFilter { + /** + * @see SCSearchAbstractFilter.type + */ + type: 'date range'; +} + +/** + * A distance filter + * + * Filter for documents with a numeric field that satisfies the given constraints + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-range-query.html#query-dsl-range-query + */ +export interface SCSearchNumericRangeFilter extends SCSearchAbstractFilter { + /** + * @see SCSearchAbstractFilter.type + */ + type: 'numeric range'; +} + +/** + * Additional arguments for date range filters + * + * Filter uses a plain string to allow for date math expressions + * @see https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/date-math-expressions.html + */ +export interface SCDateRangeFilterArguments extends SCRangeFilterArguments { + /** + * Optional date format specifier + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-range-query.html#_date_format_in_range_queries + */ + format?: string; + + /** + * Optional timezone specifier + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-range-query.html#_time_zone_in_range_queries + */ + timeZone?: string; +} + +/** + * Additional arguments for numeric range filters + */ +export type SCNumericRangeFilterArguments = SCRangeFilterArguments; + +/** + * Additional arguments for range filters + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-range-query.html#query-dsl-range-query + */ +export interface SCRangeFilterArguments extends SCSearchAbstractFilterArguments { + /** + * Bounds of the range + */ + bounds: Bounds; + + /** + * Field where the filter will be applied + */ + field: SCThingsField; +} + +export interface Bounds { + /** + * The lower bound + */ + lowerBound?: Bound; + + /** + * The upper bound + */ + upperBound?: Bound; +} + +export interface Bound { + /** + * Limit of the bound + */ + limit: T; + + /** + * Bound mode + */ + mode: 'inclusive' | 'exclusive'; +} diff --git a/src/protocol/search/sort.ts b/src/protocol/search/sort.ts index fadbfe76..2fecdd02 100644 --- a/src/protocol/search/sort.ts +++ b/src/protocol/search/sort.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 StApps + * Copyright (C) 2019, 2020 StApps * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, version 3. @@ -16,6 +16,7 @@ import {SCMap} from '../../general/map'; import {SCThingsField} from '../../meta'; import {SCDistanceSort} from './sorts/distance'; import {SCDucetSort} from './sorts/ducet'; +import {SCGenericSort} from './sorts/generic'; import {SCPriceSort} from './sorts/price'; /** @@ -51,9 +52,9 @@ export interface SCSearchAbstractSortArguments extends SCMap { /** * Type of a sort instruction */ -export type SCSearchSortType = 'distance' | 'price' | 'ducet'; +export type SCSearchSortType = 'distance' | 'price' | 'ducet' | 'generic'; /** * A sort instruction */ -export type SCSearchSort = SCDistanceSort | SCPriceSort | SCDucetSort; +export type SCSearchSort = SCDistanceSort | SCPriceSort | SCDucetSort | SCGenericSort; diff --git a/src/protocol/search/sorts/generic.ts b/src/protocol/search/sorts/generic.ts new file mode 100644 index 00000000..d04c5737 --- /dev/null +++ b/src/protocol/search/sorts/generic.ts @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2020 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +import {SCSearchAbstractSort, SCSearchAbstractSortArguments} from '../sort'; + +/** + * Sort instruction for generic sort such as date + */ +export interface SCGenericSort extends SCSearchAbstractSort { + /** + * @see SCSearchAbstractSort.type + */ + type: 'generic'; +}