Bug 37018: Clarify operators

This patch clarifies the list of operators both in the validate routine
and in the swagger descrption block where we document this feature for
the end user.

JD amended patch: tidy

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2024-07-10 09:39:33 +01:00 committed by Lucas Gass
parent b81b388db3
commit e7b3d05bc7
2 changed files with 17 additions and 2 deletions

View File

@ -664,7 +664,8 @@ sub _rewrite_related_metadata_query {
sub _validate_operator {
my ($operator) = @_;
my %allowed_operators =
map { $_ => 1 } qw(= != < > <= >= like -not_like -in -ident -bool -not_bool -or -like -not -and -regexp);
map { $_ => 1 }
qw(= != < > <= >= -in -ident -bool -not_bool -or like -like -not_like -between -not_between -not -and -regexp);
Koha::Exceptions::REST::Query::InvalidOperator->throw( operator => $operator )
unless exists $allowed_operators{$operator};
return;

View File

@ -1000,13 +1000,27 @@ info:
We can refine that with more complex matching clauses by nesting a the clause into the
object; `{ "fieldname": { "clause": "value" } }`.
Available matching clauses include `>`, `<`, `>=`, `<=`, `-like`, and `-not_like`.
Available matching clauses include `=`, `!=`, `<`, `>`, `<=`, `>=` and `-not`. We also support `-like`
and `-not_like` string comparisons with `%` used to denote wildcards, thus you can pass
`{ "fieldname": { "-like": "value%" } }` to do a 'starts with' string match for example.
We can filter on multiple fields by adding them to the JSON respresentation. Adding at `HASH`
level will result in an "AND" query, whilst combinding them in an `ARRAY` will result in an
"OR" query: `{ "field1": "value2", "field2": "value2" }` will filter the response to only those
results with both field1 containing value2 AND field2 containing value2 for example.
There is a collection of special operators also available to you, including:
* `-in` - Expects an array of values to perform an OR match against
* `-not_in` - Expects an array of values to perform a NOR match against
* `-between` - Expects two values which the value of the field is expected to fall between
* `-not_between` - Expects two values which the value of the field is expected to fall outside of
* `-ident` - Expects a second field name to match the two field values against
* `-regexp` - Expects a perl compatible regular expression for which the value should match
Logic and nesting is also supported and you may use `-and` and `-or` to change the logic of an ARRAY
or HASH as described above.
Additionally, if you are requesting related data be embedded into the response one can query
on the related data using dot notation in the field names.