Francis's Octopress Blog

A blogging framework for hackers.

Errno::ECONNREFUSED: Connection Refused - Connect(2) While Connecting to a Remote Solr Instance From Sunspot

Errno::ECONNREFUSED: Connection refused – connect(2) while connecting to a remote solr instance from Sunspot

Quickstart with Rails 3

Add to Gemfile:

gem 'sunspot_rails' gem 'sunspot_solr' # optional pre-packaged Solr distribution for use in development

Bundle it!

bundle install

Generate a default configuration file:

rails generate sunspot_rails:install

If sunspot_solr was installed, start the packaged Solr distribution with:

bundle exec rake sunspot:solr:start # or sunspot:solr:run to start in foreground

Now that Sunspot knows how to index the Post model, we need to get the existing data into Solr. Any time a Post is created, updated, or destroyed, Sunspot::Rails will automatically make the change to the index; you only need to do a full reindex if you’ve added or changed a searchable definition for a model.

$ rake sunspot:reindex

If sunspot_solr was installed, start the packaged Solr distribution with:

jhjguxin@jhjguxin-Aspire-4750:~$ heroku run:detached rake sunspot:solr:start RAILS_ENV=production rake sunspot:solr:start --app francisjiang or type:sunspot-solr start -- -p 8983 or sunspot-solr start -- -p 8983 -d data/solr/myapp Try to start the solr
##with apache+solr+rails
jhjguxin@jhjguxin-virtual-machine:/var/www/enki$ sudo gem install sunspot_solr
Successfully installed escape-0.0.4
Successfully installed sunspot_solr-1.3.0
2 gems installed
Installing ri documentation for escape-0.0.4...
Installing ri documentation for sunspot_solr-1.3.0...
Installing RDoc documentation for escape-0.0.4...
Installing RDoc documentation for sunspot_solr-1.3.0...
jhjguxin@jhjguxin-virtual-machine:/var/www/enki$ sudo sunspot-solr start -- -p 8983 -d solr/data/
[sudo] password for jhjguxin: 
java version "1.6.0_23"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)
OpenJDK Client VM (build 20.0-b11, mixed mode, sharing)

Solr服务控制 将以上内容添加到Rakefile后,将会多出4个task出来 服务器启动: rake sunspot:solr:start 初次启动,会安装一个embed的solr程序,那么开发环境中省去了安装配置Solr环境繁琐步骤。不过,production环境里可不要使用这个embed版。 服务器停止: rake sunspot:solr:stop 全部重建索引: rake sunspot:reindex 如果你想看到运行日志,把服务跑在前端。可以使用一下命令: rake sunspot:solr:run 使用以上命令,就能完成对Sunspot的控制。