Class: Neography::Rest::Indexes
- Inherits:
-
Object
- Object
- Neography::Rest::Indexes
show all
- Includes:
- Helpers
- Defined in:
- lib/neography/rest/indexes.rb
Instance Method Summary
collapse
-
#add(index, key, value, id) ⇒ Object
-
#create(name, type = "exact", provider = "lucene") ⇒ Object
-
#create_auto(type = "exact", provider = "lucene") ⇒ Object
-
#find(index, key_or_query, value = nil) ⇒ Object
-
#find_by_key_value(index, key, value) ⇒ Object
-
#find_by_query(index, query) ⇒ Object
-
#get(index, key, value) ⇒ Object
-
#initialize(connection, index_type) ⇒ Indexes
constructor
A new instance of Indexes.
-
#list ⇒ Object
-
#remove(index, id_or_key, id_or_value = nil, id = nil) ⇒ Object
Mimick original neography API in Rest class.
-
#remove_by_id(index, id) ⇒ Object
-
#remove_by_key(index, id, key) ⇒ Object
-
#remove_by_value(index, id, key, value) ⇒ Object
Methods included from Helpers
#get_id, #json_content_type
Constructor Details
#initialize(connection, index_type) ⇒ Indexes
Returns a new instance of Indexes.
6
7
8
9
|
# File 'lib/neography/rest/indexes.rb', line 6
def initialize(connection, index_type)
@connection = connection
@index_type = index_type
end
|
Instance Method Details
#add(index, key, value, id) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/neography/rest/indexes.rb', line 34
def add(index, key, value, id)
options = {
:body => (
{ :uri => @connection.configuration + "/#{@index_type}/#{get_id(id)}",
:key => key,
:value => value
}
).to_json,
:headers => json_content_type
}
@connection.post(base_path(:index => index), options)
end
|
#create(name, type = "exact", provider = "lucene") ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/neography/rest/indexes.rb', line 15
def create(name, type = "exact", provider = "lucene")
options = {
:body => (
{ :name => name,
:config => {
:type => type,
:provider => provider
}
}
).to_json,
:headers => json_content_type
}
@connection.post(all_path, options)
end
|
#create_auto(type = "exact", provider = "lucene") ⇒ Object
30
31
32
|
# File 'lib/neography/rest/indexes.rb', line 30
def create_auto(type = "exact", provider = "lucene")
create("#{@index_type}_auto_index", type, provider)
end
|
#find(index, key_or_query, value = nil) ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'lib/neography/rest/indexes.rb', line 54
def find(index, key_or_query, value = nil)
if value
index = find_by_key_value(index, key_or_query, value)
else
index = find_by_query(index, key_or_query)
end
return nil if index.empty?
index
end
|
#find_by_key_value(index, key, value) ⇒ Object
64
65
66
|
# File 'lib/neography/rest/indexes.rb', line 64
def find_by_key_value(index, key, value)
@connection.get(key_value_path(:index => index, :key => key, :value => value)) || []
end
|
#find_by_query(index, query) ⇒ Object
68
69
70
|
# File 'lib/neography/rest/indexes.rb', line 68
def find_by_query(index, query)
@connection.get(query_path(:index => index, :query => query)) || []
end
|
#get(index, key, value) ⇒ Object
48
49
50
51
52
|
# File 'lib/neography/rest/indexes.rb', line 48
def get(index, key, value)
index = @connection.get(key_value_path(:index => index, :key => key, :value => value)) || []
return nil if index.empty?
index
end
|
#list ⇒ Object
11
12
13
|
# File 'lib/neography/rest/indexes.rb', line 11
def list
@connection.get(all_path)
end
|
#remove(index, id_or_key, id_or_value = nil, id = nil) ⇒ Object
Mimick original neography API in Rest class.
73
74
75
76
77
78
79
80
81
|
# File 'lib/neography/rest/indexes.rb', line 73
def remove(index, id_or_key, id_or_value = nil, id = nil)
if id
remove_by_value(index, id, id_or_key, id_or_value)
elsif id_or_value
remove_by_key(index, id_or_value, id_or_key)
else
remove_by_id(index, id_or_key)
end
end
|
#remove_by_id(index, id) ⇒ Object
83
84
85
|
# File 'lib/neography/rest/indexes.rb', line 83
def remove_by_id(index, id)
@connection.delete(id_path(:index => index, :id => get_id(id)))
end
|
#remove_by_key(index, id, key) ⇒ Object
87
88
89
|
# File 'lib/neography/rest/indexes.rb', line 87
def remove_by_key(index, id, key)
@connection.delete(key_path(:index => index, :id => get_id(id), :key => key))
end
|
#remove_by_value(index, id, key, value) ⇒ Object
91
92
93
|
# File 'lib/neography/rest/indexes.rb', line 91
def remove_by_value(index, id, key, value)
@connection.delete(value_path(:index => index, :id => get_id(id), :key => key, :value => value))
end
|