Class: Couchbase::Management::SearchIndexManager

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

Defined Under Namespace

Classes: AllowQueryingOptions, AnalyzeDocumentOptions, DisallowQueryingOptions, DropIndexOptions, FreezePlanOptions, GetAllIndexesOptions, GetIndexOptions, GetIndexStatsOptions, GetIndexedDocumentsCountOptions, PauseIngestOptions, ResumeIngestOptions, UnfreezePlanOptions, UpsertIndexOptions

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend) ⇒ SearchIndexManager

Returns a new instance of SearchIndexManager.

Parameters:



23
24
25
# File 'lib/couchbase/management/search_index_manager.rb', line 23

def initialize(backend)
  @backend = backend
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.



358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/couchbase/management/search_index_manager.rb', line 358

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 = AllowQueryingOptions.new) ⇒ Object

Allows querying against the index

Parameters:

  • index_name (String)

    name of the index

  • options (AllowQueryingOptions) (defaults to: AllowQueryingOptions.new)

Returns:

  • void

Raises:



170
171
172
# File 'lib/couchbase/management/search_index_manager.rb', line 170

def allow_querying(index_name, options = AllowQueryingOptions.new)
  @backend.search_index_allow_querying(nil, nil, index_name, options.timeout)
end

#analyze_document(index_name, document, options = AnalyzeDocumentOptions.new) ⇒ 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

Returns:

  • (Array<Hash>)

Raises:



222
223
224
225
# File 'lib/couchbase/management/search_index_manager.rb', line 222

def analyze_document(index_name, document, options = AnalyzeDocumentOptions.new)
  res = @backend.search_index_analyze_document(nil, nil, index_name, JSON.generate(document), options.timeout)
  JSON.parse(res[:analysis])
end

#disallow_querying(index_name, options = DisallowQueryingOptions.new) ⇒ Object

Disallows querying against the index

Parameters:

  • index_name (String)

    name of the index

  • options (DisallowQueryingOptions) (defaults to: DisallowQueryingOptions.new)

Returns:

  • void

Raises:



183
184
185
# File 'lib/couchbase/management/search_index_manager.rb', line 183

def disallow_querying(index_name, options = DisallowQueryingOptions.new)
  @backend.search_index_disallow_querying(nil, nil, index_name, options.timeout)
end

#drop_index(index_name, options = DropIndexOptions.new) ⇒ Object

Drops the index

Parameters:

  • index_name (String)

    name of the index

  • options (DropIndexOptions) (defaults to: DropIndexOptions.new)

Returns:

  • void

Raises:



86
87
88
# File 'lib/couchbase/management/search_index_manager.rb', line 86

def drop_index(index_name, options = DropIndexOptions.new)
  @backend.search_index_drop(nil, nil, index_name, options.timeout)
end

#freeze_plan(index_name, options = FreezePlanOptions.new) ⇒ Object

Freeze the assignment of index partitions to nodes

Parameters:

  • index_name (String)

    name of the index

  • options (FreezePlanOptions) (defaults to: FreezePlanOptions.new)

Returns:

  • void

Raises:



196
197
198
# File 'lib/couchbase/management/search_index_manager.rb', line 196

def freeze_plan(index_name, options = FreezePlanOptions.new)
  @backend.search_index_freeze_plan(nil, nil, index_name, options.timeout)
end

#get_all_indexes(options = GetAllIndexesOptions.new) ⇒ Array<SearchIndex>

Fetches all indexes from the server

Parameters:

Returns:



46
47
48
49
# File 'lib/couchbase/management/search_index_manager.rb', line 46

def get_all_indexes(options = GetAllIndexesOptions.new)
  res = @backend.search_index_get_all(nil, nil, options.timeout)
  res[:indexes].map { |idx| self.class.extract_search_index(idx) }
end

#get_index(index_name, options = GetIndexOptions.new) ⇒ SearchIndex

Fetches an index from the server if it exists

Parameters:

  • index_name (String)

    name of the index

  • options (GetIndexOptions) (defaults to: GetIndexOptions.new)

Returns:

Raises:



36
37
38
39
# File 'lib/couchbase/management/search_index_manager.rb', line 36

def get_index(index_name, options = GetIndexOptions.new)
  res = @backend.search_index_get(nil, nil, index_name, options.timeout)
  self.class.extract_search_index(res)
end

#get_index_stats(index_name, options = GetIndexStatsOptions.new) ⇒ Integer

Retrieves metrics, timings and counters for a given index

Parameters:

  • index_name (String)

    name of the index

  • options (GetIndexStatsOptions) (defaults to: GetIndexStatsOptions.new)

Returns:

  • (Integer)

Raises:



115
116
117
118
# File 'lib/couchbase/management/search_index_manager.rb', line 115

def get_index_stats(index_name, options = GetIndexStatsOptions.new)
  res = @backend.search_index_get_stats(index_name, options.timeout)
  JSON.parse(res)
end

#get_indexed_documents_count(index_name, options = GetIndexedDocumentsCountOptions.new) ⇒ Integer

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

Parameters:

Returns:

  • (Integer)

Raises:



99
100
101
102
# File 'lib/couchbase/management/search_index_manager.rb', line 99

def get_indexed_documents_count(index_name, options = GetIndexedDocumentsCountOptions.new)
  res = @backend.search_index_get_documents_count(nil, nil, index_name, options.timeout)
  res[:count]
end

#get_stats(options = GetIndexStatsOptions.new) ⇒ Integer

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

Parameters:

Returns:

  • (Integer)

Raises:

  • (ArgumentError)


130
131
132
133
# File 'lib/couchbase/management/search_index_manager.rb', line 130

def get_stats(options = GetIndexStatsOptions.new)
  res = @backend.search_get_stats(options.timeout)
  JSON.parse(res)
end

#pause_ingest(index_name, options = PauseIngestOptions.new) ⇒ Object

Pauses updates and maintenance for the index

Parameters:

  • index_name (String)

    name of the index

  • options (PauseIngestOptions) (defaults to: PauseIngestOptions.new)

Returns:

  • void

Raises:



144
145
146
# File 'lib/couchbase/management/search_index_manager.rb', line 144

def pause_ingest(index_name, options = PauseIngestOptions.new)
  @backend.search_index_pause_ingest(nil, nil, index_name, options.timeout)
end

#resume_ingest(index_name, options = ResumeIngestOptions.new) ⇒ Object

Resumes updates and maintenance for an index

Parameters:

  • index_name (String)

    name of the index

  • options (ResumeIngestOptions) (defaults to: ResumeIngestOptions.new)

Returns:

  • void

Raises:



157
158
159
# File 'lib/couchbase/management/search_index_manager.rb', line 157

def resume_ingest(index_name, options = ResumeIngestOptions.new)
  @backend.search_index_resume_ingest(nil, nil, index_name, options.timeout)
end

#unfreeze_plan(index_name, options = UnfreezePlanOptions.new) ⇒ Object

Unfreeze the assignment of index partitions to nodes

Parameters:

  • index_name (String)

    name of the index

  • options (UnfreezePlanOptions) (defaults to: UnfreezePlanOptions.new)

Returns:

  • void

Raises:



209
210
211
# File 'lib/couchbase/management/search_index_manager.rb', line 209

def unfreeze_plan(index_name, options = UnfreezePlanOptions.new)
  @backend.search_index_unfreeze_plan(nil, nil, index_name, options.timeout)
end

#upsert_index(index_definition, options = UpsertIndexOptions.new) ⇒ Object

Creates or updates the index

Parameters:

Returns:

  • void

Raises:

  • (ArgumentError)

    if name, type or source_type is empty



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/couchbase/management/search_index_manager.rb', line 59

def upsert_index(index_definition, options = UpsertIndexOptions.new)
  @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
  )
end