Category Archives: Cypher

Enabling Legacy Automatic Full Text Search on Neo4j 3.x

solar-elastic-lucene

Neo4j 3.x has made inroads toward Full Text Search capabilities using Cypher keywords “STARTS WITH”, “ENDS WITH” and “CONTAINS”. However this search capability is limited to a single Schema Index and can be a problem when you need a very flexible search interface. To search across multiple models you can do this trick:
Continue reading

Tagged , , , , ,

News Feeds

Ron Burgundy Gets Hungry

Ron Burgundy (in Anchorman) gets Hungry

The “News Feed” is a core feature of social networks like Twitter, Facebook, or Vine (RIP). Let’s take a look at how we could model and implement this in Neo4j. Our social network needs Users (otherwise it would be kinda empty) that FOLLOW each other (otherwise it would not be very social). Those users need to POST some Messages (otherwise it would be boring). Here is our first attempt at a model (using Arrows):
Continue reading

Tagged , , , , , , ,

Catalogs and Hierarchies

street-samurai-catalog-large

When I was younger, friends and I would play a role playing game called “Shadowrun“. The game draws elements from science fiction, crime dramas, and magic and blends them all together to make a fun mess. You could be a Dwarf Shaman, an Elf Decker, a Human Rigger, an Orc Adept, a Troll Street Samurai or whatever combination your heart desired. Choosing a gender, race and archetype was just the beginning a more important question: “What is your character going to wear and take on missions?”
Continue reading

Tagged , , , , , , , ,

Speeding up Traversals

roots

A few folks have come to us recently with the need to trace lineages of nodes of variable depth many hops away. You can run into this need if you are looking at the ancestries of living things, tracing data as it flows through an ETL, large network connectivity maps, etc. These types of queries tend to be murder on relational databases because of the massive recursive joins they have to deal with. Let’s give them a try in Neo4j.
Continue reading

Tagged , , , , ,

Scaling Cypher Writes

salt-pepa-writes

Let’s talk about writes, baby. Let’s talk about you and me. Let’s talk about all the good things. And the bad things that may be. Let’s talk about writes, and indexing and batching, and transactions in Neo4j. Let’s start with my environment. A 3 year old MacBook Pro (dying to get the new ones… once they finally come out) running a 4 core 2.3 GHz Intel Core i7 that is hyper-threading and pretending to have 8. An Apple SM256E SSD that is about average as far as SSDs go. So definitely not a production grade server, so bear that in mind.
Continue reading

Tagged , , , , , ,

Importing the Hacker News Interest Graph

HackerNews-799e9e47

Graphs are everywhere. Think about the computer networks that allow you to read this sentence, the road or train networks that get you to work, the social network that surrounds you and the interest graph that holds your attention. Everywhere you look, graphs. If you manage to look somewhere and you don’t see a graph, then you may be looking at an opportunity to build one. Today we are going to do just that. We are going to make use of the new Neo4j Import tool to build a graph of the things that interest Hacker News.
Continue reading

Tagged , , , , , , , , , , , ,

Triggers in Neo4j

al-capones-gun

One of the often overlooked features in Neo4j is the “TransactionEventHandler” capabilities… better known in the database world as “Triggers“. When a transaction occurs, we can analyze that event and decide to take some action. To accomplish this, we’ll write a “Kernel Extension” ( a little different from the Unmanaged Extensions we’ve seen on this blog ) to tie in our trigger.

Continue reading

Tagged , , , , , ,

One Direction Relationships in Neo4j

onedirectionchop

In the Neo4j Property Graph model, every single Relationship must be Typed and Directed. This means they must have a specific name (FRIENDS, LIKES, FOLLOWS, etc) and have a Start Node and an End Node to show direction. What’s neat is that when you write your queries you can choose to ignore that. The following queries are all valid:

// Get all the people I follow 
MATCH (u1:Person)-[:FOLLOWS]->(u2:Person)
WHERE u1.username = "maxdemarzi"
RETURN u2.username

// Get all the people that I follow or follow me
MATCH (u1:Person)-[:FOLLOWS]-(u2:Person)
WHERE u1.username = "maxdemarzi"
RETURN u2.username

// Get all the people related to me 
MATCH (u1:Person)--(u2:Person)
WHERE u1.username = "maxdemarzi"
RETURN u2.username

Continue reading

Tagged , , , , ,

Giving Neo4j 2.2 a Workout

rhino_running

Neo4j 2.2 is getting released any day now, so let’s put the Release Candidate through its paces with Gatling. Once we download and start it up, you’ll notice it wants us to authenticate.
Continue reading

Tagged , , , , , , , ,

Tracking User Paths in an IVR with Neo4j

I started my software development career writing applications for a Call Center at a small bank in Florida. I remember the bank had purchased whatever the “Cadillac” of Interactive Voice Response (IVR) systems was then for some crazy amount of money. Today you can build an IVR overnight using Twilio.

twilio

When you sign up with Twilio, you get to choose your phone number (more or less). For example, I picked +1 (636) 451-7411, which spells out +1 (neo) 4j1-7411. If you were to call this number right now (assuming I have not run out of Twilio credits) you’ll connect to my IVR.
Continue reading

Tagged , , , , ,