Search Index with a given array

Hello.

I’m pretty new to Fauna and I got stuck by trying to do the follow:

I need to return a list of phone numbers and status from a given list of phone numbers.
Basically search in the index the phones numbers that match,

This would be the query for a single phone number

Map(
  Paginate(
    Match(Index("unique_phones"), "351910000001")
  ),
  Lambda(
    "person",
    Get(Var("person"))
  )
)

and this is what I’m looking for

Map(
  Paginate(
    Match(Index("unique_phones"), ["18008675309", "351910000001"])
  ),
  Lambda(
    "person",
    Get(Var("person"))
  )
)

How can I do this?

Thanks

Match does not take a list of alternatives. It takes a single value, or an array of values, that must match the number of elements defined in the index’s terms field.

Match returns a set, so you can use a set function to combine multiple Match calls into another set:

Map(
  Paginate(
    Union(
      Match(Index("unique_phones"), "18008675309"),
      Match(Index("unique_phones"), "351910000001"),
    )
  ),
  Lambda(
    "person",
    Get(Var("person"))
  )
)

See the Union examples here: Union | Fauna Documentation

1 Like

Thank you, Ewan.

What I’m looking for would be the query for this mutation

mutation {
  getPhoneStatuses(phones:["18008675309", "351910000001"]){
    phone
    isOnline
  }
}

What I was trying was this, this was my approach:

Lambda(["phones"],
  Map(
    Paginate(
      Match(Index("unique_phones"), Map(["phones"], Lambda("phone", Var("phone"))))
    ),
    Lambda(
      "person",
      Get(Var("person"))
    )
  )
)

But I still can’t figure out how to proceed.

Much appreciated for your quickly response. Thanks

It was more easy than expected, but took my a while.

Finally, I have got it.

Map(["18008675309", "351910000001"], 
         Lambda("phone", Paginate(
                Match(Index("unique_phones"), Var("phone"))
                           )
           )
)

Thank to everyone

2 Likes