Union
Union( group, ... )
Description
The Union
function combines the results of one or more group
s, which
can be Arrays or
Set References.
Parameters
Argument | Type | Definition and Requirements |
---|---|---|
|
One or more arrays or set references which should have their results OR’d
together. All provided |
Returns
When group
is an array, an array of the items that appear in any
provided group
.
When group
is a set reference, a set reference of the items that appear in any
provided group
.
Examples
The following query combines the Set Reference (i.e. set reference)
returned by locating the search term "fire" in the index named
"spells_by_element" and the Set Reference returned by locating the
search term "water" in the Index named "spells_by_element". The
Paginate function materialized the
results of the Union
operation into an array of type Page.
client.query(
q.Paginate(
q.Union(
q.Match(q.Index('spells_by_element'), 'fire'),
q.Match(q.Index('spells_by_element'), 'water'),
)
)
)
.then((ret) => console.log(ret))
{ data:
[ Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))),
Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))),
Ref(id=181388642088911360, collection=Ref(id=spells, collection=Ref(id=collections))) ] }
The query below is similar to the example above, but it returns document events instead of the index tuples.
client.query(
q.Paginate(
q.Events(
q.Union(
q.Match(q.Index('spells_by_element'), 'fire'),
q.Match(q.Index('spells_by_element'), 'water'),
)
)
)
)
.then((ret) => console.log(ret))
{ data:
[ { ts: 1526677776479051,
action: 'add',
document:
Ref(id=181388642046968320, collection=Ref(id=spells, collection=Ref(id=collections))) },
{ ts: 1526677776479051,
action: 'add',
document:
Ref(id=181388642071085568, collection=Ref(id=spells, collection=Ref(id=collections))) },
{ ts: 1527095201753208,
action: 'add',
document:
Ref(id=181388642088911360, collection=Ref(id=spells, collection=Ref(id=collections))) } ] }
The following query demonstrates how various arrays are evaluated:
client.query([
q.Union(['A', 'B'], ['C', 'D']),
q.Union(['A', 'B'], ['B', 'C']),
q.Union(['A', 'B', 'C'], ['B', 'C'], ['B', 'C', 'D']),
q.Union(['A', 'B', 'C'], ['B', 'B'], ['B']),
])
.then((ret) => console.log(ret))
[ [ 'A', 'B', 'C', 'D' ],
[ 'A', 'B', 'C' ],
[ 'A', 'B', 'C', 'D' ],
[ 'A', 'B', 'B', 'C' ] ]
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!