Class: Noiseless::Adapter
Instance Method Summary
collapse
-
#async_context? ⇒ Boolean
-
#bulk(actions) ⇒ Object
-
#create_index(index_name) ⇒ Object
-
#delete_document(index:, id:) ⇒ Object
-
#delete_index(index_name) ⇒ Object
-
#document_exists?(index:, id:) ⇒ Boolean
-
#index_document(index:, id:, document:) ⇒ Object
-
#index_exists?(index_name) ⇒ Boolean
-
#initialize(hosts: [], **connection_params) ⇒ Adapter
constructor
A new instance of Adapter.
-
#search(ast_node, model_class: nil, response_type: nil) ⇒ Object
Convert AST to Hash/JSON before execution.
-
#search_raw(query_body, indexes: []) ⇒ Object
Raw search method for backward compatibility.
-
#update_document(index:, id:, changes:) ⇒ Object
#adapter_capabilities, #adapter_info, #build_execution_plan, #compatibility_matrix, #detect_execution_module, #engine_name, #explain_query, #profile_query
#instrument
Constructor Details
#initialize(hosts: [], **connection_params) ⇒ Adapter
Returns a new instance of Adapter.
12
13
14
15
16
|
# File 'lib/noiseless/adapter.rb', line 12
def initialize(hosts: [], **connection_params)
@hosts = hosts
@connection_params = connection_params.dup
@connection_params.delete(:async)
end
|
Instance Method Details
#async_context? ⇒ Boolean
18
19
20
|
# File 'lib/noiseless/adapter.rb', line 18
def async_context?
true
end
|
#bulk(actions) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/noiseless/adapter.rb', line 40
def bulk(actions, **)
Async do
instrument(:bulk, actions_count: actions.size) do
execute_bulk(actions, **)
end
end
end
|
#create_index(index_name) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/noiseless/adapter.rb', line 48
def create_index(index_name, **)
Async do
instrument(:create_index, index: index_name) do
execute_create_index(index_name, **)
end
end
end
|
#delete_document(index:, id:) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/noiseless/adapter.rb', line 86
def delete_document(index:, id:, **)
Async do
instrument(:delete_document, index: index, id: id) do
execute_delete_document(index, id, **)
end
end
end
|
#delete_index(index_name) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/noiseless/adapter.rb', line 56
def delete_index(index_name, **)
Async do
instrument(:delete_index, index: index_name) do
execute_delete_index(index_name, **)
end
end
end
|
#document_exists?(index:, id:) ⇒ Boolean
94
95
96
97
98
|
# File 'lib/noiseless/adapter.rb', line 94
def document_exists?(index:, id:)
Async do
execute_document_exists?(index, id)
end
end
|
#index_document(index:, id:, document:) ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/noiseless/adapter.rb', line 70
def index_document(index:, id:, document:, **)
Async do
instrument(:index_document, index: index, id: id) do
execute_index_document(index, id, document, **)
end
end
end
|
#index_exists?(index_name) ⇒ Boolean
64
65
66
67
68
|
# File 'lib/noiseless/adapter.rb', line 64
def index_exists?(index_name)
Async do
execute_index_exists?(index_name)
end
end
|
#search(ast_node, model_class: nil, response_type: nil) ⇒ Object
Convert AST to Hash/JSON before execution
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/noiseless/adapter.rb', line 23
def search(ast_node, model_class: nil, response_type: nil, **)
query_hash = ast_to_hash(ast_node)
Async do
raw_response = instrument(:search, indexes: ast_node.indexes, query: query_hash) do
execute_search(query_hash, indexes: ast_node.indexes, **)
end
ResponseFactory.create(
raw_response,
model_class: model_class,
response_type: response_type,
query_hash: query_hash
)
end
end
|
#search_raw(query_body, indexes: []) ⇒ Object
Raw search method for backward compatibility
101
102
103
104
105
106
107
|
# File 'lib/noiseless/adapter.rb', line 101
def search_raw(query_body, indexes: [], **)
Async do
instrument(:search, indexes: indexes, query: query_body) do
execute_search(query_body, indexes: indexes, **)
end
end
end
|
#update_document(index:, id:, changes:) ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/noiseless/adapter.rb', line 78
def update_document(index:, id:, changes:, **)
Async do
instrument(:update_document, index: index, id: id, changes_count: changes.size) do
execute_update_document(index, id, changes, **)
end
end
end
|