apoc.text.hammingDistance

Function APOC Core

apoc.text.hammingDistance(text1, text2) - compare the given strings with the Hamming distance algorithm.

Signature

apoc.text.hammingDistance(text1 :: STRING?, text2 :: STRING?) :: (INTEGER?)

Input parameters

Name Type Default

text1

STRING?

null

text2

STRING?

null

Usage Examples

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

0

RETURN apoc.text.hammingDistance("Neo4j", "Neoj4") AS output;
Table 2. 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;
Table 3. Results

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