You need to create an appropriate index for the field (or “column”) that you want to search:
CreateIndex({
name: "search_people_by_first",
source: Collection("People"),
terms: [
{ field: ["data", "first"] }
]
})
When you search an index, the matching entries are returned as a set. You can use set functions to get the union, difference, etc. In this case, we want to combine the set of results for each term that you want to search for, so we’lll use Union
:
Map(
Paginate(
Union(
Match(Index("search_people_by_first"), "Alan"),
Match(Index("search_people_by_first"), "Grace")
)
),
Lambda("X", Get(Var("X")))
)
The result would look like:
{
data: [
{
ref: Ref(Collection("People"), "293318393615876608"),
ts: 1615989068650000,
data: {
first: 'Alan',
last: 'Perlis',
age: 97,
degrees: [ 'BA', 'MA', 'PhD' ],
letter: 'A'
}
},
{
ref: Ref(Collection("People"), "293318393615877632"),
ts: 1615989068650000,
data: {
first: 'Alan',
last: 'Turing',
age: 107,
degrees: [ 'BA', 'MA', 'MS', 'PhD' ],
letter: 'B'
}
},
{
ref: Ref(Collection("People"), "293318393617973760"),
ts: 1615989068650000,
data: {
first: 'Grace',
last: 'Hopper',
age: 119,
degrees: [ 'BA', 'MA', 'PhD' ],
letter: 'C'
}
}
]
}
The data you see here is from our indexing tutorials: Index tutorials | Fauna Documentation