1

I'm accessing Solr in a Ruby on Rails application by using rsolr (not Sunspot). I create the local solr object that I use to send requests like this:

solr = RSolr.connect(:url => "http://localhost:8983/solr")

as far as I understand, this is not really a connection but just an object that will issue requests on demand, so it shouldn't be expensive to keep it initialized and it should never disconnect. According to that, it should be ok to have one global solr object, create it at start time and forget about it. Right? But maybe it's not thread safe?

When should I create the solr connection?

4

1 に答える 1

2

RSolr.connectメソッドが実際に行うことは、使用しているオプションをサニタイズして保存することだけです。ここでその方法を見ることができます。 新しい接続オブジェクト (特に、initializeメソッドがないため、作成時に何も実行されません) と に渡すオプションが渡されRSolr.connectます。

そうです、その通りです。一度接続して、どこかの変数に永久に接続したままにしても害はありません。(たとえばRSolr.connect 、Solr/Rails アプリでの結果をメモします。 )

于 2012-06-10T14:00:58.253 に答える