Module: Neography::Rest::RelationshipIndexes

Includes:
Helpers
Included in:
Neography::Rest
Defined in:
lib/neography/rest/relationship_indexes.rb

Instance Method Summary collapse

Methods included from Helpers

#encode, #escape, #get_id, #json_content_type, #parse_depth, #parse_direction, #parse_order, #parse_type, #parse_uniqueness

Instance Method Details

#add_relationship_to_index(index, key, value, id, unique = false) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/neography/rest/relationship_indexes.rb', line 31

def add_relationship_to_index(index, key, value, id, unique = false)
  options = {
    :body => (
      { :uri   => @connection.configuration + "/relationship/#{get_id(id)}",
        :key   => key,
        :value => value
      }
    ).to_json,
    :headers => json_content_type
  }
  path = unique ? "/index/relationship/%{index}?unique" % {:index => index} : "/index/relationship/%{index}" % {:index => index}
  @connection.post(path, options)
end

#create_or_fail_unique_relationship(index, key, value, properties = {}) ⇒ Object


124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/neography/rest/relationship_indexes.rb', line 124

def create_or_fail_unique_relationship(index, key, value, properties = {})
  options = {
    :body => (
      { :properties => properties,
        :key => key,
        :value => value
      }
    ).to_json,
    :headers => json_content_type
  }
  @connection.post("/index/relationship/%{index}?uniqueness=%{function}" %  {:index => index, :function => 'create_or_fail'}, options)

end

#create_relationship_auto_index(type = "exact", provider = "lucene") ⇒ Object


27
28
29
# File 'lib/neography/rest/relationship_indexes.rb', line 27

def create_relationship_auto_index(type = "exact", provider = "lucene")
  create_relationship_index("relationship_auto_index", type, provider)
end

#create_relationship_index(name, type = "exact", provider = "lucene", extra_config = nil) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/neography/rest/relationship_indexes.rb', line 10

def create_relationship_index(name, type = "exact", provider = "lucene", extra_config = nil)
  config = {
    :type => type,
    :provider => provider
  }
  config.merge!(extra_config) unless extra_config.nil?
  options = {
    :body => (
      { :name => name,
        :config => config
      }
    ).to_json,
    :headers => json_content_type
  }
  @connection.post("/index/relationship", options)
end

#create_unique_relationship(index, key, value, type, from, to, props = nil) ⇒ Object


96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/neography/rest/relationship_indexes.rb', line 96

def create_unique_relationship(index, key, value, type, from, to, props = nil)
  body = {
    :key   => key,
    :value => value,
    :type  => type,
    :start => @connection.configuration + "/node/#{get_id(from)}",
    :end   => @connection.configuration + "/node/#{get_id(to)}",
    :properties => props
  }
  options = { :body => body.to_json, :headers => json_content_type }

  @connection.post("/index/relationship/%{index}?unique" % {:index => index}, options)
end

#drop_relationship_index(index) ⇒ Object


92
93
94
# File 'lib/neography/rest/relationship_indexes.rb', line 92

def drop_relationship_index(index)
  @connection.delete("/index/relationship/%{index}" % {:index => index})
end

#find_relationship_index(index, key_or_query, value = nil) ⇒ Object


51
52
53
54
55
56
57
58
59
# File 'lib/neography/rest/relationship_indexes.rb', line 51

def find_relationship_index(index, key_or_query, value = nil)
  if value
    index = find_relationship_index_by_key_value(index, key_or_query, value)
  else
    index = find_relationship_index_by_query(index, key_or_query)
  end
  return nil if index.empty?
  index
end

#find_relationship_index_by_key_value(index, key, value) ⇒ Object


61
62
63
# File 'lib/neography/rest/relationship_indexes.rb', line 61

def find_relationship_index_by_key_value(index, key, value)
  @connection.get("/index/relationship/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}) || []
end

#find_relationship_index_by_query(index, query) ⇒ Object


65
66
67
# File 'lib/neography/rest/relationship_indexes.rb', line 65

def find_relationship_index_by_query(index, query)
  @connection.get("/index/relationship/%{index}?query=%{query}" % {:index => index, :query => encode(query)}) || []
end

#get_or_create_unique_relationship(index, key, value, properties = {}) ⇒ Object


110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/neography/rest/relationship_indexes.rb', line 110

def get_or_create_unique_relationship(index, key, value, properties = {})
  options = {
    :body => (
      { :properties => properties,
        :key => key,
        :value => value
      }
    ).to_json,
    :headers => json_content_type
  }
  @connection.post("/index/relationship/%{index}?uniqueness=%{function}" %  {:index => index, :function => 'get_or_create'}, options)

end

#get_relationship_index(index, key, value) ⇒ Object


45
46
47
48
49
# File 'lib/neography/rest/relationship_indexes.rb', line 45

def get_relationship_index(index, key, value)
  index = @connection.get("/index/relationship/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}) || []
  return nil if index.empty?
  index
end

#list_relationship_indexesObject


6
7
8
# File 'lib/neography/rest/relationship_indexes.rb', line 6

def list_relationship_indexes
  @connection.get("/index/relationship")
end

#remove_relationship_from_index(index, id_or_key, id_or_value = nil, id = nil) ⇒ Object

Mimick original neography API in Rest class.


70
71
72
73
74
75
76
77
78
# File 'lib/neography/rest/relationship_indexes.rb', line 70

def remove_relationship_from_index(index, id_or_key, id_or_value = nil, id = nil)
  if id
    remove_relationship_index_by_value(index, id, id_or_key, id_or_value)
  elsif id_or_value
    remove_relationship_index_by_key(index, id_or_value, id_or_key)
  else
    remove_relationship_index_by_id(index, id_or_key)
  end
end

#remove_relationship_index_by_id(index, id) ⇒ Object


80
81
82
# File 'lib/neography/rest/relationship_indexes.rb', line 80

def remove_relationship_index_by_id(index, id)
  @connection.delete("/index/relationship/%{index}/%{id}" % {:index => index, :id => get_id(id)})
end

#remove_relationship_index_by_key(index, id, key) ⇒ Object


84
85
86
# File 'lib/neography/rest/relationship_indexes.rb', line 84

def remove_relationship_index_by_key(index, id, key)
  @connection.delete("/index/relationship/%{index}/%{key}/%{id}" % {:index => index, :id => get_id(id), :key => key})
end

#remove_relationship_index_by_value(index, id, key, value) ⇒ Object


88
89
90
# File 'lib/neography/rest/relationship_indexes.rb', line 88

def remove_relationship_index_by_value(index, id, key, value)
  @connection.delete("/index/relationship/%{index}/%{key}/%{value}/%{id}" % {:index => index, :id => get_id(id), :key => key, :value => encode(value)})
end