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:

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.

Any workaround for the exception???

On Fri, Dec 2, 2011 at 11:10 AM, Somnath M.
[email protected]wrote:

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.

On Fri, Dec 2, 2011 at 5:10 AM, Somnath M. [email protected]
wrote:

rake aborted!
You need a Java Runtime Environment to run the Solr server

Any solution to this? I have JDK 1.7 installed

Uh, “JDK 1.7” ??? – what is the output of

java -version
echo $JAVA_HOME
echo $JRE_HOME


Hassan S. ------------------------ [email protected]

twitter: @hassan

On Fri, Dec 2, 2011 at 11:33 AM, Somnath M.
[email protected]wrote:

Any workaround for the exception???

You have to install Solr. =)

First, make sure java is installed properly by Hassan S.'s post.
Then, download and set up Solr.
Then, install the sunspot gem

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

Dheeraj K.

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


Joelson de Abreu
[email protected]
(48) 9902-2800

The output of java -version is:

java version “1.7.0_01”
Java™ SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot™ 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 am stuck with installing Solr.

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:ininitialize’
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:inblock (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:inblock 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:inexecute’
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:inmon_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:ininvoke’
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:inblock (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:inblock 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:intop_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:instandard_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
Tasks: TOP => sunspot:solr:run

On Sat, Dec 3, 2011 at 12:28 AM, Somnath M. [email protected]
wrote:

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" ?


Hassan S. ------------------------ [email protected]

twitter: @hassan

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:inblock (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:inblock 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:inrequire’
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:inrequire’
c:/railscode/SunspotTutorial/Rakefile:4:in <top (required)>' c:/Ruby193/lib/ruby/1.9.1/rake/rake_module.rb:25:inload’
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:inraw_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:instandard_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:inblock 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:inrun’
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:inload’
c:/Ruby193/bin/rake:19:in `’

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

On Tue, Dec 6, 2011 at 7:07 AM, Somnath M. [email protected]
wrote:

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’

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…


Hassan S. ------------------------ [email protected]

twitter: @hassan

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.

On Dec 3, 3:28am, Somnath M. [email protected] wrote:

** 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’

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 J.

On Wed, Dec 7, 2011 at 6:58 AM, Somnath M. [email protected]
wrote:

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

And yet you still haven’t answered my previous question…


Hassan S. ------------------------ [email protected]

twitter: @hassan

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.

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.

On Wed, Dec 7, 2011 at 2:15 PM, Somnath M. [email protected]
wrote:

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.

The question is what environment Rails is running in; if you’re starting
it from GitBash, does it execute system calls using that? I don’t know
and I can’t test it.

The sample code I provided is copied from the sunspot_solr check
for a Java installation, so that’s why I suggested trying it. You could
certainly try debugging directly from that gem.


Hassan S. ------------------------ [email protected]

twitter: @hassan