太阳黑子(Rails)不支持data_path配置

时间:2016-08-31 16:45:06

标签: sunspot sunspot-rails sunspot-solr

我在sunspot.yml中使用了以下配置的sunpot_rails gem:

test:
  solr:
    hostname: localhost
    port: <%= 8990 + (ENV['TEST_ENV_NUMBER'] || '1').to_i %>
    path: /solr/test
    pid_dir: solr/pids/test<%= ENV['TEST_ENV_NUMBER'] %>
    data_path: solr/test<%= ENV['TEST_ENV_NUMBER'] %>/data

当我更改port环境变量时,它成功阅读了不同的pid_dirTEST_ENV_NUMBER。 但是我的问题是它总是指向同一个数据目录而data_path没有效果。实际上创建了一个空目录,但是solr admin显示了相同的路径。请参阅下面的/default/data正在使用。

我知道recent commit删除了该配置,但我使用的是自己的分支。

enter image description here

1 个答案:

答案 0 :(得分:1)

To answer my question, I will first tell why I need to change the data directory from the sunspot config files, rather than from solr configuration. I wanted to have multiple instances of Solr to run tests in parallel using the parallel_tests gem.

I figured out that only 1 Solr instance is needed. However, parallel tests can be achieved through 1 running instance but with multiple Solr cores. To do this you need to update solr/solr.xml by adding more cores:

<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
  <cores adminPath="/admin/cores" host="${host:}" hostPort="${jetty.port:}">
    <core name="default"     instanceDir="." dataDir="default/data"/>
    <core name="development" instanceDir="." dataDir="development/data"/>
    <core name="test"        instanceDir="." dataDir="test/data"/>
    <core name="test2"       instanceDir="." dataDir="test2/data"/>
    <core name="test3"       instanceDir="." dataDir="test3/data"/>
    <core name="test4"       instanceDir="." dataDir="test4/data"/>
    <core name="test5"       instanceDir="." dataDir="test5/data"/>
    <core name="test6"       instanceDir="." dataDir="test6/data"/>
    <core name="test7"       instanceDir="." dataDir="test7/data"/>
    <core name="test8"       instanceDir="." dataDir="test8/data"/>
  </cores>
</solr>

Then restart Solr to create those new cores:

RAILS_ENV=test bundle exec rake sunspot:solr:restart

Then modify config/sunspot.yml by appending the environment variable to the path:

test:
  solr:
    hostname: localhost
    port: 8981
    log_level: DEBUG
    path: /solr/test<%= ENV['TEST_ENV_NUMBER'] %>

Now whenever you run the parallel tests, the appropriate path/core will be selected:

bundle exec rake parallel:spec
相关问题