Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regexp filter operations #500

Merged
merged 1 commit into from
Nov 8, 2023
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,31 @@
*
* <table border="1">
* <caption>Mapping operation abbreviation to filter operation</caption>
* <tr><th>Symbol </th><th>Operation </th><th>Example filter query param </th></tr>
* <tr><td>eq </td><td>equals </td><td>city=eq:Munich </td></tr>
* <tr><td>eq_notset </td><td>equals or not set </td><td>city=eq_notset:Munich </td></tr>
* <tr><td>neq </td><td>not equals </td><td>country=neq:de </td></tr>
* <tr><td>gt </td><td>greater than </td><td>amount=gt:10000 </td></tr>
* <tr><td>gt_notset </td><td>greater than or not set </td><td>presentationEnd=gt_notset:2020-10-06 </td></tr>
* <tr><td>gte </td><td>greater than or equals </td><td>amount=gte:10000 </td></tr>
* <tr><td>gte_notset</td><td>greater than or equals or not set</td><td>amount=gte_notset:10000 </td></tr>
* <tr><td>lt </td><td>less than </td><td>amount=lt:10000 </td></tr>
* <tr><td>lt_notset </td><td>less than or not set </td><td>amount=lt_notset:10000 </td></tr>
* <tr><td>lt_set </td><td>less than and set </td><td>amount=lt_set:10000 </td></tr>
* <tr><td>lte </td><td>less than or equals to </td><td>amount=lte:10000 </td></tr>
* <tr><td>lte_set </td><td>less than or equals and set </td><td>presentationStart=lte_set:2020-10-06 </td></tr>
* <tr><td>lte_notset</td><td>less than or equals or not set </td><td>presentationStart=lte_notset:2020-10-06</td></tr>
* <tr><td>in </td><td>in </td><td>country=in:uk,usa,au </td></tr>
* <tr><td>nin </td><td>not in </td><td>country=nin:fr,de,nz </td></tr>
* <tr><td>btn </td><td>between (inclusive) </td><td>joiningDate=btn:2018-01-01,2016-01-01 </td></tr>
* <tr><td>like </td><td>like </td><td>firstName=like:John </td></tr>
* <tr><td>stw </td><td>starts with </td><td>firstName=stw:A </td></tr>
* <tr><td>set </td><td>value exists (not null) </td><td>firstName=set: </td></tr>
* <tr><td>notset </td><td>value is not set (null) </td><td>firstName=notset: </td></tr>
* <tr><th>Symbol </th><th>Operation </th><th>Example filter query param (unescaped) </th></tr>
* <tr><td>eq </td><td>equals </td><td>city:eq:Munich </td></tr>
* <tr><td>eq_notset </td><td>equals or not set </td><td>city:eq_notset:Munich </td></tr>
* <tr><td>neq </td><td>not equals </td><td>country:neq:de </td></tr>
* <tr><td>gt </td><td>greater than </td><td>amount:gt:10000 </td></tr>
* <tr><td>gt_notset </td><td>greater than or not set </td><td>presentationEnd:gt_notset:2020-10-06 </td></tr>
* <tr><td>gte </td><td>greater than or equals </td><td>amount:gte:10000 </td></tr>
* <tr><td>gte_notset</td><td>greater than or equals or not set</td><td>amount:gte_notset:10000 </td></tr>
* <tr><td>lt </td><td>less than </td><td>amount:lt:10000 </td></tr>
* <tr><td>lt_notset </td><td>less than or not set </td><td>amount:lt_notset:10000 </td></tr>
* <tr><td>lt_set </td><td>less than and set </td><td>amount:lt_set:10000 </td></tr>
* <tr><td>lte </td><td>less than or equals to </td><td>amount:lte:10000 </td></tr>
* <tr><td>lte_set </td><td>less than or equals and set </td><td>presentationStart:lte_set:2020-10-06 </td></tr>
* <tr><td>lte_notset</td><td>less than or equals or not set </td><td>presentationStart:lte_notset:2020-10-06</td></tr>
* <tr><td>in </td><td>in </td><td>country:in:uk,usa,au </td></tr>
* <tr><td>nin </td><td>not in </td><td>country:nin:fr,de,nz </td></tr>
* <tr><td>btn </td><td>between (inclusive) </td><td>joiningDate:btn:2018-01-01,2016-01-01 </td></tr>
* <tr><td>like </td><td>like </td><td>firstName:like:John </td></tr>
* <tr><td>stw </td><td>starts with </td><td>firstName:stw:A </td></tr>
* <tr><td>set </td><td>value exists (not null) </td><td>firstName:set: </td></tr>
* <tr><td>notset </td><td>value is not set (null) </td><td>firstName:notset: </td></tr>
* <tr><td>regex </td><td>regexp matching (case sensitive) </td><td>firstName:regex:Joh?n.+ </td></tr>
* <tr><td>iregex </td><td>regexp matching (case insensitive)</td><td>firstName:iregex:Joh?n.+ </td></tr>
* <tr><td>nregex </td><td>regexp not matching (case sensitive) </td><td>firstName:nregex:Joh?n.+ </td></tr>
* <tr><td>niregex </td><td>regexp not matching (case insensitive)</td><td>firstName:niregex:Joh?n.+ </td></tr>
* </table>
*
* <p>References:
Expand Down Expand Up @@ -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()) {
Expand Down