代码之家  ›  专栏  ›  技术社区  ›  Trip

为IRB设置bash别名?

  •  0
  • Trip  · 技术社区  · 15 年前

    >> sunspot-solr stop
    >> sunspot-solr start
    >> script/console
    >> Organization.reindex
    >> Event.reindex
    >> Deal.reindex
    >> exit
    >> script/server
    

    有没有办法在我的~/.profile中创建一个快捷方式作为别名来执行所有这些操作,而不用我每天都键入它?

    像这样虽然不管用?

    alias blam='cur && sunspot-solr stop && sunspot-solr start && script/console && Organization.reindex && Event.reindex && Deal.reindex && exit && script/server'
    
    2 回复  |  直到 15 年前
        1
  •  1
  •   yfeldblum    15 年前

    也许这会减轻一些痛苦?

    #Rakefile
    desc "Reindex the organizations, events, and deals Solr indexes."
    task :reindex => :environment do
      Organization.reindex
      Event.reindex
      Deal.reindex
    end
    

    > sunspot-solr stop
    > sunspot-solr start
    > rake reindex
    > script/server
    
        2
  •  1
  •   Marcelo W.    15 年前

    这是我的第一篇StackOverflow文章,这是一个老问题,但我觉得我可以贡献一些东西:D 定期重建Solr索引是一项非常昂贵的任务,您应该避免在生产中执行类似的操作!你所追求的目标可以通过三种方式实现:

    auto_commit_after_request = true

    这将告诉太阳黑子更新索引 将保存(或删除)新模型条目。这将保持你的索引更新,但可能是昂贵的。

    2-创建一个rake任务(可以在DelayedJob worker中运行cron),如下所示

    task :update_index => :environment do
    Sunspot.commit_if_dirty
    end

    这比在每次模型更新后执行提交要便宜得多,但请记住,这会给索引带来最终一致性的问题,这对于添加很好,但是对于删除却很糟糕:它会在索引中生成孤立项。这也是解决此问题的第三种方法的问题->

    autoCommit 具有 maxTime 提交之间的任意间隔(请记住使用毫秒表示的时间)。对于大多数应用程序来说,5分钟是不错的,但是你应该自己测试一下。

    希望这有帮助!