Skip to main content
Known Participant
Jan 13, 2022 3:10 PM UTC
Question

Fuzzy Search On Array

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
    Jan 13, 2022 3:58 PM UTC

    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
    Jan 13, 2022 10:22 PM UTC

    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)))
        )
      )
    )