Skip to content

Instantly share code, notes, and snippets.

@hipertracker
Created October 10, 2009 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hipertracker/206827 to your computer and use it in GitHub Desktop.
Save hipertracker/206827 to your computer and use it in GitHub Desktop.
# testneo.rb
require 'rubygems'
require 'neo4j'
NEO4J_STORAGE = File.dirname(__FILE__)+'/db/neo4j'
LUCENE_STORAGE = File.dirname(__FILE__)+'/db/lucene'
Neo4j::Config[:storage_path] = NEO4J_STORAGE
Lucene::Config[:store_on_file] = true
Lucene::Config[:storage_path] = LUCENE_STORAGE
FileUtils.rm_rf NEO4J_STORAGE
FileUtils.rm_rf LUCENE_STORAGE
class NeoLang
include Neo4j::NodeMixin
property :code, :name, :available
index :code, :tokenized => true
index :name, :tokenized => true
index :available, :tokenized => true
def to_s
"#{self.code}(#{self.name})"
end
end
Neo4j.start
Neo4j::Transaction.run do
node = NeoLang.new
node.code = 'en'
node.name = "English"
node.available = 1
node = NeoLang.new
node.code = 'it'
node.name = "Italian"
node.available = 1
end
Neo4j::Transaction.run do
NeoLang.find(:available=>1).each{|o|puts o}
# => en(English)
# => it(Italian)
p NeoLang.find(:code=>'it').first
# => nil .............................. WTF?
puts NeoLang.find(:code=>'en').first
# => en(English)
puts '--'
# again, with Lucene DSL:
NeoLang.find('available:1').each{|o|puts o}
# => en(English)
# => it(Italian)
p NeoLang.find('code:it').first
# => nil .............................. WTF?
puts NeoLang.find('code:en').first
# => en(English)
end
Neo4j.stop
=begin
MacBook Pro, Mac OS-X 2.6.1, used Lucene 2.4.0, but also tested with Lucene 2.9.0
$ uname -a
Darwin MacBook-Pro-15-admin.local 10.0.0 Darwin Kernel Version 10.0.0: Fri Jul 31 22:47:34 PDT 2009; root:xnu-1456.1.25~1/RELEASE_I386 i386
$ java -version
java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03-219)
Java HotSpot(TM) 64-Bit Server VM (build 14.1-b02-90, mixed mode)
$ jruby -v
jruby 1.4.0RC1 (ruby 1.8.7 patchlevel 174) (2009-10-06 6586) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_15) [x86_64-java]
$ jruby -S gem list neo4j
neo4j (0.3.2)
$ jruby testneo.rb
en(English)
it(Italian)
nil
en(English)
--
en(English)
it(Italian)
nil
en(English)
=end
# ANOTHER TRY:
#!/opt/jruby/bin/jruby
require 'rubygems'
require 'neo4j'
NEO4J_STORAGE = File.dirname(__FILE__)+'/db/neo4j'
LUCENE_STORAGE = File.dirname(__FILE__)+'/db/lucene'
Neo4j::Config[:storage_path] = NEO4J_STORAGE
Lucene::Config[:store_on_file] = true
Lucene::Config[:storage_path] = LUCENE_STORAGE
FileUtils.rm_rf NEO4J_STORAGE
FileUtils.rm_rf LUCENE_STORAGE
class NeoLang
include Neo4j::NodeMixin
property :code
index :code
def to_s
"#{self.code}"
end
end
Neo4j.start
@langs = %w(en at ut ti it id)
Neo4j::Transaction.run do
@langs.each do |lang|
node = NeoLang.new
node.code = lang
end
end
Neo4j::Transaction.run do
puts "Try1:"
@langs.each do |lang|
puts "#{lang} -> #{NeoLang.find(:code=>lang).first.to_s}"
end
puts "Try2:"
@langs.each do |lang|
puts "#{lang} -> #{NeoLang.find('code:'+lang).first.to_s}"
end
end
Neo4j.stop
=begin
Result:
Try1:
en -> en
at -> at
ut -> ut
ti -> ti
it -> it
id -> id
Try2:
en -> en
at ->
ut -> ut
ti -> ti
it ->
id -> id
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment