Skip to main content
Calculate the ngram similarity of the two strings. Info
  • Currently, the character encoding only supports ASCII encoding and does not support UTF-8 encoding.
  • The function ngram_search is case-sensitive. Another function ngram_search_case_insensitive is case-insensitive. Other than that, these two functions are the same.

Syntax

Parameters

  • haystack: required, the first string to compare. It must be a VARCHAR value. It can be a column name or a const value. If haystack is a column name, and an N-Gram bloom filter index is created for that column in the table, the index can accelerate the computation speed of the ngram_search function.
  • needle: required, the second string to compare. It must be a VARCHAR value. It can only be a const value. Tip
    • The length of the needle value can not be larger than 2^15. Otherwise an error will be thrown.
    • If the length of the haystack value is larger than 2^15, this function will return 0.
    • If the length of the haystack or needle value is smaller than gram_num, this function will return 0.
  • gram_num: required, used for specifying the number of grams. The recommended value is 4.

Return value

Returns a value describing how similar these two strings are. The range of returned value is between 0 and 1. The larger this value, the more similar the two strings are.

Examples