[[search-predicates]]
Search Predicates
-----------------

This page lists all of the comparison predicates that Titan supports in global graph search and local traversals.

Compare Predicate
~~~~~~~~~~~~~~~~~

The `Compare` enum specifies the following self-explanatory comparison predicates used for index query construction and used in the examples above:

* EQUAL
* NOT_EQUAL
* GREATER_THAN
* GREATER_THAN_EQUAL
* LESS_THAN
* LESS_THAN_EQUAL

Text Predicate
~~~~~~~~~~~~~~

The `Text` enum specifies the <<text-search,search operator>> used to query for matching text or string values.  We differentiate between two types of predicates:

* Text search predicates which match against the individual words inside a text string after it has been tokenized. These predicates are not case sensitive.
** CONTAINS: is true if (at least) one word inside the text string matches the query string
** CONTAINS_PREFIX: is true if (at least) one word inside the text string begins with the query string
** CONTAINS_REGEX: is true if (at least) one word inside the text string matches the given regular expression
* String search predicates which match against the entire string value
** PREFIX: if the string value starts with the given query string
** REGEX: if the string value matches the given regular expression in its entirety

See <<text-search>> for more information about full-text and string search.

Geo Predicate
~~~~~~~~~~~~~

The `Geo` enum specifies the geo-location predicate `Geo.WITHIN` which holds true if one geometric object contains the other.


Query Examples
~~~~~~~~~~~~~~

The following query examples demonstrate some of the predicates on the tutorial graph.

[source,java]
// 1) Find vertices with the name "hercules"
g.query().has("name",EQUAL,"hercules").vertices()
// 2) Find all vertices with an age greater than 50
g.query().has("age",GREATER_THAN,50).vertices()
// or find all vertices between 1000 (inclusive) and 5000 (exclusive) years of age and order by increasing age
g.query().has("age",GREATER_THAN_EQUAL,1000).has("age",LESS_THAN,5000).orderBy("age",Order.ASC).vertices()
// which returns the same result set as the following query but in reverse order
g.query().interval("age",1000,5000).orderBy("age",Order.DESC).vertices()
// 3) Find all edges where the place is at most 50 kilometers from the given latitude-longitude pair
g.query().has("place",WITHIN,Geoshape.circle(37.97,23.72,50)).edges()
// 4) Find all edges where reason contains the word "loves"
g.query().has("reason",CONTAINS,"loves").edges()
// or all edges which contain two words (need to chunk into individual words)
g.query().has("reason",CONTAINS,"loves").has("reason",CONTAINS,"breezes").edges()
// or all edges which contain words that start with "lov"
g.query().has("reason",CONTAINS_PREFIX,"lov").edges()
// or all edges which contain words that match the regular expression "br[ez]*s" in their entirety
g.query().has("reason",CONTAINS_REGEX,"br[ez]*s").edges()
// 5) Find all vertices older than a thousand years and named "saturn"
g.query().has("age",GREATER_THAN,1000).has("name",EQUAL,"saturn").vertices()

