我想在保存模型的同时禁用solr重建索引。例如:
def show
@item = Item.where(params[:id]).first
@item.views_count += 1
@item.save
render :show_item
end
字段views_count
无法搜索。但solr在保存模型的同时需要2秒钟。在这种情况下,我可以关闭solr重建索引吗?
答案 0 :(得分:0)
变体1
@ item.update_column(:views_count,count)
变体2
class MySearchableModel < ActiveRecord::Base
searchable :auto_index => false do
bla bla
end
end
class AdministratorController < ApplicationController
def make_public
bla bla
MySearchableModel.reindex
Sunspot.commit
bla bla
end
end
变体3,如2
..
Sunspot.index @item
Sunspot.commit
..