Search using token methods on full text
token()
In a traversal query, use a token search to find list the names of all recipes that have the word Saute
in the instructions.
The method token()
is used with a supplied word.
g.V().has('recipe','instructions', token('Saute')).values('name')
results in:
==>Oysters Rockefeller
==>Beef Bourguignon
==>Wild Mushroom Stroganoff
Why does this search find these three recipes? Because the instructions for each meet the search requirements:
tokenPrefix()
In a traversal query, use a token prefix search to list the names of all recipes that have a word that includes a prefix of Sea
in the instructions.
The method tokenPrefix()
is used with a supplied prefix (a set of alphanumeric characters).
g.V().hasLabel('recipe').has('instructions', tokenPrefix('Sea')).values('name','instructions')
results in:
==>Oysters Rockefeller
==>Saute the shallots, celery, herbs, and seasonings in 3 tablespoons of the butter for 3 minutes. Add the watercress and let it wilt.
==>Roast Pork Loin
==>The day before, separate the meat from the ribs, stopping about 1 inch before the end of the bones. Season the pork liberally inside and out with salt and pepper and refrigerate overnight.
Two recipes are returned, one with the word Season in the instructions, and one with the word seasonings in the instructions.
Case is insensitive in tokenPrefix()
indexing.
tokenRegex()
In a traversal query, use a token regular expression (regex) search to find all recipes that have a word that includes the regular expression specified.
The regex, .sea*in.
, looks for the letters sea preceded by any number of other characters and followed by any number of other characters until the letters in are found and also followed by any number of other characters in the instructions and list the recipe names.
The method tokenRegex()
is used with a supplied regex.
include::example$food/TRAVERSALS/search_tokenRegex.gremlin[]
results in:
==>Oysters Rockefeller
==>Saute the shallots, celery, herbs, and seasonings in 3 tablespoons of the butter for 3 minutes. Add the watercress and let it wilt.
Note that in this query, only the Oysters Rockefeller
recipe is returned because the word Season in the Roast Pork Loin recipe does not meet the requirements for the regular expression.