sebastiandaschner blog


How to Search Full-text in Neo4j with Java & Quarkus OGM

#neo4j #java #quarkus thursday, may 19, 2022

In the following video, I’ll show how to conduct searches with your Neo4j database. We have the possibility to define full-text indexes or other searches such as via regular expressions, and we’ll have a look how to implement these in your Java application.

 

 

The example uses my favorite coffee example on GitHub and is based on the code I showed in a previous post on building recommendations with Neo4j.

 

You define and call full-text indexes as follows:

CALL db.index.fulltext.createNodeIndex("beanNames", ["CoffeeBean"], ["name"]);
// OR
CALL db.index.fulltext.createNodeIndex("beanNames", ["CoffeeBean"], ["name"],
  {analyzer: "simple"});

// invoke search
CALL db.index.fulltext.queryNodes("beanNames", "some query") YIELD node, score
WITH node, score
RETURN node
ORDER BY score DESC, node.name

 

Regex searches work as follows:

MATCH (bean:CoffeeBean)
WHERE bean.name =~ "Hello.*"
RETURN bean
ORDER BY bean.name

 

Happy searching!

 

Found the post useful? Subscribe to my newsletter for more free content, tips and tricks on IT & Java: