类:Mongo::SearchIndex::View
- 继承:
-
对象
- 对象
- Mongo::SearchIndex::View
- 定义于:
- lib/ Mongo/search_index/view.rb
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 、 #write_worker
构造函数详情
#initialize (集合, options = {}) ⇒查看
创建新的搜索索引视图。
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ Mongo/search_index/view.rb', line 33 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 ⇒ 哈希(只读)
在查询可用索引时,返回用于聚合命令的选项哈希。
22 23 24 |
# File 'lib/ Mongo/search_index/view.rb', line 22 def @aggregate_options end |
# 集合 ⇒ Mongo::Collection (只读)
返回此视图所属的集合。
12 13 14 |
# File 'lib/ Mongo/search_index/view.rb', line 12 def 集合 @collection end |
# requests_index_id ⇒ nil |字符串(只读)
返回要查询的索引ID 。
15 16 17 |
# File 'lib/ Mongo/search_index/view.rb', line 15 def requests_index_id @requested_index_id end |
# requests_index_name ⇒ nil |字符串(只读)
返回要查询的索引名称。
18 19 20 |
# File 'lib/ Mongo/search_index/view.rb', line 18 def requests_index_name @requested_index_name end |
实例方法详细信息
# create_many (indexes) ⇒ Array<String>
使用单个命令创建多个搜索索引。
62 63 64 65 66 |
# File 'lib/ Mongo/search_index/view.rb', line 62 def create_many(索引) spec = spec_with(索引: 索引.map { |v| validate_search_index!(v) }) 结果 = 操作::创建搜索索引.new(spec).执行(next_primary, 上下文: execution_context) 结果.first['indexesCreated'].map { |idx| idx[' name '] } end |
# create_one (definition, name: nil, type: ' 搜索') ⇒ 字符串
使用给定定义创建单个搜索索引。 如果提供了名称,则会为新索引指定该名称。
51 52 53 |
# File 'lib/ Mongo/search_index/view.rb', line 51 def create_one(定义, 名称: nil, 类型: ' 搜索 ') create_many([ { 名称: 名称, 定义: 定义, 类型: 类型 } ]).first end |
# drop_one (ID: nil, name: nil) ⇒ Mongo::Operation::Result | false
删除具有给定 ID 或名称的搜索索引。 必须指定其中之一,但不能同时指定两者。
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ Mongo/search_index/view.rb', line 76 def drop_one(ID : nil, 名称: nil) validate_id_or_name!(id, 名称) spec = spec_with(index_id: id, index_name: 名称) op = 操作::DropSearchIndex.new(spec) # 根据规范: # 驱动程序必须抑制 NamespaceNotFound 错误 # ``dropSearchIndex`` 助手。 删除操作应该是幂等的。 do_drop(op, nil, execution_context) end |
#each (&block) ⇒ self |枚举器
遍历搜索索引。
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ Mongo/search_index/view.rb', line 95 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
查询搜索索引可枚举项是否为空。
136 137 138 |
# File 'lib/ Mongo/search_index/view.rb', line 136 def 空? 数数.zero? end |
# update_one (definition, ID: nil, name: nil) ⇒ Mongo::Operation::Result
使用给定 ID 或名称更新搜索索引。 必须提供其中之一,但不能同时提供。
123 124 125 126 127 128 |
# File 'lib/ Mongo/search_index/view.rb', line 123 def update_one(定义, ID : nil, 名称: nil) validate_id_or_name!(id, 名称) spec = spec_with(index_id: id, index_name: 名称, index: 定义) 操作::updateSearchIndex.new(spec).执行(next_primary, 上下文: execution_context) end |