Need Some Guides on Solr with Rails.

Hi Everyone,

I am pretty new to Rails. I have very little idea about everything. But
for my new project i have been asked to do some research on Solr search
and implement it on Rails. Please provide me some link on tutorials and
guides about Solr on Rails. Trouble is... have to do it by tomorrow.

Hi!

Take a look at:

http://railscasts.com/episodes/278-search-with-sunspot

Ok.... So Sunspot and solr is one and the same thing?

I tried this example...
http://techbot.me/2011/01/full-text-search-in-in-rails-with-sunspot-and-solr/

but when i run it i get the exception:

$ rake sunspot:solr:run
Requiring REXML
The syntax of the command is incorrect.
rake aborted!
You need a Java Runtime Environment to run the Solr server

Tasks: TOP => sunspot:solr:run
(See full trace by running task with --trace)

Any solution to this? I have JDK 1.7 installed with PATH variable
properly set.

Ok… So Sunspot and solr is one and the same thing?

I guess Solr is the fulltext engine (in java) and sunspot is a rubygem which “wraps” access to solr.

Any workaround for the exception???

Any workaround for the exception???

You have to install Solr. =)

Uh, "JDK 1.7" ??? -- what is the output of

   java -version
   echo $JAVA_HOME
   echo $JRE_HOME

First, make sure java is installed properly by Hassan Schroeder’s post.

Then, download and set up Solr.

Then, install the sunspot gem

Then, RTFM. This entire post could have been avoided then…

Dheeraj Kumar

http://www.wowebook.pro/book/apache-solr-3-enterprise-search-server

The output of java -version is:

java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) Client VM (build 21.1-b02, mixed mode, sharing)

echo $JAVA_HOME is:
$ echo $JAVA_HOME
C:\Program Files\Java\jdk1.7.0_01

I dont have a JRE_HOME variable set. Is that really needed?

Right now... I have installed Solr and am able to start it using Tomcat.

I can see the Solr Admin page (attached sreenshot). But still i get the
above error mentioned. running the command with --trace gives me this:

$ rake sunspot:solr:run --trace
Requiring REXML
** Invoke sunspot:solr:run (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute sunspot:solr:run
The syntax of the command is incorrect.
rake aborted!
You need a Java Runtime Environment to run the Solr server
C:/Ruby193/gems/sunspot_solr-1.3.0/lib/sunspot/solr/server.rb:202:in
`ensure_java_installed'
C:/Ruby193/gems/sunspot_solr-1.3.0/lib/sunspot/solr/server.rb:27:in
`initialize'
C:/Ruby193/gems/sunspot_solr-1.3.0/lib/sunspot/solr/tasks.rb:23:in `new'
C:/Ruby193/gems/sunspot_solr-1.3.0/lib/sunspot/solr/tasks.rb:23:in
`block (3 levels) in <top (required)>'
c:/Ruby193/lib/ruby/1.9.1/rake/task.rb:205:in `call'
c:/Ruby193/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
c:/Ruby193/lib/ruby/1.9.1/rake/task.rb:200:in `each'
c:/Ruby193/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
c:/Ruby193/lib/ruby/1.9.1/rake/task.rb:158:in `block in
invoke_with_call_chain'
c:/Ruby193/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
c:/Ruby193/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
c:/Ruby193/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in
top_level'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:94:in `each'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:133:in
`standard_exception_handling'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:133:in
`standard_exception_handling'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:63:in `run'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:32:in `<top
(required)>'
c:/Ruby193/bin/rake:19:in `load'
c:/Ruby193/bin/rake:19:in `<main>'
Tasks: TOP => sunspot:solr:run

Attachments:
http://www.ruby-forum.com/attachment/6806/Solr.JPG

I can see the Solr Admin page (attached sreenshot). But still i get the
above error mentioned. running the command with --trace gives me this:

$ rake sunspot:solr:run --trace

...

rake aborted!
You need a Java Runtime Environment to run the Solr server
C:/Ruby193/gems/sunspot_solr-1.3.0/lib/sunspot/solr/server.rb:202:in
`ensure_java_installed'
C:/Ruby193/gems/sunspot_solr-1.3.0/lib/sunspot/solr/server.rb:27:in
`initialize'
C:/Ruby193/gems/sunspot_solr-1.3.0/lib/sunspot/solr/tasks.rb:23:in `new'
C:/Ruby193/gems/sunspot_solr-1.3.0/lib/sunspot/solr/tasks.rb:23:in

If `java -version` works from the command line, it should work here,
because that's what this gem is using to confirm Java is installed
(lib/solr/sunspot/java.rb) --

  3 module Java
  4 def self.installed?
  5 `java -version &> /dev/null`
  6 $?.success?
  7 end

But you're using Windows? What happens if you run the above
command from a shell? Does CMD understand " &> /dev/null" ?

If you've got Solr working with Tomcat, then you won't need
sunspot_solr (the packaged server) at all. All you need in that
scenario is the files generated by:

rails generate sunspot_rails:install

and a correct config file in config/sunspot.yml. In particular, you
may need to adjust the path value there to reflect your Tomcat config.

--Matt Jones

From one problem to another! I got a ready-made project and trying to
understand the code... And when i run the rake command i get:

$ rake sunspot:solr:run --trace
rake aborted!
126: The specified module could not be found. -
C:/Ruby193/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so
C:/Ruby193/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/mysql2.rb:2:in
`require'
C:/Ruby193/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/mysql2.rb:2:in
`<top (required)>'
C:/Ruby193/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2.rb:9:in `require'
C:/Ruby193/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2.rb:9:in `<top
(required)>'
C:/Ruby193/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
C:/Ruby193/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2
levels) in require'
C:/Ruby193/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
C:/Ruby193/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in
require'
C:/Ruby193/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
C:/Ruby193/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
C:/Ruby193/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
c:/railscode/SunspotTutorial/config/application.rb:7:in `<top
(required)>'
c:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
c:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
c:/railscode/SunspotTutorial/Rakefile:4:in `<top (required)>'
c:/Ruby193/lib/ruby/1.9.1/rake/rake_module.rb:25:in `load'
c:/Ruby193/lib/ruby/1.9.1/rake/rake_module.rb:25:in `load_rakefile'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:501:in `raw_load_rakefile'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:82:in `block in
load_rakefile'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:133:in
`standard_exception_handling'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:81:in `load_rakefile'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:65:in `block in run'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:133:in
`standard_exception_handling'
c:/Ruby193/lib/ruby/1.9.1/rake/application.rb:63:in `run'
c:/Ruby193/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:32:in `<top
(required)>'
c:/Ruby193/bin/rake:19:in `load'
c:/Ruby193/bin/rake:19:in `<main>'

I think Solr and me are not meant to be! :frowning:

It appears you have a MySQL, not Solr, problem.

You might want to create a new, bare Rails test app and make sure
the basics work first...

Yeah I did do a fresh creation of a project and changed from MySQL to
SQLite. And now i am back at Square 1...

$ rake sunspot:solr:run
Requiring REXML
The syntax of the command is incorrect.
rake aborted!
You need a Java Runtime Environment to run the Solr server

Tasks: TOP => sunspot:solr:run
(See full trace by running task with --trace)

By the way... I am on JDK 1.7, Win XP, Rails 3.1.3.

And yet you still haven't answered my previous question...

Which one?? If you are talking about the CMD command then i don't think
it would work. Those are commands that work on Unix. But i am using
GitBash to run my commands. Which is like a Unix shell in Windows.

Just to add:

java -version works from the command line.
I tried running the command from GitBash console coz on CMD it doesn't
work:
java -version &> /dev/null

And it does not throw and error of any sort.

Not sure what "works" and "doesn't work" above mean, so let's do
this; create a file, let's say java.rb with

# start
def java_installed?
  `java -version &> /dev/null`
  $?.success?
end

puts java_installed?
# end

Then run it from the command line, e.g. ruby java.rb

Let's see what the output is.