Reputation: 1879
Using rails 3.0.6 , ruby 1.9.3
Gemfile (pasted as per info needed)
gem 'rails', '3.0.6',
gem 'rake', '0.9.2'
gem 'sunspot_rails'
gem 'sunspot_solr'
gem 'progress_bar'
I have set up the model as such in user.rb
Sunspot.setup(User) do
text :resume_body, :stored => true
text :job_title, :stored => true
end
and then i have used
class CandidatesController < ApplicationController
def index
@search = Sunspot.search(User) do
# Full text on resume body and job title with highlighting
keywords params[:q] do
highlight :resume_body, :max_snippets => 3, :fragment_size => 120, :merge_contiguous_fragments => true
end
Whenever i run rake tasks such as bundle exec rake sunspot:solr:reindex rake sunspot:reindex
it throws error
Error
bundle exec rake sunspot:solr:reindex --trace
Your Gemfile lists the gem rspec-rails (>= 2.0.0.beta.19) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
Your Gemfile lists the gem mysql2 (~> 0.2.22) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
Your Gemfile lists the gem mysql2 (~> 0.2.22) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
** Invoke sunspot:solr:reindex (first_time)
** Invoke sunspot:reindex (first_time)
** Invoke environment (first_time)
** Execute environment
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
** Execute sunspot:reindex
rake aborted!
undefined method `solr_reindex' for #<Class:0xb762a7c>
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.0.6/lib/active_record/base.rb:1008:in `method_missing'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/sunspot_rails-2.1.0/lib/sunspot/rails/tasks.rb:57:in `block (4 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/sunspot-2.1.0/lib/sunspot/class_set.rb:16:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/sunspot-2.1.0/lib/sunspot/class_set.rb:16:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/sunspot_rails-2.1.0/lib/sunspot/rails/tasks.rb:56:in `block (3 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/sunspot_rails-2.1.0/lib/sunspot/rails/tasks.rb:68:in `with_session'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/sunspot_rails-2.1.0/lib/sunspot/rails/tasks.rb:19:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/task.rb:174:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/usr/local/rvm/gems/ruby-1.9.3-p448/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p448/bin/rake:23:in `load'
/usr/local/rvm/gems/ruby-1.9.3-p448/bin/rake:23:in `<main>'
/usr/local/rvm/gems/ruby-1.9.3-p448/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-1.9.3-p448/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => sunspot:solr:reindex => sunspot:reindex
This is the first time i am trying out solr and sunspot in development , and i have followed all the tutorials too to make sure the installation is right . But still , i maybe missing something . Anyhelp to point a newbie to a right direction would be very much appreciated . Thanks in advance , i very much intend to use sunspot in production too :)
tail -f log/sunspot-solr-development.log
at org.apache.solr.core.Config.<init>(Config.java:103)
at org.apache.solr.core.Config.<init>(Config.java:73)
at org.apache.solr.core.SolrConfig.<init>(SolrConfig.java:117)
at org.apache.solr.core.CoreContainer.createFromLocal(CoreContainer.java:989)
... 9 more
Feb 25, 2014 1:31:54 PM org.apache.solr.servlet.SolrDispatchFilter init
INFO: user.dir=/usr/local/rvm/gems/ruby-1.9.3-p448/gems/sunspot_solr-2.1.0/solr
Feb 25, 2014 1:31:54 PM org.apache.solr.servlet.SolrDispatchFilter init
INFO: SolrDispatchFilter.init() done
Loading development environment (Rails 3.0.6)
1.9.3-p448 :001 > User.reindex
NoMethodError: undefined method `reindex' for #<Class:0x9910fd8>
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.0.6/lib/active_record/base.rb:1008:in `method_missing'
from (irb):1
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.0.6/lib/rails/commands/console.rb:44:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.0.6/lib/rails/commands/console.rb:8:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/railties-3.0.6/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Upvotes: 1
Views: 1480
Reputation: 9995
This might help you to get ride .....
Steps for Sunspot Quick Start :
Add this gem to your gemfile
gem 'sunspot_rails'
Install this gem using
bundle install
start solr using this command
rake sunspot:solr:start
For a simple example, consider a Post model with a title field and a content field. We will index these fields as Solr text fields.
rake sunspot:solr:reindex
Here's a simple search against the Post class that we indexed above, running from the index action of the PostsController:
class PostsController < ApplicationController
def index
@search = Post.search do
keywords params[:query]
end
@posts = @search.results
end
end
Thats all now we can use @posts
variable in our view for index
action. Results will come accordingly
Note: This is just a simplest example to understanding flow and get started with sunspot solr indexing and searching ... there are many other options which should be used according to our requirement.
Upvotes: 1