Skip to content

Commit

Permalink
Add docs for new normalize predicate expression.
Browse files Browse the repository at this point in the history
  • Loading branch information
gem-neo4j committed Jan 3, 2024
1 parent a6629e4 commit 0cf84ca
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
51 changes: 51 additions & 0 deletions modules/ROOT/pages/clauses/where.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,57 @@ The `name` and `age` for `Peter` are are returned because his name contains "ete
|===


[[match-string-is-normalized]]
=== Checking if a string is normalized `IS NORMALIZED`

The `IS NORMALIZED` operator is used to check whether the given `STRING` is in the `NFC` Unicode normalization form:

.Query
[source, cypher]
----
RETURN "the \u212B char" IS NORMALIZED AS normalized
----

The given string contains a non-normalized Unicode character: `\u212B`, therefore `false` is returned.
To normalize the string, it is possible to use the xref:functions/string.adoc#functions-normalize[normalize()] function.

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
|===
| normalized
| false
2+|Rows: 1
|===

==== Using `IS NORMALIZED` with a specified normalization type
It is also possible to define which Unicode normalization type is used, with the default being `NFC`.

The possible normalization types are:

* `NFC`
* `NFD`
* `NFKC`
* `NFKD`

.Query
[source, cypher]
----
WITH "the \u00E4 char" as myString
RETURN myString IS NFC NORMALIZED AS nfcNormalized,
myString IS NFD NORMALIZED AS nfdNormalized
----

The given string contains the Unicode character: `\u00E4`, which is considered normalized in `NFC` form, but not in `NFD` form.

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
|===
| nfcNormalized | nfdNormalized
| true | false
2+|Rows: 2
|===


[[match-string-negation]]
=== String matching negation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ RETURN normalize("string", NFC)
| Introduction of a xref::functions/string.adoc#functions-normalize[normalize()] function.
Normalize a `STRING` according to the specified normalization form, which can be of type `NFC`, `NFD`, `NFKC` or `NFKD`.

a|
label:functionality[]
label:new[]

[source, cypher, role=noheader]
----
IS [NOT] [NFC \| NFD \| NFKC \| NFKD] NORMALIZED
----

[source, cypher, role=noheader]
----
RETURN "string" IS NORMALIZED
----

| Introduction of a xref::clauses/where.adoc#match-string-is-normalized[IS NORMALIZED] predicate expression.
Check if a `STRING` is normalized according to the specified normalization form, which can be of type `NFC`, `NFD`, `NFKC` or `NFKD`.

|===

[[cypher-deprecations-additions-removals-5.15]]
Expand Down
36 changes: 35 additions & 1 deletion modules/ROOT/pages/syntax/operators.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This page contains an overview of the available Cypher operators.
| xref::syntax/operators.adoc#query-operators-comparison[Comparison operators] | `+=+`, `+<>+`, `+<+`, `+>+`, `+<=+`, `+>=+`, `IS NULL`, `IS NOT NULL`
| xref::syntax/operators.adoc#query-operators-comparison[String-specific comparison operators] | `STARTS WITH`, `ENDS WITH`, `CONTAINS`, `=~` (regex matching)
| xref::syntax/operators.adoc#query-operators-boolean[Boolean operators] | `AND`, `OR`, `XOR`, `NOT`
| xref::syntax/operators.adoc#query-operators-string[String operators] | `+` (string concatenation)
| xref::syntax/operators.adoc#query-operators-string[String operators] | `+` (string concatenation), `IS NORMALIZED`
| xref::syntax/operators.adoc#query-operators-temporal[Temporal operators] | `+` and `-` for operations between durations and temporal instants/durations, `*` and `/` for operations between durations and numbers
| xref::syntax/operators.adoc#query-operators-map[Map operators] | `.` for static value access by key, `[]` for dynamic value access by key
| xref::syntax/operators.adoc#query-operators-list[List operators] | `+` (list concatenation), `IN` to check existence of an element in a list, `[]` for accessing element(s) dynamically
Expand Down Expand Up @@ -543,6 +543,7 @@ RETURN number
The string operators comprise:

* concatenating strings: `+`
* checking if a string is normalized: `IS NORMALIZED`


[[syntax-concatenating-two-strings]]
Expand All @@ -562,6 +563,39 @@ RETURN 'neo' + '4j' AS result
1+d|Rows: 1
|===

[[syntax-check-string-is-normalized]]
=== Check if a string is normalized

.Query
[source, cypher]
----
RETURN 'neo' IS NORMALIZED AS result
----

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
|===
| +result+
| +true+
1+d|Rows: 1
|===

.Query
[source, cypher]
----
RETURN 'The char \u00E4' IS NFD NORMALIZED AS result
----

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
|===
| +result+
| +false+
1+d|Rows: 1
|===




[[query-operators-temporal]]
== Temporal operators
Expand Down

0 comments on commit 0cf84ca

Please sign in to comment.