测试期间的太阳黑子重建索引擦除开发索引

Sunspot reindexing during tests erase development indexing

我正在进行一项搜索 API,它使用 Sunspot 进行索引并使用 Rspec 进行测试。

我对我的搜索控制器进行了测试:

  context 'when doing a simple search', :type => :request do
    let!(:instance_of_my_model) { create(:instance_of_my_model) }
    it 'return the correct results' do
      MyModel.reindex

     # some test code with a GET request
    end
  end

对于 运行ning 测试,我首先启动 solr 服务器:

rake sunspot:solr:start RAILS_ENV=test

在 运行 完成我的测试后,我停止了 solr 服务器,然后 运行 它又回到了开发环境中。搜索不再有效。

如果我重新索引,它会再次工作:

rake sunspot:reindex

(约 1 小时,因为我有超过 1000 万条条目)

为什么会这样?

有关信息,我的 /config/sunspot.yml :

development:
  solr:
    hostname: localhost
    port: 8982
    log_level: INFO

test:
  solr:
    hostname: localhost
    port: 8981
    log_level: WARNING

经过一番搜索,这个答案:Reindex on sunspot rails 告诉我的。

我的 sunspot.yml 应该是:

development:
  solr:
    hostname: localhost
    port: 8982
    log_level: INFO
    path: /solr/development


test:
  solr:
    hostname: localhost
    port: 8981
    log_level: WARNING
    path: /solr/test