Skip to main content
January 13, 2022
Question

Fuzzy Search On Array

  • January 13, 2022
  • 2 replies
  • 0 views

Hi,

I am trying to do a fuzzy search on a CDT field which is a string array. The array is { "One"; "Five"; "Seven"; "Ten" }.

Input:

{"Five","Seven"}

Output:

Array of all those CDT items where we have {"Five"} and {"Seven"} and ("Five","Seven")

Please help me with it.

    2 replies

    mikes0011
    Brainy
    January 13, 2022

    Did you try whereContains()?  It will give you the indexes in the larger array that contain any members of the smaller array.

    The Expression Guru
    peter.lewis
    Employee
    January 13, 2022

    Are you looking across a list of lists or across a single list? wherecontains() should work for a single list but you might need something a bit more fancy if you want to compare across multiple lists, like this:

    a!localVariables(
      local!data: {
        a!map(id: 1, items: {"One","Two","Three"}),
        a!map(id: 2, items: {"One","Two",}),
        a!map(id: 3, items: {"Two","Four"}),
        a!map(id: 4, items: {"Three"})
      },
      where(
        a!forEach(
          items: local!data,
          expression: sum(wherecontains({"One", "Three"},touniformstring(fv!item.items)))
        )
      )
    )