Module: Swiftype::Client::Document
- Included in:
- Swiftype::Client
- Defined in:
- lib/swiftype/client.rb
Overview
Documents have fields that can be searched or filtered.
For more information on indexing documents, see the REST API indexing documentation.
Instance Method Summary collapse
- #async_create_or_update_documents(engine_id, document_type_id, documents = []) ⇒ Object
- #create_document(engine_id, document_type_id, document = {}) ⇒ Object
- #create_documents(engine_id, document_type_id, documents = []) ⇒ Object
- #create_or_update_document(engine_id, document_type_id, document = {}) ⇒ Object
- #create_or_update_documents(engine_id, document_type_id, documents = []) ⇒ Object
- #create_or_update_documents_verbose(engine_id, document_type_id, documents = []) ⇒ Object
- #destroy_document(engine_id, document_type_id, document_id) ⇒ Object
- #destroy_documents(engine_id, document_type_id, document_ids = []) ⇒ Object
- #document(engine_id, document_type_id, document_id) ⇒ Object
-
#document_receipts(receipt_ids) ⇒ Array<Hash>
Retrieve Document Receipts from the API by ID.
- #documents(engine_id, document_type_id, page = nil, per_page = nil) ⇒ Object
-
#index_documents(engine_id, document_type_id, documents = [], options = {}) ⇒ Array<Hash>
Index a batch of documents using the asynchronous API.
- #update_document(engine_id, document_type_id, document_id, fields) ⇒ Object
- #update_documents(engine_id, document_type_id, documents = {}) ⇒ Object
Instance Method Details
#async_create_or_update_documents(engine_id, document_type_id, documents = []) ⇒ Object
339 340 341 |
# File 'lib/swiftype/client.rb', line 339 def async_create_or_update_documents(engine_id, document_type_id, documents=[]) post("engines/#{engine_id}/document_types/#{document_type_id}/documents/async_bulk_create_or_update.json", :documents => documents) end |
#create_document(engine_id, document_type_id, document = {}) ⇒ Object
303 304 305 |
# File 'lib/swiftype/client.rb', line 303 def create_document(engine_id, document_type_id, document={}) post("engines/#{engine_id}/document_types/#{document_type_id}/documents.json", :document => document) end |
#create_documents(engine_id, document_type_id, documents = []) ⇒ Object
307 308 309 |
# File 'lib/swiftype/client.rb', line 307 def create_documents(engine_id, document_type_id, documents=[]) post("engines/#{engine_id}/document_types/#{document_type_id}/documents/bulk_create.json", :documents => documents) end |
#create_or_update_document(engine_id, document_type_id, document = {}) ⇒ Object
319 320 321 |
# File 'lib/swiftype/client.rb', line 319 def create_or_update_document(engine_id, document_type_id, document={}) post("engines/#{engine_id}/document_types/#{document_type_id}/documents/create_or_update.json", :document => document) end |
#create_or_update_documents(engine_id, document_type_id, documents = []) ⇒ Object
323 324 325 |
# File 'lib/swiftype/client.rb', line 323 def create_or_update_documents(engine_id, document_type_id, documents=[]) post("engines/#{engine_id}/document_types/#{document_type_id}/documents/bulk_create_or_update.json", :documents => documents) end |
#create_or_update_documents_verbose(engine_id, document_type_id, documents = []) ⇒ Object
327 328 329 |
# File 'lib/swiftype/client.rb', line 327 def create_or_update_documents_verbose(engine_id, document_type_id, documents=[]) post("engines/#{engine_id}/document_types/#{document_type_id}/documents/bulk_create_or_update_verbose.json", :documents => documents) end |
#destroy_document(engine_id, document_type_id, document_id) ⇒ Object
311 312 313 |
# File 'lib/swiftype/client.rb', line 311 def destroy_document(engine_id, document_type_id, document_id) delete("engines/#{engine_id}/document_types/#{document_type_id}/documents/#{document_id}.json") end |
#destroy_documents(engine_id, document_type_id, document_ids = []) ⇒ Object
315 316 317 |
# File 'lib/swiftype/client.rb', line 315 def destroy_documents(engine_id, document_type_id, document_ids=[]) post("engines/#{engine_id}/document_types/#{document_type_id}/documents/bulk_destroy.json", :documents => document_ids) end |
#document(engine_id, document_type_id, document_id) ⇒ Object
299 300 301 |
# File 'lib/swiftype/client.rb', line 299 def document(engine_id, document_type_id, document_id) get("engines/#{engine_id}/document_types/#{document_type_id}/documents/#{document_id}.json") end |
#document_receipts(receipt_ids) ⇒ Array<Hash>
Retrieve Document Receipts from the API by ID
348 349 350 |
# File 'lib/swiftype/client.rb', line 348 def document_receipts(receipt_ids) post("document_receipts.json", :ids => receipt_ids) end |
#documents(engine_id, document_type_id, page = nil, per_page = nil) ⇒ Object
292 293 294 295 296 297 |
# File 'lib/swiftype/client.rb', line 292 def documents(engine_id, document_type_id, page=nil, per_page=nil) = {} [:page] = page if page [:per_page] = per_page if per_page get("engines/#{engine_id}/document_types/#{document_type_id}/documents.json", ) end |
#index_documents(engine_id, document_type_id, documents = [], options = {}) ⇒ Array<Hash>
Index a batch of documents using the asynchronous API. This is a good choice if you have a large number of documents.
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/swiftype/client.rb', line 366 def index_documents(engine_id, document_type_id, documents = [], = {}) documents = wrap(documents) res = async_create_or_update_documents(engine_id, document_type_id, documents) if [:async] res else receipt_ids = res["document_receipts"].map { |a| a["id"] } poll() do receipts = document_receipts(receipt_ids) flag = receipts.all? { |a| a["status"] != "pending" } flag ? receipts : false end end end |
#update_document(engine_id, document_type_id, document_id, fields) ⇒ Object
331 332 333 |
# File 'lib/swiftype/client.rb', line 331 def update_document(engine_id, document_type_id, document_id, fields) put("engines/#{engine_id}/document_types/#{document_type_id}/documents/#{document_id}/update_fields.json", { :fields => fields }) end |
#update_documents(engine_id, document_type_id, documents = {}) ⇒ Object
335 336 337 |
# File 'lib/swiftype/client.rb', line 335 def update_documents(engine_id, document_type_id, documents={}) put("engines/#{engine_id}/document_types/#{document_type_id}/documents/bulk_update.json", { :documents => documents }) end |