Use one Solr instance for two Rails apps

試著忘記壹切 提交于 2019-12-13 05:48:59

问题


I have a server set up with several Rails apps, two of which are using Solr Sunspot. However, Solr is returning irrelevant results for a given search, and I believe the problem boils down to not having separated Solr/Sunspot to handle two Rails apps.

I have this in one app:

class Article < ActiveRecord::Base
  searchable do
    text :title, :boost => 2.0
    text :body do
      strip_tags body
    end
    time :created_at
  end
end

and this in the other:

class Article < ActiveRecord::Base
  searchable do
    text :title, :body
  end
end

And my sunspot.yml files are basically identical:

production:
  solr:
    hostname: localhost
    port: 8983
    log_level: WARNING
    path: /solr/default
    solr_home: solr

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

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

my solr.xml for both apps reads:

<?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"/>
  </cores>
</solr>

Is there a way to have 1 Solr instance index and deliver results for 2 Rails apps?

I haven't found much documentation on this so am a bit confused as to how to do this.

Any help is much appreciated. Thanks!


回答1:


I believe what you're looking for is a multicore setup. By default that is how sunspot runs now, except that the cores are for the different rails environments. See https://github.com/sunspot/sunspot/issues/115 for that change. Following that template I think you need to find one place to keep the config files and data directories, and then update them to list all the cores that it will run. This post at http://eemglobal.com/2014/07/setup-rails-4-with-sunspot-gem-and-solr-4-7-in-production-environment-on-ubuntu-14/ shows an alternate means, where you add the cores using the solr admin interface and then update the configuration files to match.



来源:https://stackoverflow.com/questions/28721996/use-one-solr-instance-for-two-rails-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!