Module: SwiftypeEnterprise::Client::ContentSourceDocuments

Included in:
SwiftypeEnterprise::Client
Defined in:
lib/swiftype-enterprise/client.rb

Overview

Documents have fields that can be searched or filtered.

For more information on indexing documents, see the Content Source documentation.

Constant Summary collapse

REQUIRED_TOP_LEVEL_KEYS =
[
  'external_id',
  'url',
  'title',
  'body'
].map!(&:freeze).to_set.freeze
OPTIONAL_TOP_LEVEL_KEYS =
[
  'created_at',
  'updated_at',
  'type',
].map!(&:freeze).to_set.freeze
CORE_TOP_LEVEL_KEYS =
(REQUIRED_TOP_LEVEL_KEYS + OPTIONAL_TOP_LEVEL_KEYS).freeze

Instance Method Summary collapse

Instance Method Details

#destroy_documents(content_source_key, document_ids) ⇒ Array<Hash>

Destroy a batch of documents given a list of external IDs

Parameters:

  • document_ids (Array<String>)

    an Array of Document External IDs

Returns:

  • (Array<Hash>)

    an Array of Document destroy result hashes

Raises:

  • (Timeout::Error)

    when timeout expires waiting for results



79
80
81
82
# File 'lib/swiftype-enterprise/client.rb', line 79

def destroy_documents(content_source_key, document_ids)
  document_ids = Array(document_ids)
  post("ent/sources/#{content_source_key}/documents/bulk_destroy.json", document_ids)
end

#index_documents(content_source_key, documents) ⇒ Array<Hash>

Index a batch of documents using the Content Source API.

Parameters:

  • content_source_key (String)

    the unique Content Source key as found in your Content Sources dashboard

  • documents (Array)

    an Array of Document Hashes

Returns:

  • (Array<Hash>)

    an Array of Document indexing Results

Raises:

  • (SwiftypeEnterprise::InvalidDocument)

    when a single document is missing required fields or contains unsupported fields

  • (Timeout::Error)

    when timeout expires waiting for results



66
67
68
69
70
# File 'lib/swiftype-enterprise/client.rb', line 66

def index_documents(content_source_key, documents)
  documents = Array(documents).map! { |document| validate_and_normalize_document(document) }

  async_create_or_update_documents(content_source_key, documents)
end