Class: Gcloud::Search::Connection
- Inherits:
-
Object
- Object
- Gcloud::Search::Connection
- Defined in:
- lib/gcloud/search/connection.rb
Overview
Represents the connection to Search, as well as expose the API calls.
Constant Summary collapse
- API_VERSION =
:nodoc:
"v1"
Instance Attribute Summary collapse
-
#client ⇒ Object
:nodoc:.
-
#connection ⇒ Object
:nodoc:.
-
#credentials ⇒ Object
:nodoc:.
-
#project ⇒ Object
Returns the value of attribute project.
Instance Method Summary collapse
- #create_doc(index_id, document_hash) ⇒ Object
- #delete_doc(index_id, doc_id) ⇒ Object
- #delete_index(index_id) ⇒ Object
- #get_doc(index_id, doc_id) ⇒ Object
-
#initialize(project, credentials) ⇒ Connection
constructor
Creates a new Connection instance.
-
#inspect ⇒ Object
:nodoc:.
- #list_docs(index_id, options = {}) ⇒ Object
- #list_indexes(options = {}) ⇒ Object
- #search(index_id, query, options = {}) ⇒ Object
Constructor Details
#initialize(project, credentials) ⇒ Connection
Creates a new Connection instance.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gcloud/search/connection.rb', line 34 def initialize project, credentials #:nodoc: @project = project @credentials = credentials client_config = { application_name: "gcloud-ruby", application_version: Gcloud::VERSION } @client = Gcloud::Search::APIClient.new client_config @client. = @credentials.client @search = @client.discovered_api "cloudsearch", API_VERSION end |
Instance Attribute Details
#client ⇒ Object
:nodoc:
29 30 31 |
# File 'lib/gcloud/search/connection.rb', line 29 def client @client end |
#connection ⇒ Object
:nodoc:
30 31 32 |
# File 'lib/gcloud/search/connection.rb', line 30 def connection @connection end |
#credentials ⇒ Object
:nodoc:
28 29 30 |
# File 'lib/gcloud/search/connection.rb', line 28 def credentials @credentials end |
#project ⇒ Object
Returns the value of attribute project.
27 28 29 |
# File 'lib/gcloud/search/connection.rb', line 27 def project @project end |
Instance Method Details
#create_doc(index_id, document_hash) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/gcloud/search/connection.rb', line 91 def create_doc index_id, document_hash @client.execute( api_method: @search.documents.create, parameters: { projectId: @project, indexId: index_id }, body_object: document_hash ) end |
#delete_doc(index_id, doc_id) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/gcloud/search/connection.rb', line 100 def delete_doc index_id, doc_id @client.execute( api_method: @search.documents.delete, parameters: { projectId: @project, indexId: index_id, docId: doc_id } ) end |
#delete_index(index_id) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/gcloud/search/connection.rb', line 60 def delete_index index_id @client.execute( api_method: @search.indexes.delete, parameters: { projectId: @project, indexId: index_id } ) end |
#get_doc(index_id, doc_id) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/gcloud/search/connection.rb', line 68 def get_doc index_id, doc_id @client.execute( api_method: @search.documents.get, parameters: { projectId: @project, indexId: index_id, docId: doc_id } ) end |
#inspect ⇒ Object
:nodoc:
123 124 125 |
# File 'lib/gcloud/search/connection.rb', line 123 def inspect #:nodoc: "#{self.class}(#{@project})" end |
#list_docs(index_id, options = {}) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/gcloud/search/connection.rb', line 77 def list_docs index_id, = {} params = { projectId: @project, indexId: index_id, view: ([:view] || "FULL"), pageSize: [:max], pageToken: [:token] }.delete_if { |_, v| v.nil? } @client.execute( api_method: @search.documents.list, parameters: params ) end |
#list_indexes(options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gcloud/search/connection.rb', line 46 def list_indexes = {} params = { projectId: @project, indexNamePrefix: [:prefix], view: ([:view] || "FULL"), pageSize: [:max], pageToken: [:token] }.delete_if { |_, v| v.nil? } @client.execute( api_method: @search.indexes.list, parameters: params ) end |
#search(index_id, query, options = {}) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/gcloud/search/connection.rb', line 109 def search index_id, query, = {} # Always encode expression hashes as JSON strings if [:expressions] # Force to an array of hashes, this works with an array or a hash tmp = [[:expressions]].flatten.map { |ex| JSON.dump ex } [:expressions] = tmp end @client.execute( api_method: @search.indexes.search, parameters: search_request(index_id, query, ) ) end |