Search using numerical values
Numeric search
Search indexes can also be used for non-textual values such as the integers values of cal_goal
:
schema.vertexLabel('person').
searchIndex().
ifNotExists().
by('person_id').
by('badge').
by('cal_goal').
by('country').
by('gender').
by('macro_goal').
by('name').
create()
This example illustrates that only one search index can exist for each vertex or edge label and includes seven properties that are indexed.
With this search index, a numeric query to find all persons who have a calorie goal greater than 1200 calories is:
g.V().has('person', 'cal_goal', gt(1200)).values('name', 'cal_goal')
results in: Five people have calorie goals of greater than 1200 calories:
==>Sharon SMITH
==>1600
==>Betsy JONES
==>1700
==>John DOE
==>1750
==>John Smith
==>1800
==>Jane DOE
==>1500
To sort the previous search, add additional methods order().by('cal_goal', incr)
to sort in increasing order by calorie goals, and fold()
to create a more readable result:
g.V().has('person', 'cal_goal', gt(1200)).
order().
by('cal_goal', incr).
values('cal_goal', 'name').
fold()
results in:
==>[1500, Jane DOE, 1600, Sharon SMITH, 1700, Betsy JONES, 1750, John DOE, 1800, John SMITH]