apoc.text.hammingDistance

Details

Syntax

apoc.text.hammingDistance(text1, text2)

Description

Compares the two given STRING values using the Hamming distance algorithm.

Arguments

Name

Type

Description

text1

STRING

The first string to be compared against the second.

text2

STRING

The second string to be compared against the first.

Returns

INTEGER

Usage Examples

RETURN apoc.text.hammingDistance("Neo4j", "Neo4j") AS output;
Results
output

0

RETURN apoc.text.hammingDistance("Neo4j", "Neoj4") AS output;
Results
output

2

The provided strings must be the same length, otherwise this procedure will throw an exception, as shown in the example below:

RETURN apoc.text.hammingDistance("Neo4j Aura", "Neo4j Graph Database") AS output;
Results

Failed to invoke function apoc.text.hammingDistance: Caused by: java.lang.IllegalArgumentException: CharSequences must have the same length