Sunspot + Solr 5.2 (latest) - ruby-on-rails

I don't know where to put this, I can move it to Stack Overflow if you want.
I'm new at Sunspot and Rails, and I have use it before with Solr 4.X running over Tomcat7 without issues, I was happy.
Now, I'm deploying a new app, and I want to use Solr 5.2 which is the latest, this one doesn't run on top of Tomcat like his predecessors, it's now a nice standalone service running on top of a jetty instance.
So, I followed this guid to install it https://www.digitalocean.com/community/tutorials/how-to-install-solr-5-2-1-on-ubuntu-14-04
I have even creating a collection and stuff, but when I do rake sunspot:reindex it returned the following error:
RSolr::Error::Http: RSolr::Error::Http - 400 Bad Request Error: {'responseHeader'=>{'status'=>400,'QTime'=>127},'error'=>{'msg'=>'undefined field type','code'=>400}} URI: http://localhost:8983/solr/screencap-dev/update?wt=ruby Request Headers: {"Content-Type"=>"text/xml"} Request Data: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><query>type:[MODEL NAME]</query></delete>"
That [MODEL NAME] is the name of the model I'm indexing.
I can't make it work, so I'm using the sunspot_solr version, I even tried to move every config file over to my Solr 5.2 without success, Server errors and stuff.
Did anyone did this already?
UPDATE
I have tried to copy the collection files from sunspot_solr (Solr 5.0.0) to my Solr Service (Solr 5.2.0), I got it to load the files, but:
Error CREATEing SolrCore 'screencap-dev': Unable to create core [screencap-dev] Caused by: solr.DateField
Obviously Sunspot collections files are not compatible.

Your solr instance is broken.
These are the terminal commands you should follow to solve your problems:
ps aux | grep solr to get solr process ID
sudo kill , is the ID you found from 1
rm -r , remove the solr directory inside your project
to
remove all of previous indexes
RAILS_ENV=development bundle exec rake sunspot:solr:start
Change the path to /solr/default inside config/sunspot.yml
RAILS_ENV=development bundle exec rake sunspot:solr:reindex

Related

How to configure Solr standalone in Production server with Rails application using sunspot gem?

I'm looking to deploy solr-8 in production as standalone mode with Ruby on Rails application. While running bundle exec rake sunspot:solr:reindex getting this error
RSolr::Error::Http - 500 Internal Server Error
Any help would be appreciated!
using gem sunspot in development and is working fine with standalone solr-8 on local machine.
Solr is running in cloud mode. Please share the configuration which is used to talk to solr and rails for index
It's really straight forward setup but took long time for me to resolve.
In standalone mode it is bit tricky to communicate with rails
we need to copy schema.xml and solrconfig.xml to server/solr/your-core/conf/
as Solr-8 have some deprecation warning. Please carefully read warnings.
Once you copied files restart solr and run
rake sunspot:solr:reindex

Rake Stats task failure with code_statistics file missing issue

Have a legacy application built on Rails 3.2.16, Ruby 1.9.3 which is being assessed for updates. Apart from the obvious in that it's running on outdated versions of both Ruby and Rails, I'm stuck with an error when trying to gather the stats.
When executing the command:
rake stats
I'm getting the error:
rake stats
rake aborted!
cannot load such file -- code_statistics
This is also correlated via the 'Rails Console' whereby issuing the command require 'code_statistics' also produces a similar error.
Now I can confirm the following
Rake task exists as shown by the rake -T giving command output of rake stats # Report code statistics (KLOCs, etc...
CodeStatistics class is in the railities library
I suspect that it's a path or file issue with potentially an environment setting that I'm missing Rails 3.2.
Any suggestions ?
Regards
Grant
Ok - so solved the problem. It was a path issue as first suspected.
After some digging in this legacy system I'm reviewing there were path changes made in rspec.rake and cuke.rake files which indicated a parent directory. Changing the path
from:
require 'code_statistics'
to
require 'rails/code_statistics'
has now resolved the issue such that rake stats gives the usual results.

Solr Sunspot Production environment setup issue

I am trying to setup solr sunspot search in production mode.
I have followed the below tutorial and got success in setting up tomcat-solr server running.
http://www.arborisoft.com/how-to-install-apache-solr-4-4-on-ubuntu-12-04/
I ran
rails generate sunspot_rails:install
and configured the config/sunspot.yml file.
For development mode I used 'sunspot_solr' gem(which is not advisable for production mode) and got this command working.
bundle exec rake sunspot:solr:start
When I removed this gem
it's giving me following error
Note: This task has been moved to the sunspot_solr gem. To install, start and
stop a local Solr instance, please add sunspot_solr to your Gemfile:
group :development do
gem 'sunspot_solr'
end
I have tried adding this to Rakefile:
require 'sunspot/solr/tasks'
when I run the following command
bundle exec rake app:sunspot:solr:start
I am getting the following error
rake aborted!
cannot load such file -- sunspot/solr/tasks
I am using rails 4.
I don't know what I've missed. I have searched for the solution in and out of stackoverflow. But I couldn't get any reference. Even if I find any since I am a rails noob, I couldn't understand what they are talking about. any solution will be really helpful.
You can also change the path to solr/default in config/sunspot.yml file for production mode or any other defined modes.
These are some terminal commands which could follow to solve your problems:
ps aux | grep solr to get solr process ID
through this you can check which server id is running and which one is in your sunspot pid file.
sudo kill <ID>, <ID> is the ID you found from 1
rm -r <path/to/solr>, remove the solr directory inside your project to remove all of previous indexes
RAILS_ENV=production bundle exec rake sunspot:solr:start
Change the path to /solr/default inside config/sunspot.yml
RAILS_ENV=production bundle exec rake sunspot:solr:reindex
this link can also help in understanding problem and issues:https://github.com/sunspot/sunspot/issues/492

Can I run Solr server without running rake command for rails application?

Is there any alternate way for running solr server without running rake command for rails application like providing all those solr related classes into single jar and then use that jar.
Please suggest some of the solutions regarding this
Thanks
I don't know if you checked Sunspot (the best haha), but you can use the start/stop commands, for example: https://github.com/sunspot/sunspot#sunspot_rails
bundle exec sunspot-solr start -p 8983
Also check this out for an example https://gist.github.com/doitian/1795439 (integrates Sunspot with Capistrano, but you can get an idea of the implementation)

Can't reindex Sunspot SOLR - Error - RSolr::Error::Http - 500 Internal Server Error

Everytime i try to reindex using...
rake sunspot:solr:reindex
These error messages always show:
Error - RSolr::Error::Http - 500 Internal Server Error - retrying...
Error - RSolr::Error::Http - 500 Internal Server Error - ignoring...
Error - RSolr::Error::Http - 500 Internal Server Error - retrying...
Error - RSolr::Error::Http - 500 Internal Server Error - ignoring...
I tried to stop then start using...
rake sunspot:solr:stop
rake sunspot:solr:start
But nothing happened.
And now everytime I try to run my app in localhost...
This is the error:
RSolr::Error::Http - 500 Internal Server Error
Error: Severe errors in solr configuration.
Check your log files for more detailed information on what may be wrong.
If you want solr to continue after configuration errors, change:
<abortOnConfigurationError>false</abortOnConfigurationError>
in null
-------------------------------------------------------------
Request Data: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><query>type:Trip</query></delete>"
A more detailed error message than the one I had in terminal.
I tried plenty of solutions from the net like setting Abort Configuration to false, but nothing happened.
The error still persists.
Any work around will be appreciated.
The solution:
rake sunspot:solr:stop
rm -rvf solr (Delete your /solr directory)
rake sunspot:solr:start
rake sunspot:solr:reindex
Enjoy
Based on the answer provided by #professormeowingtons, what worked for me in production is the following:
$ rake sunspot:solr:stop RAILS_ENV=production
$ rm -rvf solr # delete your /solr directory
$ sudo reboot # reboot the machine RAILS_ENV=production
$ rake sunspot:solr:start RAILS_ENV=production
$ rake sunspot:solr:reindex RAILS_ENV=production
With reference to #professormeowingtons, you don't have to delete entire solr directory as you might not want to delete your solr configurations like schema.xml and solrconfig.xml. The reason you are getting error might be because of corrupted indexes, what you can do is delete 'solr/env' i.e. solr/development or/and solr/data/development and restart solr server.
1. rake sunspot:solr:stop
2. rm -rf solr/development (Delete your solr/development directory)
3. rm -rf solr/data/development
4. rake sunspot:solr:start
5. rake sunspot:solr:reindex
If problem still persists, rollback your recent changes because you might have added some wrong configurations.
I've got this working by restarting my PC. I guess there was a solr instance incorrectly stopped :-?
This means there is a problem in your config file and solr couldn't start. Check the sunspot logs.
Check your sunspot server by localhost:8982 (depelopment). if you get same error like console. try again by localhost:8983 (production). for my case, port 8983 is work fine and I change sunspot config at rails/config/sunspot.yml to port :8983. and solved.
Upgrade Rsolr gem to latest version, 1.0.10.pre1, that worked for me.
Now I was able to reindex my models, and everything seems fine, in production that is.
For those of you that are using Websolr in Heroku production and getting this error when reindexing:
Remember that you have to upload your schema.xml manually in the Websolr admin GUI, under the "Advanced Configuration" tab when viewing your index.
Here's the direct link: https://websolr.com/slices/<index_uri>/schema
You can get the <index_uri> from running heroku config and getting it from the last part of your
WEBSOLR_URL that looks like this: http://index.websolr.com/solr/<index_uri>
I ran into this error because I mistakenly assumed that Websolr would just use the schema.xml that I committed to git and pushed to heroku together with all the other <appname>/solr/conf files.
The essence is to reset every sunspot solr part, that may occur problems.
Delete the complete solr directory. This deletes the complete solr directory for sure - double check!
rm -rf solr
Delete the sunspot solr configuration file config/sunspot.yml.
rm config/sunspot.yml
Stop sunspot solr.
bundle exec rake sunspot:solr:stop
Check if sunspot solr is no longer running. If there are solr processes running note there PID
ps aux | grep solr
Manually kill the solr processes by PID. This command is only needed if bundle exec rake sunspot:solr:stop wasn't successful.
kill -9 PID # (fully turns off solr - double check `ps aux|grep solr`)
Delete your database, double check if you really sure! Then recreate the database and restore the schema from the migration files.
bundle exec rake db:drop
bundle exec rake db:create
bundle exec rake db:migrate
creates a new sunspot configuration config/sunspot.yml.
rails generate sunspot_rails:install
recreates the solr directory
bundle exec rake sunspot:solr:start
create a new solr index
bundle exec rake sunspot:reindex
Finally refill the empty database with your seed data.
bundle exec rake db:seed

Resources