我无法索引我的数据库以便使用sunspot_rails进行搜索。我收到以下错误:
执行太阳黑子:reindex耙子中止! 未定义的局部变量或方法 '计数器'
运行rake sunspot后,我得到以下输出:reindex。我是Rails的新手。我想在我的项目中添加sunspot_rails以添加搜索功能(希望使用Heroku部署项目)。
我正在使用Rails 3.我按照这里的说明进行操作:https://github.com/outoftime/sunspot/blob/master/sunspot_rails/README.rdoc。我的其他各种尝试来诊断问题包括:
按照此处的说明单独安装libxml2以安装nokogiri:http://www.engineyard.com/blog/2010/getting-started-with-nokogiri/
**调用太阳黑子:reindex(first_time)
**调用环境(first_time)
**执行环境
**执行太阳黑子:reindex耙子中止! undefined局部变量或方法counter' for [removed pound]<Class:0x10359aef8> /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:1008:in
method_missing'/ Library/Ruby/Gems/1.8/gems/sunspot_rails-1.2.0/lib/sunspot/rails/searchable.rb:235:in solr_index' /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/relation/batches.rb:71:in
find_in_batches'/ Library / Ruby / Gems / 1.8 / gems / activerecord-3.0.3 / lib / active_record / base.rb:440:in __send__' /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:440:in
find_in_batches'/Library/Ruby/Gems/1.8/gems/sunspot_rails-1.2.0 /lib/sunspot/rails/searchable.rb:234:in solr_index' /Library/Ruby/Gems/1.8/gems/sunspot_rails-1.2.0/lib/sunspot/rails/searchable.rb:184:in
solr_reindex'/ Library/Ruby/Gems/1.8/gems/sunspot_rails-1.2.0/lib/sunspot/rails/tasks.rb:57 / Library / Ruby / Gems / 1.8 / gems / sunspot_rails-1.2.0 / lib / sunspot / rails / tasks.rb:56:in each' /Library/Ruby/Gems/1.8/gems/sunspot_rails-1.2.0/lib/sunspot/rails/tasks.rb:56 /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in
call'/ Library/Ruby/Gems/1.8/gems/rake-0.8 .7 / lib / rake.rb:636:in execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in
each'/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in execute' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in
invoke_with_call_chain'/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in synchronize' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in
invoke_with_call_chain'/ Library/Ruby/Gems/1.8/gems/ rake-0.8.7 / lib / rake.rb:583:in invoke' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in
invoke_task'/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in {{ 1}}每个'/Library/Ruby/Gems/1.8/gems/rake-0.8 .7 / lib / rake.rb:2029:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in
standard_exception_handling'/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in
运行'/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in top_level' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in
运行'/Library/Ruby/Gems/1.8/gems/rake-0.8。 7 / bin / rake:31 / usr / bin / rake:19:in`load'/ usr / bin / rake:19
这就是我在课堂上想要搜索的内容:
standard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in
非常感谢任何帮助!
答案 0 :(得分:2)
错误发生在sunspot_rails-1.2.0 / lib / sunspot / rails / searchable.rb:235代码中。 你应该自己修理它。
修理它很容易:
def solr_index(opts={})
options = {
:batch_size => 500,
:batch_commit => true,
:include => self.sunspot_options[:include],
:first_id => 0
}.merge(opts)
if options[:batch_size]
counter = 1 #Add the variable
find_in_batches(:include => options[:include], :batch_size => options[:batch_size]) do |records|
solr_benchmark options[:batch_size], counter do
Sunspot.index(records)
end
Sunspot.commit if options[:batch_commit]
counter += 1 # Increase the variable
end
Sunspot.commit unless options[:batch_commit]
else
Sunspot.index!(all(:include => options[:include]))
end
end
在find_in_batches的前面添加计数器变量,并在find_in_batches块的末尾增加它。 而这个变量用于基准测试。 别担心〜
答案 1 :(得分:1)
只需添加一个注释,现在已在Sunspot 1.2.1
中修复答案 2 :(得分:0)
这是一个非常及时的干预,user34。
只需安装从Ubuntu 10.4运行的Sunspot for Rails 3.0.1。在第一次遇到重建索引的连接问题后(Ubuntu用户需要确保他们运行Javascript,看起来似乎是sudo apt-get install default-jdk),然后我遇到了与Walter一样的'counter'问题。
这是一个新的太阳黑子问题,我想知道吗?
无论如何,你在我需要之前的几个小时就发布了你的回复..据我所见,我现在很好看。
感谢你们两位..(并且总是要小心安装5分钟的声明:))