Class: Couchbase::Management::SearchIndexManager

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/management/search_index_manager.rb

Constant Summary collapse

GetIndexOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Deprecated.
Options::Search::GetIndex
GetAllIndexesOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Deprecated.
Options::Search::GetAllIndexes
UpsertIndexOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Deprecated.
Options::Search::UpsertIndex
DropIndexOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Deprecated.
Options::Search::DropIndex
GetIndexedDocumentsCountOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Options::Search::GetIndexedDocumentsCount
GetIndexStatsOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Deprecated.
Options::Search::GetIndexStats
PauseIngestOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Deprecated.
Options::Search::PauseIngest
ResumeIngestOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Deprecated.
Options::Search::ResumeIngest
AllowQueryingOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Deprecated.
Options::Search::AllowQuerying
DisallowQueryingOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Deprecated.
Options::Search::DisallowQuerying
FreezePlanOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Deprecated.
Options::Search::FreezePlan
UnfreezePlanOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Deprecated.
Options::Search::UnfreezePlan
AnalyzeDocumentOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Deprecated.
Options::Search::AnalyzeDocument

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend, observability) ⇒ SearchIndexManager

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of SearchIndexManager.

Parameters:



293
294
295
296
# File 'lib/couchbase/management/search_index_manager.rb', line 293

def initialize(backend, observability)
  @backend = backend
  @observability = observability
end

Class Method Details

.extract_search_index(resp) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/couchbase/management/search_index_manager.rb', line 583

def self.extract_search_index(resp)
  SearchIndex.new do |index|
    index.name = resp[:name]
    index.type = resp[:type]
    index.uuid = resp[:uuid]
    index.params = resp[:params] ? JSON.parse(resp[:params]) : {}
    index.source_name = resp[:source_name]
    index.source_type = resp[:source_type]
    index.source_uuid = resp[:source_uuid]
    index.source_params = resp[:source_params] ? JSON.parse(resp[:source_params]) : {}
    index.plan_params = resp[:plan_params] ? JSON.parse(resp[:plan_params]) : {}
  end
end

Instance Method Details

#allow_querying(index_name, options = Options::Search::AllowQuerying::DEFAULT) ⇒ Object

Allows querying against the index

Parameters:

Returns:

  • void

Raises:



462
463
464
465
466
# File 'lib/couchbase/management/search_index_manager.rb', line 462

def allow_querying(index_name, options = Options::Search::AllowQuerying::DEFAULT)
  @observability.record_operation(Observability::OP_SM_ALLOW_QUERYING, options.parent_span, self, :search) do |obs_handler|
    @backend.search_index_allow_querying(nil, nil, index_name, options.timeout, obs_handler)
  end
end

#analyze_document(index_name, document, options = Options::Search::AnalyzeDocument::DEFAULT) ⇒ Array<Hash>

Allows to see how a document is analyzed against a specific index

Parameters:

  • index_name (String)

    name of the index

  • document (Hash)

    the document to be analyzed

  • options (Options::Search::AnalyzeDocument) (defaults to: Options::Search::AnalyzeDocument::DEFAULT)

Returns:

  • (Array<Hash>)

Raises:



523
524
525
526
527
528
# File 'lib/couchbase/management/search_index_manager.rb', line 523

def analyze_document(index_name, document, options = Options::Search::AnalyzeDocument::DEFAULT)
  @observability.record_operation(Observability::OP_SM_ANALYZE_DOCUMENT, options.parent_span, self, :search) do |obs_handler|
    res = @backend.search_index_analyze_document(nil, nil, index_name, JSON.generate(document), options.timeout, obs_handler)
    JSON.parse(res[:analysis])
  end
end

#disallow_querying(index_name, options = Options::Search::DisallowQuerying::DEFAULT) ⇒ Object

Disallows querying against the index

Parameters:

Returns:

  • void

Raises:



477
478
479
480
481
# File 'lib/couchbase/management/search_index_manager.rb', line 477

def disallow_querying(index_name, options = Options::Search::DisallowQuerying::DEFAULT)
  @observability.record_operation(Observability::OP_SM_DISALLOW_QUERYING, options.parent_span, self, :search) do |obs_handler|
    @backend.search_index_disallow_querying(nil, nil, index_name, options.timeout, obs_handler)
  end
end

#drop_index(index_name, options = Options::Search::DropIndex::DEFAULT) ⇒ Object

Drops the index

Parameters:

  • index_name (String)

    name of the index

  • options (Options::Search::DropIndex) (defaults to: Options::Search::DropIndex::DEFAULT)

Returns:

  • void

Raises:



365
366
367
368
369
# File 'lib/couchbase/management/search_index_manager.rb', line 365

def drop_index(index_name, options = Options::Search::DropIndex::DEFAULT)
  @observability.record_operation(Observability::OP_SM_DROP_INDEX, options.parent_span, self, :search) do |obs_handler|
    @backend.search_index_drop(nil, nil, index_name, options.timeout, obs_handler)
  end
end

#freeze_plan(index_name, options = Options::Search::FreezePlan::DEFAULT) ⇒ Object

Freeze the assignment of index partitions to nodes

Parameters:

Returns:

  • void

Raises:



492
493
494
495
496
# File 'lib/couchbase/management/search_index_manager.rb', line 492

def freeze_plan(index_name, options = Options::Search::FreezePlan::DEFAULT)
  @observability.record_operation(Observability::OP_SM_FREEZE_PLAN, options.parent_span, self, :search) do |obs_handler|
    @backend.search_index_freeze_plan(nil, nil, index_name, options.timeout, obs_handler)
  end
end

#get_all_indexes(options = Options::Search::GetAllIndexes::DEFAULT) ⇒ Array<SearchIndex>

Fetches all indexes from the server

Parameters:

Returns:



319
320
321
322
323
324
# File 'lib/couchbase/management/search_index_manager.rb', line 319

def get_all_indexes(options = Options::Search::GetAllIndexes::DEFAULT)
  @observability.record_operation(Observability::OP_SM_GET_ALL_INDEXES, options.parent_span, self, :search) do |obs_handler|
    res = @backend.search_index_get_all(nil, nil, options.timeout, obs_handler)
    res[:indexes].map { |idx| self.class.extract_search_index(idx) }
  end
end

#get_index(index_name, options = Options::Search::GetIndex::DEFAULT) ⇒ SearchIndex

Fetches an index from the server if it exists

Parameters:

  • index_name (String)

    name of the index

  • options (Options::Search::GetIndex) (defaults to: Options::Search::GetIndex::DEFAULT)

Returns:

Raises:



307
308
309
310
311
312
# File 'lib/couchbase/management/search_index_manager.rb', line 307

def get_index(index_name, options = Options::Search::GetIndex::DEFAULT)
  @observability.record_operation(Observability::OP_SM_GET_INDEX, options.parent_span, self, :search) do |obs_handler|
    res = @backend.search_index_get(nil, nil, index_name, options.timeout, obs_handler)
    self.class.extract_search_index(res)
  end
end

#get_index_stats(index_name, options = Options::Search::GetIndexStats::DEFAULT) ⇒ Integer

Retrieves metrics, timings and counters for a given index

Parameters:

Returns:

  • (Integer)

Raises:



399
400
401
402
403
404
# File 'lib/couchbase/management/search_index_manager.rb', line 399

def get_index_stats(index_name, options = Options::Search::GetIndexStats::DEFAULT)
  @observability.record_operation(Observability::OP_SM_GET_INDEX_STATS, options.parent_span, self, :search) do |obs_handler|
    res = @backend.search_index_get_stats(index_name, options.timeout, obs_handler)
    JSON.parse(res)
  end
end

#get_indexed_documents_count(index_name, options = Options::Search::GetIndexedDocumentsCount::DEFAULT) ⇒ Integer

Retrieves the number of documents that have been indexed for an index

Parameters:

Returns:

  • (Integer)

Raises:



380
381
382
383
384
385
386
# File 'lib/couchbase/management/search_index_manager.rb', line 380

def get_indexed_documents_count(index_name, options = Options::Search::GetIndexedDocumentsCount::DEFAULT)
  @observability.record_operation(Observability::OP_SM_GET_INDEXED_DOCUMENTS_COUNT, options.parent_span, self,
                                  :search) do |obs_handler|
    res = @backend.search_index_get_documents_count(nil, nil, index_name, options.timeout, obs_handler)
    res[:count]
  end
end

#get_stats(options = Options::Search::GetIndexStats::DEFAULT) ⇒ Integer

Retrieves statistics on search service. Information is provided on documents, partition indexes, mutations, compactions, queries, and more.

Parameters:

Returns:

  • (Integer)

Raises:

  • (ArgumentError)


416
417
418
419
420
421
# File 'lib/couchbase/management/search_index_manager.rb', line 416

def get_stats(options = Options::Search::GetIndexStats::DEFAULT)
  @observability.record_operation(Observability::OP_SM_GET_STATS, options.parent_span, self, :search) do |obs_handler|
    res = @backend.search_get_stats(options.timeout, obs_handler)
    JSON.parse(res)
  end
end

#pause_ingest(index_name, options = Options::Search::PauseIngest::DEFAULT) ⇒ Object

Pauses updates and maintenance for the index

Parameters:

Returns:

  • void

Raises:



432
433
434
435
436
# File 'lib/couchbase/management/search_index_manager.rb', line 432

def pause_ingest(index_name, options = Options::Search::PauseIngest::DEFAULT)
  @observability.record_operation(Observability::OP_SM_PAUSE_INGEST, options.parent_span, self, :search) do |obs_handler|
    @backend.search_index_pause_ingest(nil, nil, index_name, options.timeout, obs_handler)
  end
end

#resume_ingest(index_name, options = Options::Search::ResumeIngest::DEFAULT) ⇒ Object

Resumes updates and maintenance for an index

Parameters:

Returns:

  • void

Raises:



447
448
449
450
451
# File 'lib/couchbase/management/search_index_manager.rb', line 447

def resume_ingest(index_name, options = Options::Search::ResumeIngest::DEFAULT)
  @observability.record_operation(Observability::OP_SM_RESUME_INGEST, options.parent_span, self, :search) do |obs_handler|
    @backend.search_index_resume_ingest(nil, nil, index_name, options.timeout, obs_handler)
  end
end

#unfreeze_plan(index_name, options = Options::Search::UnfreezePlan::DEFAULT) ⇒ Object

Unfreeze the assignment of index partitions to nodes

Parameters:

Returns:

  • void

Raises:



507
508
509
510
511
# File 'lib/couchbase/management/search_index_manager.rb', line 507

def unfreeze_plan(index_name, options = Options::Search::UnfreezePlan::DEFAULT)
  @observability.record_operation(Observability::OP_SM_UNFREEZE_PLAN, options.parent_span, self, :search) do |obs_handler|
    @backend.search_index_unfreeze_plan(nil, nil, index_name, options.timeout, obs_handler)
  end
end

#upsert_index(index_definition, options = Options::Search::UpsertIndex::DEFAULT) ⇒ Object

Creates or updates the index

Parameters:

Returns:

  • void

Raises:

  • (ArgumentError)

    if name, type or source_type is empty



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/couchbase/management/search_index_manager.rb', line 334

def upsert_index(index_definition, options = Options::Search::UpsertIndex::DEFAULT)
  @observability.record_operation(Observability::OP_SM_UPSERT_INDEX, options.parent_span, self, :search) do |obs_handler|
    @backend.search_index_upsert(
      nil,
      nil,
      {
        name: index_definition.name,
        type: index_definition.type,
        uuid: index_definition.uuid,
        params: (JSON.generate(index_definition.params) if index_definition.params),
        source_name: index_definition.source_name,
        source_type: index_definition.source_type,
        source_uuid: index_definition.source_uuid,
        source_params: (JSON.generate(index_definition.source_params) if index_definition.source_params),
        plan_params: (JSON.generate(index_definition.plan_params) if index_definition.plan_params),
      },
      options.timeout,
      obs_handler,
    )
  end
end