Levenshtein Distance in Zoho Deluge (Because Why Not?)

Levenshtein Distance in Zoho Deluge (Because Why Not?)

Ever wanted to run a Levenshtein Distance algorithm inside Zoho Deluge? No? Me neither, but I did it anyway.

I built a fully functional fuzzy matching system inside Zoho, brute-forcing a dynamic programming solution using Maps and recursive list generation.

  • Does it scale? Not really.
  • Does it work? Absolutely.
  • Did I need to do this? Not at all, but it was fun.

I don’t even use this anymore because I found a better way around fuzzy matching for my needs, but hey, if you ever need a low volume Levenshtein calculator inside Zoho, now you have one. 🤷‍♂️


How It Works

The function computes Levenshtein Distance, a metric for fuzzy string similarity, by calculating the number of insertions, deletions, and substitutions needed to convert one string into another.

This method is commonly used in spell-checking, DNA sequencing, and fuzzy search algorithms—so obviously, I decided to implement it inside Zoho, because why not?

🔹 The Challenge: Zoho doesn’t support 2D arrays natively.
🔹 The Solution: I brute-forced it using Map-of-Maps as a manual matrix.
🔹 Bonus: I even used recursion to generate number sequences (which is completely unnecessary but kinda cool).

Code & Example Usage

Main Function: standalone.levenshteinDistance

📌 Input: {"s": "kitten", "t": "sitting"}
📌 Output: "3"

Code:

string standalone.levenshteinDistance(Map args)
{
// Retrieve input strings.
s = args.get("s");
t = args.get("t");
m = s.length();
n = t.length();
// If one string is empty, return the length of the other.
if(m == 0)
{
return n.toString();
}
if(n == 0)
{
return m.toString();
}
//info "Length of s: " + m.toString() + ", Length of t: " + n.toString();
// ------------------------------
// Get index lists via the helper function.
// The helper function standalone.UtilitygetListOfLength returns a comma-separated string.
// For example, if (m+1) is 5, it returns "0,1,2,3,4".
// ------------------------------
indices_m_str = standalone.UtilitygetListOfLength({"myLength":m + 1});
indices_n_str = standalone.UtilitygetListOfLength({"myLength":n + 1});
//info "indices_m_str: " + indices_m_str;
//info "indices_n_str: " + indices_n_str;
// Convert these comma-separated strings into lists of long values.
indices_m = list();
numList_m = indices_m_str.toList(",");
for each  numStr in numList_m
{
if(numStr.trim() != "")
{
indices_m.add(numStr.trim().toLong());
}
}
indices_n = list();
numList_n = indices_n_str.toList(",");
for each  numStr in numList_n
{
if(numStr.trim() != "")
{
indices_n.add(numStr.trim().toLong());
}
}
//info "indices_m list: " + indices_m.toString();
//info "indices_n list: " + indices_n.toString();
// ------------------------------
// Initialize matrix as a map-of-maps.
// Each row is a map keyed by the column index.
// ------------------------------
matrix = Map();
for each  i in indices_m
{
rowMap = Map();
for each  j in indices_n
{
rowMap.put(j,0);
}
matrix.put(i,rowMap);
}
// Set up the first column: matrix[i][0] = i.
for each  i in indices_m
{
rowMap = matrix.get(i);
rowMap.put(0,i);
}
// Set up the first row: matrix[0][j] = j.
firstRow = matrix.get(0);
for each  j in indices_n
{
firstRow.put(j,j);
}
// ------------------------------
// Compute Levenshtein distances.
// ------------------------------
for each  i in indices_m
{
if(i == 0)
{
continue;
}
for each  j in indices_n
{
if(j == 0)
{
continue;
}
// Determine cost: 0 if characters are the same, otherwise 1.
if(s.subString(i - 1,i) == t.subString(j - 1,j))
{
cost = 0;
}
else
{
cost = 1;
}
deletion = matrix.get(i - 1).get(j) + 1;
insertion = matrix.get(i).get(j - 1) + 1;
substitution = matrix.get(i - 1).get(j - 1) + cost;
minValue = deletion;
if(insertion < minValue)
{
minValue = insertion;
}
if(substitution < minValue)
{
minValue = substitution;
}
rowMap = matrix.get(i);
rowMap.put(j,minValue);
}
}
result = matrix.get(m).get(n);
//info "Levenshtein distance: " + result.toString();
return result.toString();
}

Recursive Helper Function: standalone.UtilitygetListOfLength

📌 Input: {"myLength": 6}
📌 Output: "0,1,2,3,4,5"

Code:

string standalone.UtilitygetListOfLength(Map args)
{
myLength = args.get("myLength");
//info "Input myLength: " + myLength;
if(myLength == null || myLength <= 0)
{
//info "Base case reached (myLength <= 0). Returning empty string.";
return "";
}
else
{
// Recursively get the string for (myLength - 1)
prevStr = standalone.UtilitygetListOfLength({"myLength":myLength - 1});
//info "Previous string returned for myLength " + (myLength - 1).toString() + ": " + prevStr;
if(prevStr.equals(""))
{
result = "0";
}
else
{
result = prevStr + "," + (myLength - 1).toString();
}
//info "Returning result for myLength " + myLength.toString() + ": " + result;
return result;
}
}

This helper function is completely unnecessary, but I made it anyway. Instead of just looping, it recursively builds a CSV string of numbers—which is both inefficient and hilarious. 😆

Why Did I Do This?

Because it wasn't supposed to work—but it does.

  • Zoho doesn’t support Levenshtein distance? I built it anyway.
  • Zoho doesn’t have fuzzy matching? Now it does.
  • Zoho doesn’t support 2D arrays? I brute-forced a matrix using Maps.
  • Does this scale for massive data? Nope, but it’s perfect for low-volume cases.

Thoughts? Ideas? Have you ever done something in Zoho just because you wanted to see if it was possible? Let me know. 😆


TL;DR:

📌 I brute-forced Levenshtein Distance into Zoho
📌 Zoho wasn’t built for this, but I made it work anyway
📌 Does it scale? No. Does it work? Yes.
📌 Do I use it? Nope. Was it fun? Absolutely.

Let me know what you think! 🚀


    Access your files securely from anywhere







                            Zoho Developer Community





                                                  Use cases

                                                  Make the most of Zoho Desk with the use cases.

                                                   
                                                    

                                                  eBooks

                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho Desk.

                                                   
                                                    

                                                  Videos

                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho Desk.

                                                   
                                                    

                                                  Webinar

                                                  Sign up for our webinars and learn the Zoho Desk basics, from customization to automation and more

                                                   
                                                    
                                                  • Desk Community Learning Series


                                                  • Meetups


                                                  • Ask the Experts


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner




                                                            • Sticky Posts

                                                            • Kaizen #197: Frequently Asked Questions on GraphQL APIs

                                                              🎊 Nearing 200th Kaizen Post – We want to hear from you! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                            • Kaizen #198: Using Client Script for Custom Validation in Blueprint

                                                              Nearing 200th Kaizen Post – 1 More to the Big Two-Oh-Oh! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                            • Celebrating 200 posts of Kaizen! Share your ideas for the milestone post

                                                              Hello Developers, We launched the Kaizen series in 2019 to share helpful content to support your Zoho CRM development journey. Staying true to its spirit—Kaizen Series: Continuous Improvement for Developer Experience—we've shared everything from FAQs
                                                            • Kaizen #193: Creating different fields in Zoho CRM through API

                                                              🎊 Nearing 200th Kaizen Post – We want to hear from you! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                            • Client Script | Update - Introducing Commands in Client Script!

                                                              Have you ever wished you could trigger Client Script from contexts other than just the supported pages and events? Have you ever wanted to leverage the advantage of Client Script at your finger tip? Discover the power of Client Script - Commands! Commands


                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner







                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources


                                                                                              Zoho Writer Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ








                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方