Skip to content

Commit

Permalink
Inheritance of Ruby Classes now work with lucene indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasronge committed Sep 20, 2010
1 parent 924ca6c commit 535aeab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 10 additions & 7 deletions lib/neo4j/index.rb
Expand Up @@ -19,6 +19,7 @@ def indexer(clazz)
if @@indexers.include?(clazz)
# we want to reuse an existing index
@indexer = @@indexers[clazz]
@indexer.include_trigger(self)
else
@indexer = Indexer.new(clazz)
@@indexers[clazz] = @indexer
Expand All @@ -37,6 +38,7 @@ def initialize(clazz)

@indexes = {} # key = type, value = java neo4j index
@field_types = {} # key = field, value = type (e.g. :exact or :fulltext)
@triggered_by = clazz.to_s
end

# add an index on a field that will be automatically updated by events.
Expand Down Expand Up @@ -99,12 +101,9 @@ def index_for_type(type)
end

def lucene_config(type)
# TODO by some weired reason we can't but this in a hash
case type.to_sym
when :exact then org.neo4j.index.impl.lucene.LuceneIndexProvider::EXACT_CONFIG
when :fulltext then org.neo4j.index.impl.lucene.LuceneIndexProvider::FULLTEXT_CONFIG
else raise "unknown lucene type #{type}"
end
conf = Neo4j::Config[:lucene][type.to_sym]
raise "unknown lucene type #{type}" unless conf
conf
end

def create_index_with(type)
Expand All @@ -118,8 +117,12 @@ def create_index_with(type)
# ------------------------------------------------------------------
# Event Handling

def include_trigger(clazz)
@triggered_by << clazz.to_s unless @triggered_by.include?(clazz.to_s)
end

def trigger?(classname)
@index_name == classname || (classname.nil? && @index_name == 'Neo4j::Node')
@triggered_by.include?(classname.nil? ? 'Neo4j::Node' : classname)
end

def on_node_created(node)
Expand Down
1 change: 0 additions & 1 deletion spec/integration/index_spec.rb
Expand Up @@ -24,7 +24,6 @@ class Car < Vehicle
end

it "can use the same index for a subclass" do
pending
volvo = Car.new(:brand => 'volvo', :wheels => 4)
new_tx
Car.find('brand: volvo').first.should == volvo
Expand Down

0 comments on commit 535aeab

Please sign in to comment.