Skip to content

Commit

Permalink
adding more indexing capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jul 18, 2012
1 parent 28313e1 commit 65f6ca9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 32 deletions.
38 changes: 34 additions & 4 deletions lib/neography/index.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
module Neography
module Index

def index(*args)

def self.included(base)
base.extend(ClassMethods)
end

def add_to_index(index, key, value)
if self.is_a? Neography::Node
neo_server.add_node_to_index(index, key, value, self.neo_id)
else
neo_server.add_relationship_to_index(index, key, value, self.neo_id)
end
end

def find(*args)

def remove_from_index(*args)
if self.is_a? Neography::Node
neo_server.remove_node_from_index(*args)
else
neo_server.remove_relationship_from_index(*args)
end
end

module ClassMethods
def find(*args)
if name == "Neography::Node"
if args.size > 1
neo_server.find_node_index(*args)
else
neo_server.get_node_index(*args)
end
else
if args.size > 1
neo_server.find_relationship_index(*args)
else
neo_server.get_relationship_index(*args)
end
end
end
end

end
end
2 changes: 1 addition & 1 deletion lib/neography/node.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Neography
class Node < PropertyContainer
extend Neography::Index
include Neography::Index
include Neography::NodeRelationship
include Neography::NodePath
include Neography::Equal
Expand Down
2 changes: 1 addition & 1 deletion lib/neography/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Neography
class Relationship < PropertyContainer
include Neography::Equal
include Neography::Property
extend Neography::Index
include Neography::Index

attr_accessor :start_node, :end_node, :rel_type

Expand Down
41 changes: 15 additions & 26 deletions spec/integration/index_spec.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe Neography::Relationship, "find" do
before(:each) do
pending "Phase 2 - Index part is not done."
Neography::Relationship.index(:strength)
end
describe Neography::Index do

it "can index when Neography::Relationships are created" do
a = Neography::Node.create
b = Neography::Node.create
r = Neography::Relationship.create(:friends, a, b)
r[:strength] = 'strong'
Neography::Relationship.find('strength: strong').first.should == r
it "can add a node to an index" do
new_node = Neography::Node.create
key = generate_text(6)
value = generate_text
new_node.add_to_index("node_test_index", key, value)
end

it "can remove index when Neography::Relationship is deleted, just like nodes" do
a = Neography::Node.create
b = Neography::Node.create
r = Neography::Relationship.create(:friends, a, b)
r[:strength] = 'weak'
r2 = Neography::Relationship.find('strength: weak').first
r2.should == r
r2.del
Neography::Relationship.find('strength: weak').should be_empty
it "can add a relationship to an index" do
node1 = Neography::Node.create
node2 = Neography::Node.create
r = Neography::Relationship.create(:friends, node1, node2)
key = generate_text(6)
value = generate_text
r.add_to_index("relationship_test_index", key, value)
end
end


describe Neography::Node, "find" do

end

end

0 comments on commit 65f6ca9

Please sign in to comment.