Indexes
Solution
The Match
function is used to find matching entries in an index.
-
Indexes created without specifying the
terms
field return all indexedvalues
on the indexed collection:map[data:[[Alan Perlis {310014288737600000 0xc000180570 0xc000180570 <nil>}] [Alan Turing {310014288735502848 0xc000180720 0xc000180720 <nil>}] [Grace Hopper {310014288734454272 0xc0001808d0 0xc0001808d0 <nil>}] [Leslie Lamport {310014288732357120 0xc000180a80 0xc000180a80 <nil>}] [Marvin Minsky {310014288731308544 0xc000180c30 0xc000180c30 <nil>}] [Stephen Cook {310014288729211392 0xc000180de0 0xc000180de0 <nil>}] [Tim Cook {310014288729212416 0xc000180f90 0xc000180f90 <nil>}]]]
{ data: [ [ 'Alan', 'Perlis', Ref(Collection("People"), "310011992898273792") ], [ 'Alan', 'Turing', Ref(Collection("People"), "310011992901419520") ], [ 'Grace', 'Hopper', Ref(Collection("People"), "310011992897225216") ], [ 'Leslie', 'Lamport', Ref(Collection("People"), "310011992895129088") ], [ 'Marvin', 'Minsky', Ref(Collection("People"), "310011992895128064") ], [ 'Stephen', 'Cook', Ref(Collection("People"), "310011992891983360") ], [ 'Tim', 'Cook', Ref(Collection("People"), "310011992891982336") ] ] }
{'data': [['Alan', 'Perlis', Ref(id=310013802959603200, collection=Ref(id=People, collection=Ref(id=collections)))], ['Alan', 'Turing', Ref(id=310013802959602176, collection=Ref(id=People, collection=Ref(id=collections)))], ['Grace', 'Hopper', Ref(id=310013802957505024, collection=Ref(id=People, collection=Ref(id=collections)))], ['Leslie', 'Lamport', Ref(id=310013802956457472, collection=Ref(id=People, collection=Ref(id=collections)))], ['Marvin', 'Minsky', Ref(id=310013802956456448, collection=Ref(id=People, collection=Ref(id=collections)))], ['Stephen', 'Cook', Ref(id=310013802953310720, collection=Ref(id=People, collection=Ref(id=collections)))], ['Tim', 'Cook', Ref(id=310013802953311744, collection=Ref(id=People, collection=Ref(id=collections)))]]}
{ data: [ [ 'Alan', 'Perlis', Ref(Collection("People"), "309934841578653184") ], [ 'Alan', 'Turing', Ref(Collection("People"), "309934841578652160") ], [ 'Grace', 'Hopper', Ref(Collection("People"), "309934841576555008") ], [ 'Leslie', 'Lamport', Ref(Collection("People"), "309934841575507456") ], [ 'Marvin', 'Minsky', Ref(Collection("People"), "309934841575506432") ], [ 'Stephen', 'Cook', Ref(Collection("People"), "309934841572360704") ], [ 'Tim', 'Cook', Ref(Collection("People"), "309934841572361728") ] ] }
-
Results from index matches use a specific sorting precedence. The following example uses an index that sorts by
age
descending:map[data:[[119 Grace Hopper {310014288734454272 0xc0001099b0 0xc0001099b0 <nil>}] [107 Alan Turing {310014288735502848 0xc000109b60 0xc000109b60 <nil>}] [97 Alan Perlis {310014288737600000 0xc000109d10 0xc000109d10 <nil>}] [92 Marvin Minsky {310014288731308544 0xc000109ec0 0xc000109ec0 <nil>}] [81 Stephen Cook {310014288729211392 0xc00016e090 0xc00016e090 <nil>}] [80 Leslie Lamport {310014288732357120 0xc00016e240 0xc00016e240 <nil>}] [59 Tim Cook {310014288729212416 0xc00016e3f0 0xc00016e3f0 <nil>}]]]
{ data: [ [ 119, 'Grace', 'Hopper', Ref(Collection("People"), "310012262298419712") ], [ 107, 'Alan', 'Turing', Ref(Collection("People"), "310012262299469312") ], [ 97, 'Alan', 'Perlis', Ref(Collection("People"), "310012262299468288") ], [ 92, 'Marvin', 'Minsky', Ref(Collection("People"), "310012262295273984") ], [ 81, 'Stephen', 'Cook', Ref(Collection("People"), "310012262292129280") ], [ 80, 'Leslie', 'Lamport', Ref(Collection("People"), "310012262296322560") ], [ 59, 'Tim', 'Cook', Ref(Collection("People"), "310012262292128256") ] ] }
{'data': [[119, 'Grace', 'Hopper', Ref(id=310013488491660800, collection=Ref(id=People, collection=Ref(id=collections)))], [107, 'Alan', 'Turing', Ref(id=310013488494805504, collection=Ref(id=People, collection=Ref(id=collections)))], [97, 'Alan', 'Perlis', Ref(id=310013488495854080, collection=Ref(id=People, collection=Ref(id=collections)))], [92, 'Marvin', 'Minsky', Ref(id=310013488490611200, collection=Ref(id=People, collection=Ref(id=collections)))], [81, 'Stephen', 'Cook', Ref(id=310013488487466496, collection=Ref(id=People, collection=Ref(id=collections)))], [80, 'Leslie', 'Lamport', Ref(id=310013488491659776, collection=Ref(id=People, collection=Ref(id=collections)))], [59, 'Tim', 'Cook', Ref(id=310013488487465472, collection=Ref(id=People, collection=Ref(id=collections)))]]}
{ data: [ [ 119, 'Grace', 'Hopper', Ref(Collection("People"), "309995028361511424") ], [ 107, 'Alan', 'Turing', Ref(Collection("People"), "309995028357317120") ], [ 97, 'Alan', 'Perlis', Ref(Collection("People"), "309995028360462848") ], [ 92, 'Marvin', 'Minsky', Ref(Collection("People"), "309995028352074240") ], [ 81, 'Stephen', 'Cook', Ref(Collection("People"), "309995028351026688") ], [ 80, 'Leslie', 'Lamport', Ref(Collection("People"), "309995028356268544") ], [ 59, 'Tim', 'Cook', Ref(Collection("People"), "309995028351025664") ] ] }
-
For indexes where the
terms
field was defined, entries are located using the indexed terms:map[data:[[Alan Perlis {310014511710994944 0xc000184570 0xc000184570 <nil>}] [Alan Turing {310014511706800640 0xc000184720 0xc000184720 <nil>}]]]
{ data: [ [ 'Alan', 'Perlis', Ref(Collection("People"), "310012851960939008") ], [ 'Alan', 'Turing', Ref(Collection("People"), "310012851957793280") ] ] }
{'data': [['Alan', 'Perlis', Ref(id=310014237971841536, collection=Ref(id=People, collection=Ref(id=collections)))], ['Alan', 'Turing', Ref(id=310014237970793984, collection=Ref(id=People, collection=Ref(id=collections)))]]}
{ data: [ [ 'Alan', 'Perlis', Ref(Collection("People"), "309935512027660800") ], [ 'Alan', 'Turing', Ref(Collection("People"), "309935512023466496") ] ] }
-
For indexes where a binding was defined in the
terms
field,Match
works as if the binding was a normal field:map[data:[[Alan Turing {310014847404212736 0xc000092570 0xc000092570 <nil>}]]]
{ data: [ [ 'Alan Turing', Ref(Collection("People"), "310011445570961920") ] ] }
{'data': [['Alan Turing', Ref(id=310013344420463104, collection=Ref(id=People, collection=Ref(id=collections)))]]}
{ data: [ [ 'Alan Turing', Ref(Collection("People"), "313624171151098368") ] ] }
-
For indexes where there are multiple
terms
fields defined, theMatch
values must be expressed as an array:map[data:[[Alan Turing {310014511706800640 0xc000092570 0xc000092570 <nil>}]]]
{ data: [ [ 'Alan', 'Turing', Ref(Collection("People"), "310005407260082688") ] ] }
{'data': [['Alan', 'Turing', Ref(id=310013947139850752, collection=Ref(id=People, collection=Ref(id=collections)))]]}
{ data: [ [ 'Alan', 'Turing', Ref(Collection("People"), "309995228827222528") ] ] }
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!