【问题标题】:What is the correct way of maintaining indices for Sunspot Solr?维护 Sunspot Solr 索引的正确方法是什么?
【发布时间】:2013-04-05 09:22:13
【问题描述】:

我对 Solr 索引机制感到困惑。也许有人可以对此有所了解。

所以,我们有 2 个 rake 命令:rake sunspot:solr:indexrake sunspot:solr:reindex

这是我的index 任务的样子(我为 Mongoid 覆盖了它):

namespace :sunspot do
  namespace :solr do 
    desc "indexes searchable models"
    task :index => :environment do
      [Model1, Model2].each do |model|
        Sunspot.index!(model.all)
      end
    end
  end
end

据我了解,我对index 的定义是每次运行它时都会有效地重新索引集合。

我说的对吗? 它会覆盖以前的索引还是我必须使用reindex 来删除旧索引并创建新索引?

我正在使用宝石sunspot v2.0.0sunspot_mongo v1.0.1sunspot_solr v2.0.0

【问题讨论】:

    标签: solr indexing mongoid sunspot


    【解决方案1】:

    重新索引任务只是在每个模型上调用solr_reindex,该方法的源代码如下(取自 github)。

       # Completely rebuild the index for this class. First removes all 
       # instances from the index, then loads records and indexes them.
       #   
       # See #index for information on options, etc.
       #   
       def solr_reindex(options = {}) 
         solr_remove_all_from_index
         solr_index(options)
       end 
    

    如果您查看solr_index 的来源,cmets 会说该方法将“添加/更新 Solr 索引中的所有现有记录”。

    所以要回答你的问题,reindex 任务与index 任务基本相同,只是reindex 任务将首先删除现有索引。如果您的索引中有您知道不应该存在的项目,您应该致电reindex。如果您知道自己只是在索引中添加或更新项目,则只需调用 index 而不会遭受删除索引然后从头开始重建它的性能损失。

    【讨论】:

      猜你喜欢
      • 2013-08-06
      • 2017-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-25
      • 2019-07-09
      • 2017-09-06
      • 2011-11-06
      相关资源
      最近更新 更多