3

我无法索引我的数据库以使用 sunspot_rails 进行搜索。我收到以下错误:

执行 sunspot:reindex rake 中止!未定义的局部变量或方法“计数器”

运行 rake sunspot:reindex 后,我得到以下输出。我是 Rails 的新手。我想将 sunspot_rails 添加到我的项目中以添加搜索功能(希望使用 Heroku 部署项目)。

我正在使用 Rails 3。我按照此处的说明进行操作:https ://github.com/outoftime/sunspot/blob/master/sunspot_rails/README.rdoc 。我诊断问题的各种其他尝试包括:

  • 除了 sunspot_rails 之外还安装 sunspot。
  • 我最终得到了 sunspot_rails v. 1.2.0 和 1.2.1,所以我卸载了 1.2.1,因为我有 sunspot_rails 1.2.0。
  • 安装了我理解的 nokogiri gem 是 sunspot_rails 的依赖项。
  • 按照此处安装 nokogiri 的说明单独安装 libxml2:http ://www.engineyard.com/blog/2010/getting-started-with-nokogiri/

    ** 调用 sunspot:reindex (first_time) ** 调用环境 (first_time) ** 执行环境 ** 执行 sunspot:reindex rake 中止!未定义的局部变量或方法counter' for [removed pound]<Class:0x10359aef8> /Library/Ruby/Gems/1.8/gems/activerecord-3.0.3/lib/active_record/base.rb:1008:inmethod_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:infind_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:infind_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:insolr_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:incall' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:inexecute' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in每个' /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:ininvoke_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:ininvoke_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:ininvoke_task' /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:ineach' /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:2068:instandard_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:2001:inrun' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:instandard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in运行' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31 /usr/bin/rake:19:in `load' /usr/bin/rake:19

这是我在课堂上想要搜索的内容:

  searchable do
    text :fname
    text :mname
    text :lname, :default_boost => 2   end

任何帮助将不胜感激!

4

3 回答 3

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 块的末尾增加它。这个变量用于基准测试。别担心~

于 2011-02-17T16:51:45.823 回答
1

只是要添加一个注释,这现在已在 Sunspot 1.2.1 中修复

于 2011-03-04T17:20:22.960 回答
0

这是一个非常及时的干预,user34。

只需为从 Ubuntu 10.4 运行的 Rails 3.0.1 安装 Sunspot。在第一次偶然发现重新索引的连接问题之后(Ubuntu 用户需要确保他们运行了 Javascript,似乎 - sudo apt-get install default-jdk),然后我遇到了与 Walter 相同的问题,使用“counter”。

我想知道这是一个新的太阳黑子问题吗?

无论如何,你在我需要它的几个小时前发布了你的回复……据我所知,我现在看起来很好。

感谢你们俩..(并且始终警惕 5 分钟的安装要求 :))

于 2011-02-17T19:11:05.003 回答