22. /*
1. Begin a transaction.
2. Operate on the graph.
3. Mark the transaction as successful (or not).
4. Finish the transaction.
*/
Transaction tx = graphDb.beginTx();
try
{
... // any operation that works with the node space
tx.success();
}
finally
{
tx.finish();
}
23.
24. Graph Databases and Endogenous Indices
name property index
views property index gender property index
name=neo4j
views=56781
page_rank=0.023 cites
cites
name=tenderlove
gender=male
created
created
created
date=2007/10
cites
follows
follows
created
name=peterneubauer follows
name=graph_blog follows
views=1000 follows
created
name=ahzf
name=twarko
age=30
26. // Return the andy node.
index.getSingleNode( "name", "Andy Wachowski" );
// Containing only the larry node
for ( Node hit : index.getNodes( "name", "Larry Wachowski" ) )
{
// do something
}
// Containing both andy and larry
for ( Node hit : index.getNodes( "title", "Director" )
{
// do something
}
http://wiki.neo4j.org/content/Indexing_with_IndexService
27. IndexService index = // your LuceneFulltextIndexService
index.getNodes( "name", "wachowski" ); // --> andy and larry
index.getNodes( "name", "andy" ); // --> andy
index.getNodes( "name", "Andy" ); // --> andy
index.getNodes( "name", "larry Wachowski" ); // --> larry
index.getNodes( "name", "wachowski larry" ); // --> larry
index.getNodes( "name", "wachow* andy" ); // --> andy and larry
index.getNodes( "name", "Andy" ); // --> andy
index.getNodes( "name", "andy" ); // --> andy
index.getNodes( "name", "wachowski" ); // --> andy and larry
index.getNodes( "name", "+wachow* +larry" ); // --> larry
index.getNodes( "name", "andy AND larry" ); // -->
index.getNodes( "name", "andy OR larry" ); // --> andy and larry
index.getNodes( "name", "Wachowski AND larry" ); // --> larry
http://wiki.neo4j.org/content/Indexing_with_IndexService
28. of a spatial, 2D-index that is explicitly14 Marko A.within a Peter Neubauer
modeled Rodriguez and 1 2
In order to demonstrate how a quadtree index can be represented an
patial analysis makes use of advanced indexing structuresis represents a quadtreeset is diagrammed i
versed, a toy graph data set presented. This data
ure 8. The top half of Figure 8 index (vertices 1-9)
[4, 17]. Quadtrees partition a two-dimensional plane into
sed upon the spatial density of the points being indexed. type=quad
ow space is partitioned as the density of points increases bl=[0,0]
tr=[100,100]
e index. 1
sub sub
type=quad type=quad type=quad
bl=[0,0] 2 3 bl=[50,25] 4 bl=[50,0]
tr=[50,100] tr=[75,50] tr=[100,100]
type=quad type=quad
bl=[0,0] bl=[50,50]
tr=[50,50] tr=[100,100]
type=quad type=quad
bl=[0,50] 5 6 9 7 8 bl=[50,0]
tr=[50,100] tr=[100,50]
type=quad
[0,100] 1 bl=[50,25] [100,100]
tr=[62,37]
g f
a b
e
5 7
9 bl=[25,20]
d 3 h
c tr=[90,45]
artition of a plane. This figure is an adaptation of a public
i
d courtesy of David Eppstein. 6 2 4 8 [100,0]
[0,0]
motivations behind this article is to stress the A quadtree index ofof space that contains points of interest. The in
Fig. 8. importance a
29.
30.
31. TraversalDescription description = Traversal.description()
.breadthFirst()
.relationships(Relationships.PAIRED, Direction.OUTGOING)
.evaluator(Evaluators.excludeStartPosition());
description.traverse( startNode ); // Retrieves the traverser
start programmer=(3) match (programmer)-[:PAIRED]->(pair) return pair
start programmer=(3) match (programmer)-[:PAIRED]->(pair)
where pair.age > 30 return pair, count(*) order by age
skip 5 limit 10
32. [InComing/Outgoing relationships]
# All nodes that A has outgoing relationships to.
> start n=node(3) match (n)-->(x) return x
==> Node[4]{name->"Bossman"}
==> Node[5]{name->"Cesar"}
> start n=node(3) match (n)<--(x) return x
==> Node[1]{name->David"}
[Match by relationship type]
# All nodes that are Blocked by A.
> start n=node(3) match (n)-[:BLOCKS]->(x) return x
==> Node[5]{name->"Cesar"}
[Multiple relationships]
# The three nodes in the path.
> start a=node(3) match (a)-[:KNOWS]->(b)-[:KNOWS]->(c) return a,b,c
==> a: Node[3]{name->"Anders"}
==> b: Node[4]{name->"Bossman"}
==> c: Node[2]{name->"Emil"}
33. [Shortest path]
# : find the shortest path between two nodes, as long as the path is max 15
relationships long. Inside of the parenthesis you can write
> start d=node(1), e=node(2) match p = shortestPath( d-[*..15]->e ) return p
==> p: (1)--[KNOWS,2]-->(3)--[KNOWS,0]-->(4)--[KNOWS,3]-->(2)
34. [Count/ Group Count]
> start n=node(2) match (n)-->(x) return n, count(*)
# The start node and the count of related nodes.
==>
n: Node[2]{name->"A",property->13}
count(*): 3
> start n=node(2) match (n)-[r]->() return type(r), count(*)
# The relationship types and their group count.
==>
TYPE(r): KNOWS
count(*): 3