Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 73 additions & 35 deletions lib/couchbase/management/scope_search_index_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative "search_index_manager"

module Couchbase
module Management
class ScopeSearchIndexManager
Expand All @@ -31,170 +33,206 @@ def initialize(backend, bucket_name, scope_name)
# Fetches an index from the server if it exists
#
# @param [String] index_name name of the index
# @param [GetIndexOptions] options
# @param [Options::Search::GetIndex] options
#
# @return [SearchIndex]
#
# @raise [ArgumentError]
# @raise [Error::IndexNotFound]
def get_index(index_name, options = GetIndexOptions.new)
def get_index(index_name, options = Options::Search::GetIndex::DEFAULT)
res = @backend.search_index_get(@bucket_name, @scope_name, index_name, options.timeout)
SearchIndexManager.extract_search_index(res)
end

# Fetches all indexes from the server
#
# @param [GetAllIndexesOptions] options
# @param [Options::Search::GetAllIndexes] options
#
# @return [Array<SearchIndex>]
def get_all_indexes(options = GetAllIndexesOptions.new)
def get_all_indexes(options = Options::Search::GetAllIndexes::DEFAULT)
res = @backend.search_index_get_all(@bucket_name, @scope_name, options.timeout)
res[:indexes].map { |idx| SearchIndexManager.extract_search_index(idx) }
end

# Creates or updates the index
#
# @param [SearchIndex] index_definition the index definition
# @param [UpsertIndexOptions] options
# @param [Options::Search::UpsertIndex] options
#
# @return void
#
# @raise [ArgumentError] if name, type or source_type is empty
def upsert_index(index_definition, options = UpsertIndexOptions.new)
def upsert_index(index_definition, options = Options::Search::UpsertIndex::DEFAULT)
@backend.search_index_upsert(@bucket_name, @scope_name, index_definition.to_backend, options.timeout)
end

# Drops the index
#
# @param [String] index_name name of the index
# @param [DropIndexOptions] options
# @param [Options::Search::DropIndex] options
#
# @return void
#
# @raise [ArgumentError]
# @raise [Error::IndexNotFound]
def drop_index(index_name, options = DropIndexOptions.new)
def drop_index(index_name, options = Options::Search::DropIndex::DEFAULT)
@backend.search_index_drop(@bucket_name, @scope_name, index_name, options.timeout)
end

# Retrieves the number of documents that have been indexed for an index
#
# @param [String] index_name name of the index
# @param [GetIndexedDocumentsCountOptions] options
# @param [Options::Search::GetIndexedDocumentsCount] options
#
# @return [Integer]
#
# @raise [ArgumentError]
# @raise [Error::IndexNotFound]
def get_indexed_documents_count(index_name, options = GetIndexedDocumentsCountOptions.new)
def get_indexed_documents_count(index_name, options = Options::Search::GetIndexedDocumentsCount::DEFAULT)
res = @backend.search_index_get_documents_count(@bucket_name, @scope_name, index_name, options.timeout)
res[:count]
end

# Pauses updates and maintenance for the index
#
# @param [String] index_name name of the index
# @param [PauseIngestOptions] options
# @param [Options::Search::PauseIngest] options
#
# @return void
#
# @raise [ArgumentError]
# @raise [Error::IndexNotFound]
def pause_ingest(index_name, options = PauseIngestOptions.new)
def pause_ingest(index_name, options = Options::Search::PauseIngest::DEFAULT)
@backend.search_index_pause_ingest(@bucket_name, @scope_name, index_name, options.timeout)
end

# Resumes updates and maintenance for an index
#
# @param [String] index_name name of the index
# @param [ResumeIngestOptions] options
# @param [Options::Search::ResumeIngest] options
#
# @return void
#
# @raise [ArgumentError]
# @raise [Error::IndexNotFound]
def resume_ingest(index_name, options = ResumeIngestOptions.new)
def resume_ingest(index_name, options = Options::Search::ResumeIngest::DEFAULT)
@backend.search_index_resume_ingest(@bucket_name, @scope_name, index_name, options.timeout)
end

# Allows querying against the index
#
# @param [String] index_name name of the index
# @param [AllowQueryingOptions] options
# @param [Options::Search::AllowQuerying] options
#
# @return void
#
# @raise [ArgumentError]
# @raise [Error::IndexNotFound]
def allow_querying(index_name, options = AllowQueryingOptions.new)
def allow_querying(index_name, options = Options::Search::AllowQuerying::DEFAULT)
@backend.search_index_allow_querying(@bucket_name, @scope_name, index_name, options.timeout)
end

# Disallows querying against the index
#
# @param [String] index_name name of the index
# @param [DisallowQueryingOptions] options
# @param [Options::Search::DisallowQuerying] options
#
# @return void
#
# @raise [ArgumentError]
# @raise [Error::IndexNotFound]
def disallow_querying(index_name, options = DisallowQueryingOptions.new)
def disallow_querying(index_name, options = Options::Search::DisallowQuerying::DEFAULT)
@backend.search_index_disallow_querying(@bucket_name, @scope_name, index_name, options.timeout)
end

# Freeze the assignment of index partitions to nodes
#
# @param [String] index_name name of the index
# @param [FreezePlanOptions] options
# @param [Options::Search::FreezePlan] options
#
# @return void
#
# @raise [ArgumentError]
# @raise [Error::IndexNotFound]
def freeze_plan(index_name, options = FreezePlanOptions.new)
def freeze_plan(index_name, options = Options::Search::FreezePlan::DEFAULT)
@backend.search_index_freeze_plan(@bucket_name, @scope_name, index_name, options.timeout)
end

# Unfreeze the assignment of index partitions to nodes
#
# @param [String] index_name name of the index
# @param [UnfreezePlanOptions] options
# @param [Options::Search::UnfreezePlan] options
#
# @return void
#
# @raise [ArgumentError]
# @raise [Error::IndexNotFound]
def unfreeze_plan(index_name, options = UnfreezePlanOptions.new)
def unfreeze_plan(index_name, options = Options::Search::UnfreezePlan::DEFAULT)
@backend.search_index_unfreeze_plan(@bucket_name, @scope_name, index_name, options.timeout)
end

# Allows to see how a document is analyzed against a specific index
#
# @param [String] index_name name of the index
# @param [Hash] document the document to be analyzed
# @param [Options::Search::AnalyzeDocument] options
#
# @return [Array<Hash>]
#
# @raise [ArgumentError]
# @raise [Error::IndexNotFound]
def analyze_document(index_name, document, options = AnalyzeDocumentOptions.new)
def analyze_document(index_name, document, options = Options::Search::AnalyzeDocument::DEFAULT)
res = @backend.search_index_analyze_document(@bucket_name, @scope_name, index_name, JSON.generate(document), options.timeout)
JSON.parse(res[:analysis])
end

GetIndexOptions = SearchIndexManager::GetIndexOptions
GetAllIndexesOptions = SearchIndexManager::GetAllIndexesOptions
UpsertIndexOptions = SearchIndexManager::UpsertIndexOptions
DropIndexOptions = SearchIndexManager::DropIndexOptions
GetIndexedDocumentsCountOptions = SearchIndexManager::GetIndexedDocumentsCountOptions
PauseIngestOptions = SearchIndexManager::PauseIngestOptions
ResumeIngestOptions = SearchIndexManager::ResumeIngestOptions
AllowQueryingOptions = SearchIndexManager::AllowQueryingOptions
DisallowQueryingOptions = SearchIndexManager::DisallowQueryingOptions
FreezePlanOptions = SearchIndexManager::FreezePlanOptions
UnfreezePlanOptions = SearchIndexManager::UnfreezePlanOptions
AnalyzeDocumentOptions = SearchIndexManager::AnalyzeDocumentOptions
# @api private
# @deprecated use {Options::Search::GetIndex} instead
GetIndexOptions = Options::Search::GetIndex

# @api private
# @deprecated use {Options::Search::GetAllIndexes} instead
GetAllIndexesOptions = Options::Search::GetAllIndexes

# @api private
# @deprecated use {Options::Search::UpsertIndex} instead
UpsertIndexOptions = Options::Search::UpsertIndex

# @api private
# @deprecated use {Options::Search::DropIndex} instead
DropIndexOptions = Options::Search::DropIndex

# @api private
# @deprecated use {Options::Search::GetIndexedDocumentsCount} instead
GetIndexedDocumentsCountOptions = Options::Search::GetIndexedDocumentsCount

# @api private
# @deprecated use {Options::Search::PauseIngest} instead
PauseIngestOptions = Options::Search::PauseIngest

# @api private
# @deprecated use {Options::Search::ResumeIngest} instead
ResumeIngestOptions = Options::Search::ResumeIngest

# @api private
# @deprecated use {Options::Search::AllowQuerying} instead
AllowQueryingOptions = Options::Search::AllowQuerying

# @api private
# @deprecated use {Options::Search::DisallowQuerying} instead
DisallowQueryingOptions = Options::Search::DisallowQuerying

# @api private
# @deprecated use {Options::Search::FreezePlan} instead
FreezePlanOptions = Options::Search::FreezePlan

# @api private
# @deprecated use {Options::Search::UnfreezePlan} instead
UnfreezePlanOptions = Options::Search::UnfreezePlan

# @api private
# @deprecated use {Options::Search::AnalyzeDocument} instead
AnalyzeDocumentOptions = Options::Search::AnalyzeDocument
end
end
end
Loading
Loading