2014-02-25 27 views
0

使用Rails 3.0.6,1.9.3紅寶石利用太陽黑子的寶石和Solr索引搜索結果

的Gemfile(粘貼爲每個需要信息)

寶石 '軌', '3.0.6',

寶石 '耙', '0.9.2'

寶石 'sunspot_rails'

寶石 'sunspot_solr'

寶石 'progress_bar'

我在user.rb建立模型本身

Sunspot.setup(User) do 
    text :resume_body, :stored => true 
    text :job_title, :stored => true 
end 

,然後我用

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 

每當我運行rake任務,如 束EXEC耙太陽黑子:solr:reindex 耙太陽黑子:重新索引

它拋出錯誤

錯誤

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 

注 - 應用程序之前使用太陽黑子1.1和我把它升級到2.1

這是我第一次嘗試在發展的Solr和黑子,我也跟着全部這些教程也是爲了確保安裝是正確的。但是,我仍然可能錯過了一些東西。 Anyhelp指向一個新手正確的方向將非常感激。在此先感謝,我非常想使用太陽黑子在生產太:)

更新1 -

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 

更新2 -

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>' 
+0

太陽黑子給我的東西時,我總是檢查的東西清單廢話:我'耙太陽黑子:solr:開始'。我捆綁安裝嗎?我的rails是否生成了sunspot_rails install?。另外,您是否有理由在用戶模型中使用'Sunspot.setup'而不是'searchable'模塊?這不是造成這一點,我只是好奇。 – mikeryz

+0

另外,確保你測試得很好。太陽黑子2.1.0將打包的SOLR版本從3.5更改爲4.2 ... – mikeryz

+0

我嘗試過可搜索的塊,因爲這是一箇舊的應用程序,曾經使用太陽黑子1.1但沒有運氣,也提到了你提到的命令,並且我得到了結果也是如此,但搜索結果不會被索引。 –

回答

1

這可能會幫助你得到的旅程。 ...

黑子快速啓動步驟:

  1. 這塊寶石添加到您的Gemfile

    gem 'sunspot_rails' 
    
  2. 安裝使用

    bundle install 
    
  3. 開始這種寶石的Solr使用此命令

    rake sunspot:solr:start 
    
  4. 對於一個簡單的例子,考慮一個帶有標題字段和內容字段的Post模型。我們將這些字段索引爲Solr文本字段。

    rake sunspot:solr:reindex 
    
  5. 下面是對我們在上面建立索引的Post類一個簡單的搜索,從PostsController的index動作運行:

    class PostsController < ApplicationController 
    def index 
        @search = Post.search do 
        keywords params[:query] 
        end 
        @posts = @search.results 
    end 
    end 
    
  6. 這就是所有現在我們可以使用@posts變量,我們認爲對index操作。結果會相應

注意:這僅僅是理解流動的最簡單的例子,讓 開始與太陽黑子Solr的索引和搜索......存在應根據使用許多 其他選項我們需求。

+1

你能總結一下你認爲會從鏈接中獲得什麼幫助嗎?鏈接有隨着時間消失的習慣 –