Skip to content

Instantly share code, notes, and snippets.

@andreasronge
Created January 24, 2011 18:33
Show Gist options
  • Save andreasronge/793677 to your computer and use it in GitHub Desktop.
Save andreasronge/793677 to your computer and use it in GitHub Desktop.
Batch Inserter API
module Neo4j
module Batch
# == Usage
#
# === Nodes/Properties and Relationships
#
# Example:
#
# inserter = Neo4j::Batch::Inserter.new(config, storage)
#
# node_a = inserter.create_node(:name => 'andreas')
# node_c = inserter.create_node(:name => 'craig')'
#
# inserter.create_rel(node_a, node_c, :since => '2009')
#
# node_a and node_b are simply Fixnum objects
#
# === Index
#
# Example:
#
# inserter = Neo4j::Batch::Inserter.new(config, storage)
# indexer = inserter.exact_indexer
#
# node_a = inserter.create_node(:name => 'andreas')
# indexer.add_index(node_a, :name, 'andreas')'
# indexer.optimize_index
#
# === NodeMixin and _classname
#
# Example:
#
# class Person
# include Neo4j::NodeMixin
# end
#
# inserter = Neo4j::Batch::Inserter.new(config, storage)
# person_inserter = inserter.for_class(Person)
#
# node_a = person_inserter.create_node(:name => 'andreas')
# node_c = person_inserter.create_node(:name => 'craig')'
#
# This will add the '_classname' property'
#
# === NodeMixin and has_n
#
# Example:
#
# class Person
# include Neo4j::NodeMixin
# has_n(:friends).to(Person)
# end
#
# inserter = Neo4j::Batch::Inserter.new(config, storage, Person)
# person_inserter = inserter.for_class(Person)
#
# node_a = person_inserter.create_node(:name => 'andreas')
# node_c = person_inserter.create_node(:name => 'craig')'
#
# person_inserter.create_rel(node_a, node_b, :friends, :since => '2009')
#
# This create a relationship of type 'Person#friend' from node_a to node_b
#
# === NodeMixin and index
#
# Example:
#
# class Person
# include Neo4j::NodeMixin
# property :name
# index :name, :type => :fulltext
# end
#
# inserter = Neo4j::Batch::Inserter.new(config, storage, Person)
# person_inserter = inserter.for_class(Person)
#
# node_a = person_inserter.create_node(:name => 'andreas')
#
# Now there is no need to add an index since the person_inserter will do it for you.
#
# === Using the index
#
# After the #optimize_index has been call one can use the index to find nodes
#
# Example
#
# inserter = Neo4j::Batch::Inserter.new(config, storage, Person)
# person_inserter = inserter.for_class(Person)
#
# # insert and index lots of nodes
# person_inserter.optimize_index
# node_a = person_inserter.find(:name, 'andreas').first
# node_b = person_inserter.find(:name, 'craig').first
# person_inserter.create_rel(node_a, node_b, :friends, :since => '2009')
#
#
# === Shutdown
#
# Example:
#
# inserter = Neo4j::Batch::Inserter.new(config, storage, Person)
# person_inserter = inserter.for_class(Person)
#
# # lots of insert/index operations
# inserter.shutdown
#
# The shutdown method will also shutdown all index inserters.
# Notice, failing to invoke the shutdown method may corrupt the store !
#
class Inserter
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment