我正在开发一个搜索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
对于运行测试,我首先使用 solr 服务器:
rake sunspot:solr:start RAILS_ENV=test
运行测试后,我停止 solr 服务器并在开发环境中再次运行它。搜索不再有效。
如果我重新索引,它会再次工作:
rake sunspot:reindex
(~1小时,因为我有10M +条目(
为什么会这样?
有关信息,我的/config/sunspot.yml :
development:
solr:
hostname: localhost
port: 8982
log_level: INFO
test:
solr:
hostname: localhost
port: 8981
log_level: WARNING
经过一番搜索,这个答案: 在太阳黑子轨道上重新索引 给我小费了。
我的太阳黑子.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