Search using non-tokenized methods on strings

eq()

In a traversal query, use a non-token search to list all recipes that have Carrot Soup in the recipe name. Note that this search is case-sensitive, so using carrot soup would not find a vertex. The method eq() is used with a supplied name.

g.V().hasLabel('recipe').has('name', eq('Carrot Soup')).values('name')

results in:

==>Carrot Soup

In a traversal query, use a non-token search to list all recipes that have Carrot in the recipe name. The method eq() is used with a supplied name.

g.V().hasLabel('recipe').has('name', eq('Carrot')).values('name')

No match is found, because only a partial name was specified. For asString() indexes, the string must match.

There is an alternative predicate, within(), that works similarly to eq(), but not exactly the same.

neq()

In a traversal query, use a non-token search to list all recipes that do not have the word Saute in recipe instructions using neq():

g.V().has('recipe', 'instructions', neq('Saute')).values('name')

results in:

==>Salade Nicoise
==>Spicy Meatloaf
==>Rataouille
==>Carrot Soup
==>Roast Pork Loin

There is an alternative predicate, without(), that works identically to neq().

phrase()

The phrase() predicate is used with properties designated as TextFields.Find the exact phrase Wild Mushroom Stroganoff in a recipe name:

g.V().hasLabel('recipe').has('name', phrase('Wild Mushroom Stroganoff',0))

The 0 designates that the result must be an exact phrase.The query results in:

==>v[dseg:/recipe/2004]

The vertex id for the correct recipe is returned.

The phrase() predicate can be used for proximity searches, to discover phrases that have terms that are within a certain distance of one another in the tokenized text.

g.V().hasLabel('recipe').has('name', phrase('Wild Mushroom Stroganoff',1))

The value of 1 designates that the result must only have words in the recipe name that are one term away from one another.

==>v[dseg:/recipe/2004]

The vertex for the correct recipe is returned.

A match for g.V().hasLabel('recipe').has('name', phrase('Wild Mushroom',1)) will also return the correct vertex, butg.V().hasLabel('recipe').has('name', phrase('Mushroom Wild',1)) will not.

prefix()

In a traversal query, use a non-token search to find all recipes that have a name beginning with the letter R. The method prefix() is used with a supplied string.

g.V().hasLabel('recipe').has('name', prefix('R')).values('name')

results in:

==>Roast Pork Loin
==>Rataouille

Matches are found for each recipe name that begins with R, provided the recipe name was designated with asString() in the search index.

regex()

In a traversal query, use a non-token search to find all recipes that have a name that includes a specified regular expression. The method regex() is used with a supplied regex.

g.V().hasLabel('recipe').has('name', regex('.*ee.*')).values('name')

results in:

==>Beef Bourguignon

Matches are found for each recipe name that include the regex .ee. to find all strings that include ee preceded and followed by any number of other characters, provided the recipe name was designated with asString() in the search index.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com