diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c3d7d04..e45711b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- `FilterOperation`s for regular expression matching (case sensitive, insensitive and "not") +- Expand `FilterCriterion.Builder` by regexp operations + ## [12.2.1](https://github.com/dbmdz/digitalcollections-model/releases/tag/12.2.1) - 2023-09-15 ### Fixed diff --git a/dc-model/src/main/java/de/digitalcollections/model/list/filtering/FilterCriterion.java b/dc-model/src/main/java/de/digitalcollections/model/list/filtering/FilterCriterion.java index 9810bb6c..afb13f2a 100644 --- a/dc-model/src/main/java/de/digitalcollections/model/list/filtering/FilterCriterion.java +++ b/dc-model/src/main/java/de/digitalcollections/model/list/filtering/FilterCriterion.java @@ -310,6 +310,54 @@ public Builder startsWith(Object value) { return this; } + /** + * Case sensitive regular expression matching + * + * @param value operand + * @return this builder + */ + public Builder regex(String value) { + this.filterOperation = FilterOperation.REGEX; + this.value = value; + return this; + } + + /** + * Case insensitive regular expression matching + * + * @param value operand + * @return this builder + */ + public Builder iregex(String value) { + this.filterOperation = FilterOperation.IREGEX; + this.value = value; + return this; + } + + /** + * Case sensitive regular expression not matching + * + * @param value operand + * @return this builder + */ + public Builder notRegex(String value) { + this.filterOperation = FilterOperation.NOT_REGEX; + this.value = value; + return this; + } + + /** + * Case insensitive regular expression not matching + * + * @param value operand + * @return this builder + */ + public Builder notIRegex(String value) { + this.filterOperation = FilterOperation.NOT_IREGEX; + this.value = value; + return this; + } + public Builder withExpression(String expression) { this.expression = expression; return this; diff --git a/dc-model/src/main/java/de/digitalcollections/model/list/filtering/FilterOperation.java b/dc-model/src/main/java/de/digitalcollections/model/list/filtering/FilterOperation.java index 3c114130..d3d86823 100644 --- a/dc-model/src/main/java/de/digitalcollections/model/list/filtering/FilterOperation.java +++ b/dc-model/src/main/java/de/digitalcollections/model/list/filtering/FilterOperation.java @@ -5,27 +5,31 @@ * * * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * *
Mapping operation abbreviation to filter operation
Symbol Operation Example filter query param
eq equals city=eq:Munich
eq_notset equals or not set city=eq_notset:Munich
neq not equals country=neq:de
gt greater than amount=gt:10000
gt_notset greater than or not set presentationEnd=gt_notset:2020-10-06
gte greater than or equals amount=gte:10000
gte_notsetgreater than or equals or not setamount=gte_notset:10000
lt less than amount=lt:10000
lt_notset less than or not set amount=lt_notset:10000
lt_set less than and set amount=lt_set:10000
lte less than or equals to amount=lte:10000
lte_set less than or equals and set presentationStart=lte_set:2020-10-06
lte_notsetless than or equals or not set presentationStart=lte_notset:2020-10-06
in in country=in:uk,usa,au
nin not in country=nin:fr,de,nz
btn between (inclusive) joiningDate=btn:2018-01-01,2016-01-01
like like firstName=like:John
stw starts with firstName=stw:A
set value exists (not null) firstName=set:
notset value is not set (null) firstName=notset:
Symbol Operation Example filter query param (unescaped)
eq equals city:eq:Munich
eq_notset equals or not set city:eq_notset:Munich
neq not equals country:neq:de
gt greater than amount:gt:10000
gt_notset greater than or not set presentationEnd:gt_notset:2020-10-06
gte greater than or equals amount:gte:10000
gte_notsetgreater than or equals or not setamount:gte_notset:10000
lt less than amount:lt:10000
lt_notset less than or not set amount:lt_notset:10000
lt_set less than and set amount:lt_set:10000
lte less than or equals to amount:lte:10000
lte_set less than or equals and set presentationStart:lte_set:2020-10-06
lte_notsetless than or equals or not set presentationStart:lte_notset:2020-10-06
in in country:in:uk,usa,au
nin not in country:nin:fr,de,nz
btn between (inclusive) joiningDate:btn:2018-01-01,2016-01-01
like like firstName:like:John
stw starts with firstName:stw:A
set value exists (not null) firstName:set:
notset value is not set (null) firstName:notset:
regex regexp matching (case sensitive) firstName:regex:Joh?n.+
iregex regexp matching (case insensitive)firstName:iregex:Joh?n.+
nregex regexp not matching (case sensitive) firstName:nregex:Joh?n.+
niregex regexp not matching (case insensitive)firstName:niregex:Joh?n.+
* *

References: @@ -54,7 +58,11 @@ public enum FilterOperation { CONTAINS("like", OperandCount.SINGLEVALUE), NOT_SET("notset", OperandCount.NO_VALUE), SET("set", OperandCount.NO_VALUE), - STARTS_WITH("stw", OperandCount.SINGLEVALUE); + STARTS_WITH("stw", OperandCount.SINGLEVALUE), + REGEX("regex", OperandCount.SINGLEVALUE), + IREGEX("iregex", OperandCount.SINGLEVALUE), + NOT_REGEX("nregex", OperandCount.SINGLEVALUE), + NOT_IREGEX("niregex", OperandCount.SINGLEVALUE); public static FilterOperation fromValue(String value) { for (FilterOperation op : FilterOperation.values()) {