模块:Mongoid::SearchIndexable::ClassMethods
- 定义于:
- lib/mongoid/search_indexable.rb
Overview
该功能的类级方法的实现。
实例方法摘要折叠
-
# create_search_indexes ⇒ Array<String>
请求创建所有已注册的搜索索引。
-
# remove_search_index (name: nil, ID : nil) ⇒ 对象
删除给定名称或 ID 指定的搜索索引。
-
# remove_search_indexes ⇒ 对象
请求删除所有已注册的搜索索引。
-
# search_index (name_or_defn, defn = nil) ⇒ 对象
为提供的单键或复合键添加索引定义。
-
# search_indexes (options = {}) ⇒ 对象
查询当前模型集合上可用搜索索引的便捷方法。
-
# wait_for_search_indexes (names, Interval: 5 ) {|SearchIndexable::Status| ... } ⇒ 对象
等待创建命名搜索索引。
实例方法详细信息
# create_search_indexes ⇒ Array<String>
请求创建所有已注册的搜索索引。 请注意,搜索索引是异步创建的,可能需要几分钟才能完全可用。
65 66 67 68 69 |
# File 'lib/mongoid/search_indexable.rb', line 65 def create_search_indexes return if search_index_specs.空? 集合.search_indexes.create_many(search_index_specs) end |
# remove_search_index (name: nil, ID : nil) ⇒对象
删除给定名称或 ID 指定的搜索索引。 必须提供名称或 ID,但不能同时提供两者。
107 108 109 110 111 112 113 114 |
# File 'lib/mongoid/search_indexable.rb', line 107 def remove_search_index(名称: nil, ID : nil) 记录器.信息( " 搜索索引: 正在 删除 ID' #{ collection . name } ' 上的 搜索 集合 ' #{ { name || ID } ' " \ " 。 ")集合。 search_indexes 。 drop_one ( name: name , ID : ID ) end |
# remove_search_indexes ⇒对象
注意:
如果这样可以仅删除搜索索引,那就太好了
请求删除所有已注册的搜索索引。 请注意,搜索索引是异步删除的,可能需要几分钟才能完全删除。
已在模型上声明,但由于模型可能未命名索引,因此我们不能保证知道相应索引的名称或 ID。 不过,可以合理地假设,模型的意图是一对一地声明所有所需的搜索索引,因此删除所有搜索索引就足够了。 如果需要删除特定索引或索引设立,请考虑将 search_indexes.each 与 remove_search_index 一起使用。
128 129 130 131 132 |
# File 'lib/mongoid/search_indexable.rb', line 128 def remove_search_indexes search_indexes.每 do |spec| remove_search_index ID : spec[' ID '] end end |
# search_index (name_or_defn, defn = nil) ⇒对象
为提供的单键或复合键添加索引定义。
147 148 149 150 151 152 153 |
# File 'lib/mongoid/search_indexable.rb', line 147 def search_index(name_or_defn, defn = nil) 名称 = name_or_defn 名称, defn = nil, 名称 if 名称.is_a?(哈希) spec = { 定义: defn }.点击 { |s| s[:name] = 名称.to_s if 名称 } search_index_specs.推动(spec) end |
# search_indexes (options = {}) ⇒对象
查询当前模型集合上可用搜索索引的便捷方法。
98 99 100 |
# File 'lib/mongoid/search_indexable.rb', line 98 def search_indexes( = {}) 集合.search_indexes() end |
# wait_for_search_indexes (names, Interval: 5 ) {|SearchIndexable::Status| ... } ⇒对象
等待创建命名搜索索引。
78 79 80 81 82 83 84 85 86 |
# File 'lib/mongoid/search_indexable.rb', line 78 def wait_for_search_indexes(名称, interval: 5) 循环 do 状态 = 状态.new(get_indexes(名称)) 产量 状态 if block_given? 中断 if 状态.准备好了吗? 睡眠 interval end end |