DZone
Big Data Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Big Data Zone > Neo4j With Scala: Full Text Search

Neo4j With Scala: Full Text Search

Now that we have looked at integrating Neo4j and Scala, the fifth part of this series gives us a walkthrough about how to use full text search.

Anurag Srivastava user avatar by
Anurag Srivastava
·
Dec. 21, 16 · Big Data Zone · Tutorial
Like (3)
Save
Tweet
4.02K Views

Join the DZone community and get the full member experience.

Join For Free

Welcome back to my series about Neo4j with Scala. Until now, we have talked and learned about the use of Neo4j with Scala and how easily we can integrate both amazing technologies.

Before starting this article, here is a quick recap:

  1. Neo4j With Scala: An Introduction
  2. Neo4j With Scala: User Defined Procedures and APOC
  3. Neo4j With Scala: Migrating Data
  4. Neo4j With Scala: Awesome Experience With Spark

ElasticSearch is a modern search and analytic engine based on Apache Lucene. ElasticSearch is a full-text search engine and is highly scalable. It allows RESTful web interface and schema-free documents. ElasticSearch is able to achieve fast search responses because it searches an index instead of searching the text directly. ElasticSearch also provides the capability to store data but we shouldn’t use it as a primary database because ES does not provide following support:

  1. Security: ES does not provide any access control and authentication.
  2. Maturity of tools: ES does not provide mature client libraries and 3rd party tools, it makes developer life much harder.
  3. Transaction: ES doesn’t provide transaction and processing for data manipulation.
  4. Long Computation: ES commands for searching data are not suited to “large” scans of data and advanced computation on the database side.
  5. Durability: ES is scalable and distributed but backup and durability is not as high as other databases. You can lose your data if you make it your primary database.

These are some concerns when using ES. Neo4j provides the way to overcome the concerns we mentioned above and also provides full text search with the 3.x version.

We can use cypher keywords, “CONTAINS”, “STARTS WITH”, “ENDS WITH” for the full text search but it is limited to the single schema. So when we try to use it with multiple schema, we have to use keyword “UNION” and implement the multiple cypher query.

MATCH (r:Restaurant) WHERE r.name STARTS WITH {search_term} RETURN count(*);
UNION
MATCH (c:City) WHERE c.name CONTAINS {search_term} RETURN count(*);
UNION
MATCH (a:Address) WHERE a.name ENDS WITH {search_term} RETURN count(*);

But this will work only for the limited schema. When you have to make full text searching on the multiples schemas, it is better to use indexes and it will be the better choice to gain it. We have to make changes these changes (which mention below) in the conf file.

# Set this parameter equal to true to enable it
dbms.auto_index.nodes.enabled=true
# A list of node property names (comma separated) that will be indexed by default.
dbms.auto_index.nodes.keys=country

After making changes in the conf, we have to restart the neo4j and create node.

CREATE (c:Country {country:"india"})

Now we have almost finished with the primary setup. Now to see the whole picture we have to start the neo4j-shell and run this command:

index --get-config node_auto_index

Output :
{
    "provider": "lucene",
    "type": "exact"
}

exact.pngGreat, we are ready.

Wait! Here we find “exact” so now what can we do? We run the following command to change it:

index --set-config node_auto_index type fulltext

Output :
INDEX CONFIGURATION CHANGED, INDEX DATA MAY BE INVALID

When we run the above cypher it leads to very specific information, so what do we do here? We can simply reset the name property of each type of node we want to index to itself.

MATCH (c:Country) SET c.country = c.country

Now we are done with our indexing work and ready to test the result. Run this command for the searching in neo4j :

START n=node:node_auto_index("country:*india*") RETURN n;

fulltextsearch.png

Here we see that how can we use neo4j for the full text search, with Neo4j we get the advantages of database with the searching. This is a sample example on very less amount of data but we can use it on a large amount of data effectively.

I hope it will help you to set-up full text search with Neo4j.

Thanks.

References

Automatic Full Text Search on Neo4j3.x 

Database Neo4j Scala (programming language)

Published at DZone with permission of Anurag Srivastava, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Progressive Web Apps vs Native Apps: Differences and Similarities
  • Top 7 Features in Jakarta EE 10 Release
  • When Writing Code Isn't Enough: Citizen Development and the Developer Experience
  • 12 Modern CSS Techniques For Older CSS Problems

Comments

Big Data Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo