类:Mongo::SearchIndex::View
Overview
表示搜索索引视图的类。
实例属性摘要折叠
-
#aggregate_options ⇒ Hash
只读
查询可用索引时用于聚合命令的选项哈希。
-
# 集合 ⇒ Mongo::Collection
只读
此视图所属的集合。
-
# requests_index_id ⇒ nil |字符串
只读
要查询的索引ID 。
-
# requests_index_name ⇒ nil |字符串
只读
要查询的索引名称。
实例方法摘要折叠
-
# create_many (indexes) ⇒ Array<String>
使用单个命令创建多个搜索索引。
-
# create_one (definition, name: nil, type: ' 搜索') ⇒ 字符串
使用给定定义创建单个搜索索引。
-
# drop_one (ID: nil, name: nil) ⇒ Mongo::Operation::Result | false
删除具有给定 ID 或名称的搜索索引。
-
#each (&block) ⇒ self |枚举器
遍历搜索索引。
-
#为空? ⇒ true | false
查询搜索索引可枚举项是否为空。
-
#initialize (集合, options = {}) ⇒ 查看
构造函数
创建新的搜索索引视图。
-
# update_one (definition, ID: nil, name: nil) ⇒ Mongo::Operation::Result
使用给定 ID 或名称更新搜索索引。
Collection::Helpers 中包含的方法
Retryable 中包含的方法
#read_worker、#select_server、#with_overload_retry、#write_worker
构造函数详情
#initialize (集合, options = {}) ⇒查看
创建新的搜索索引视图。
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ Mongo/search_index/view.rb', line 36 def 初始化(集合, = {}) @collection = 集合 @requested_index_id = [:id] @requested_index_name = [:name] @aggregate_options = [:aggregate] || {} return if @aggregate_options.is_a?(哈希) 提高 ArgumentError, " :aggregate 选项必须是哈希(有 #{ @aggregate_options . class } ) " end |
实例属性详细信息
#aggregate_options ⇒ 哈希(只读)
在查询可用索引时,返回用于聚合命令的选项哈希。
23 24 25 |
# File 'lib/ Mongo/search_index/view.rb', line 23 def @aggregate_options end |
# 集合 ⇒ Mongo::Collection (只读)
返回此视图所属的集合。
13 14 15 |
# File 'lib/ Mongo/search_index/view.rb', line 13 def 集合 @collection end |
# requests_index_id ⇒ nil |字符串(只读)
返回要查询的索引ID 。
16 17 18 |
# File 'lib/ Mongo/search_index/view.rb', line 16 def requests_index_id @requested_index_id end |
# requests_index_name ⇒ nil |字符串(只读)
返回要查询的索引名称。
19 20 21 |
# File 'lib/ Mongo/search_index/view.rb', line 19 def requests_index_name @requested_index_name end |
实例方法详细信息
# create_many (indexes) ⇒ Array<String>
使用单个命令创建多个搜索索引。
71 72 73 74 75 76 77 78 79 |
# File 'lib/ Mongo/search_index/view.rb', line 71 def create_many(索引) spec = spec_with(索引: 索引.map { |v| validate_search_index!(v) }) 操作 = 操作::创建搜索索引.new(spec) 上下文 = execution_context 追踪器.trace_operation(操作, 上下文, op_name: 'createSearchIndexes') do 结果 = 操作.执行(next_primary, 上下文: 上下文) 结果.first['indexesCreated'].map { |idx| idx[' name '] } end end |
# create_one (definition, name: nil, type: ' 搜索') ⇒ 字符串
使用给定定义创建单个搜索索引。 如果提供了名称,则会为新索引指定该名称。
56 57 58 59 60 61 |
# File 'lib/ Mongo/search_index/view.rb', line 56 def create_one(定义, 名称: nil, 类型: ' 搜索 ') spec = { 定义: 定义, 类型: 类型 }.点击 do |sp| sp[:name] = 名称 除非 名称.nil? end create_many([ spec ]).first end |
# drop_one (ID: nil, name: nil) ⇒ Mongo::Operation::Result | false
删除具有给定 ID 或名称的搜索索引。 必须指定其中之一,但不能同时指定两者。
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ Mongo/search_index/view.rb', line 89 def drop_one(ID : nil, 名称: nil) validate_id_or_name!(id, 名称) spec = spec_with(index_id: id, index_name: 名称) op = 操作::DropSearchIndex.new(spec) 上下文 = execution_context 追踪器.trace_operation(op, 上下文, op_name: 'dropSearchIndex') do # 根据规范: # 驱动程序必须抑制 NamespaceNotFound 错误 # ``dropSearchIndex`` 助手。 删除操作应该是幂等的。 do_drop(op, nil, 上下文) end end |
#each (&block) ⇒ self |枚举器
遍历搜索索引。
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ Mongo/search_index/view.rb', line 111 def 每(和块) @result ||= 开始 spec = {}.点击 do |s| s[:id] = requests_index_id if requests_index_id s[:name] = requests_index_name if requests_index_name end 集合.通过(read_concern: {}).聚合( [ { '$listSearchIndexes' => spec } ], ) end return @result.to_enum 除非 块 @result.每(和块) self end |
#为空? ⇒ true | false
查询搜索索引可枚举项是否为空。
156 157 158 |
# File 'lib/ Mongo/search_index/view.rb', line 156 def 空? 数数.zero? end |
# update_one (definition, ID: nil, name: nil) ⇒ Mongo::Operation::Result
使用给定 ID 或名称更新搜索索引。 必须提供其中之一,但不能同时提供。
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ Mongo/search_index/view.rb', line 139 def update_one(定义, ID : nil, 名称: nil) validate_id_or_name!(id, 名称) spec = spec_with(index_id: id, index_name: 名称, index: 定义) op = 操作::updateSearchIndex.new(spec) 上下文 = execution_context 追踪器.trace_operation(op, 上下文, op_name: 'updateSearchIndex') do op.执行(next_primary, 上下文: 上下文) end end |