“无法将数组添加到 BooleanQuery” 雪貂在轨道上的错误

发布于 2024-07-08 02:02:48 字数 8121 浏览 11 评论 0原文

我正在尝试在我的 RoR 网站中使用一个简单的搜索表单。 我有以下代码:(

在note_controller.rb中)

  def search
    @results = Note.find_with_ferret(params[:term]).sort_by(&:ferret_rank)

    respond_to do |format|
      format.html
      format.xml { render :xml => @nootes }
    end
  end

(在note.rb中)

class Note < ActiveRecord::Base
  acts_as_ferret :fields => [ :title, :body ]
end

(在index.html.erb中)

<%= form_tag :action => 'search'%>
<%= text_field 'term', nil  %>
  <%= submit_tag 'Search' %>
</form>

(在search.html.erb中)

<h1><%= pluralize(@results.size, 'result') %></h1>

<ul>
<% for result in @results %>
  <li><%= result.ferret_score %>: <%= link_to result.tile, result %></li>
<% end %>
</ul>

正如您希望从上面看到的那样,我有一个模型我已经告诉acts_as_ferret了。 然后,我的控制器中有一个搜索操作,它尝试渲染到 search.html.erb 视图。 我在索引视图中有一个可以进行搜索的表单。 但是,当我运行此命令时,我收到以下错误:

无法将数组添加到 BooleanQuery

我想我的表单做错了,所以雪貂以某种方式获取了错误的数据。 我所做的 form_tag 的方法正确吗? 任何帮助将非常感激。

更新:

以下是我似乎可以从日志中提取的唯一内容。 我正在使用 Heroku,它似乎没有提供相当标准的日志文件。 希望这有帮助。

Processing NotesController#search (for 152.78.202.74, 127.0.0.1 at 2008-10-25 07:32:23)
[POST] Session ID: BAh7BzoMY3NyZl9pZCIlZmEyMzcxZTdlYTUyODRkNzlmMzdjZWJlOGNlOGYz M2UiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh c2h7AAY6CkB1c2VkewA=--450f51b45e38cba302e8ac6bd9b03c7ae79981e9
Parameters: {"commit"=>"Search", "term"=>["wheelbarrow"], "authenticity_token"=>"1879a835ded87e7a28861725ec668b690de6b7f5", "action"=>"search", "controller"=>"notes"}
configured index for class Note: {
    :index_dir=>"/mnt/home/userapps/38385/index/development/note",
    :mysql_fast_batches=>true, :name=>:note, :single_index=>false,
    :index_base_dir=>"/mnt/home/userapps/38385/index/development/note",
    :reindex_batch_size=>1000,
    :registered_models=>[Note(id: integer, title: string, body: text, created_at: datetime, updated_at: datetime)],
    :ferret=>{:dir=>#,
    :key=>[:id, :class_name],
    :or_default=>false,
    :handle_parse_errors=>true,
    :auto_flush=>true,
    :create_if_missing=>true,
    :path=>"/mnt/home/userapps/38385/index/development/note",
    :default_field=>[:title, :body],
    :analyzer=>#,
    :lock_retry_time=>2},
    :ferret_fields=>{:title=>{:via=>:title, :term_vector=>:with_positions_offsets, :boost=>1.0, :store=>:no, :highlight=>:yes, :index=>:yes},
    :body=>{:via=>:body, :term_vector=>:with_positions_offsets, :boost=>1.0, :store=>:no, :highlight=>:yes, :index=>:yes}},
    :fields=>[:title, :body],
    :raise_drb_errors=>false,
    :user_default_field=>nil,
    :enabled=>true}

ArgumentError (Cannot add Array to a BooleanQuery): /vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:124:in `add_query'
    /vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:124:in `scope_query_to_models'
    /vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:102:in `find_ids'
    /vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:85:in `find_id_model_arrays'
    /vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:41:in `ar_find'
    /vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:12:in `find_records'
    /vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb:342:in `find'
    /vendor/plugins/acts_as_ferret/lib/class_methods.rb:155:in `find_with_ferret'
    /app/controllers/notes_controller.rb:14:in `search'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `send'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `perform_action_without_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:580:in `call_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:573:in `perform_action_without_benchmark'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue_without_timeout'
    /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue_without_timeout'
    /home/userapps_plugins/preload/request_timeout/lib/request_timeout.rb:9:in `perform_action_without_rescue'
    /usr/lib/ruby/1.8/timeout.rb:48:in `timeout'
    /home/userapps_plugins/preload/request_timeout/lib/request_timeout.rb:8:in `perform_action_without_rescue'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/rescue.rb:201:in `perform_action_without_caching'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/query_cache.rb:8:in `cache'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `send'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `process_without_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:569:in `process_without_session_management_support'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/session_management.rb:130:in `process'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:389:in `process'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:149:in `handle_request'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in `dispatch'
    /usr/lib/ruby/1.8/thread.rb:135:in `synchronize'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/rack/adapter/rails.rb:54:in `serve_rails'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/rack/adapter/rails.rb:74:in `call'
    /home/heroku_rack/lib/toolbar.rb:16:in `call'
    /usr/lib/ruby/gems/1.8/gems/rack-0.4.0/lib/rack/urlmap.rb:42:in `call'
    /usr/lib/ruby/gems/1.8/gems/rack-0.4.0/lib/rack/urlmap.rb:35:in `each'
    /usr/lib/ruby/gems/1.8/gems/rack-0.4.0/lib/rack/urlmap.rb:35:in `call'
    /usr/lib/ruby/gems/1.8/gems/rack-0.4.0/lib/rack/builder.rb:53:in `call'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/connection.rb:59:in `pre_process'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/connection.rb:50:in `process'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/connection.rb:35:in `receive_data'
    /usr/lib/ruby/gems/1.8/gems/eventmachine-0.12.0/lib/eventmachine.rb:224:in `run_machine'
    /usr/lib/ruby/gems/1.8/gems/eventmachine-0.12.0/lib/eventmachine.rb:224:in `run'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/backends/base.rb:45:in `start'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/server.rb:146:in `start'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/controllers/controller.rb:79:in `start'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/runner.rb:166:in `send'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/runner.rb:166:in `run_command'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/runner.rb:136:in `run!'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/bin/thin:6 /usr/bin/thin:19:in `load'
    /usr/bin/thin:19 Rendering /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/templates/res

I'm trying to get a simple search form working in my RoR site. I've got the following code:

(in note_controller.rb)

  def search
    @results = Note.find_with_ferret(params[:term]).sort_by(&:ferret_rank)

    respond_to do |format|
      format.html
      format.xml { render :xml => @nootes }
    end
  end

(in note.rb)

class Note < ActiveRecord::Base
  acts_as_ferret :fields => [ :title, :body ]
end

(in index.html.erb)

<%= form_tag :action => 'search'%>
<%= text_field 'term', nil  %>
  <%= submit_tag 'Search' %>
</form>

(in search.html.erb)

<h1><%= pluralize(@results.size, 'result') %></h1>

<ul>
<% for result in @results %>
  <li><%= result.ferret_score %>: <%= link_to result.tile, result %></li>
<% end %>
</ul>

As you can hopefully see from the above I've got a model which I've told to acts_as_ferret. I've then got a search action in my controller, which tries to render to the search.html.erb view. I've got a form in the index view which does a search. However, when I run this I get the following error:

Cannot add Array to a BooleanQuery

I guess I'm doing something wrong with my form so that ferret is getting the wrong data somehow. Is the form_tag thing I've done the right way to do it? Any help would be much appreciated.

Update:

Below is the only bit I can seem to extract from the log. I'm using Heroku and it doesn't seem to give quite the stardard log files. Hope this is helpful.

Processing NotesController#search (for 152.78.202.74, 127.0.0.1 at 2008-10-25 07:32:23)
[POST] Session ID: BAh7BzoMY3NyZl9pZCIlZmEyMzcxZTdlYTUyODRkNzlmMzdjZWJlOGNlOGYz M2UiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh c2h7AAY6CkB1c2VkewA=--450f51b45e38cba302e8ac6bd9b03c7ae79981e9
Parameters: {"commit"=>"Search", "term"=>["wheelbarrow"], "authenticity_token"=>"1879a835ded87e7a28861725ec668b690de6b7f5", "action"=>"search", "controller"=>"notes"}
configured index for class Note: {
    :index_dir=>"/mnt/home/userapps/38385/index/development/note",
    :mysql_fast_batches=>true, :name=>:note, :single_index=>false,
    :index_base_dir=>"/mnt/home/userapps/38385/index/development/note",
    :reindex_batch_size=>1000,
    :registered_models=>[Note(id: integer, title: string, body: text, created_at: datetime, updated_at: datetime)],
    :ferret=>{:dir=>#,
    :key=>[:id, :class_name],
    :or_default=>false,
    :handle_parse_errors=>true,
    :auto_flush=>true,
    :create_if_missing=>true,
    :path=>"/mnt/home/userapps/38385/index/development/note",
    :default_field=>[:title, :body],
    :analyzer=>#,
    :lock_retry_time=>2},
    :ferret_fields=>{:title=>{:via=>:title, :term_vector=>:with_positions_offsets, :boost=>1.0, :store=>:no, :highlight=>:yes, :index=>:yes},
    :body=>{:via=>:body, :term_vector=>:with_positions_offsets, :boost=>1.0, :store=>:no, :highlight=>:yes, :index=>:yes}},
    :fields=>[:title, :body],
    :raise_drb_errors=>false,
    :user_default_field=>nil,
    :enabled=>true}

ArgumentError (Cannot add Array to a BooleanQuery): /vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:124:in `add_query'
    /vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:124:in `scope_query_to_models'
    /vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:102:in `find_ids'
    /vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:85:in `find_id_model_arrays'
    /vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:41:in `ar_find'
    /vendor/plugins/acts_as_ferret/lib/ferret_find_methods.rb:12:in `find_records'
    /vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb:342:in `find'
    /vendor/plugins/acts_as_ferret/lib/class_methods.rb:155:in `find_with_ferret'
    /app/controllers/notes_controller.rb:14:in `search'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `send'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `perform_action_without_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:580:in `call_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:573:in `perform_action_without_benchmark'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue_without_timeout'
    /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue_without_timeout'
    /home/userapps_plugins/preload/request_timeout/lib/request_timeout.rb:9:in `perform_action_without_rescue'
    /usr/lib/ruby/1.8/timeout.rb:48:in `timeout'
    /home/userapps_plugins/preload/request_timeout/lib/request_timeout.rb:8:in `perform_action_without_rescue'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/rescue.rb:201:in `perform_action_without_caching'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:13:in `perform_action'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/query_cache.rb:8:in `cache'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/caching/sql_cache.rb:12:in `perform_action'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `send'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:529:in `process_without_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/filters.rb:569:in `process_without_session_management_support'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/session_management.rb:130:in `process'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:389:in `process'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:149:in `handle_request'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:107:in `dispatch'
    /usr/lib/ruby/1.8/thread.rb:135:in `synchronize'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:104:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi'
    /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/dispatcher.rb:35:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/rack/adapter/rails.rb:54:in `serve_rails'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/rack/adapter/rails.rb:74:in `call'
    /home/heroku_rack/lib/toolbar.rb:16:in `call'
    /usr/lib/ruby/gems/1.8/gems/rack-0.4.0/lib/rack/urlmap.rb:42:in `call'
    /usr/lib/ruby/gems/1.8/gems/rack-0.4.0/lib/rack/urlmap.rb:35:in `each'
    /usr/lib/ruby/gems/1.8/gems/rack-0.4.0/lib/rack/urlmap.rb:35:in `call'
    /usr/lib/ruby/gems/1.8/gems/rack-0.4.0/lib/rack/builder.rb:53:in `call'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/connection.rb:59:in `pre_process'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/connection.rb:50:in `process'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/connection.rb:35:in `receive_data'
    /usr/lib/ruby/gems/1.8/gems/eventmachine-0.12.0/lib/eventmachine.rb:224:in `run_machine'
    /usr/lib/ruby/gems/1.8/gems/eventmachine-0.12.0/lib/eventmachine.rb:224:in `run'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/backends/base.rb:45:in `start'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/server.rb:146:in `start'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/controllers/controller.rb:79:in `start'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/runner.rb:166:in `send'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/runner.rb:166:in `run_command'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/lib/thin/runner.rb:136:in `run!'
    /usr/lib/ruby/gems/1.8/gems/thin-0.8.2/bin/thin:6 /usr/bin/thin:19:in `load'
    /usr/bin/thin:19 Rendering /usr/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/templates/res

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

☆獨立☆ 2024-07-15 02:02:48

我不记得曾经见过那个雪貂错误。 有两个基本诊断:进入脚本/控制台,然后执行以下操作

Notes.find_with_ferret("some term that should be in index") 

,然后看看当您删除索引目录(/appname/index/development)时会发生什么,执行另一个 find_with_ferret 来强制重新索引?

背景信息:“标题”和“正文”列是在表中,还是在实例方法中计算,或者是来自例如 has_many 的子项? 如果表中的字段,迁移中声明的“title”和“body”是什么列类型,它们是什么类型的 mySQL 列类型?

包含您的操作系统、您正在使用的 ruby​​、rails、ferret 和 a_a_f 的版本通常也很有帮助。

I can't recall ever seeing that ferret error. There's two basic diagnostics: go into script/console, and do

Notes.find_with_ferret("some term that should be in index") 

And then see what happens when you remove the indexes' directory (/appname/index/development), do another find_with_ferret to force reindex?

Background info: are "title" and "body" columns in table, or calculated in instance method, or children from e.g. has_many? If fields in the table, what column types are "title" and "body" declared at in the migration, and what kind fo mySQL column types are they?

Also usually helpful to include your O/S, the versions of ruby, rails, ferret and a_a_f you're using.

冬天旳寂寞 2024-07-15 02:02:48

我已经删除了索引目录,它似乎已经重新生成,但现在我在控制台上的搜索没有给出任何结果。 在删除索引目录之前,我在控制台上得到了结果,但在我的应用程序中的表单中使用时却没有得到结果。

标题和正文都是我的 MySQL 表中的列。 它们是使用 Rails 迁移分别作为字符串和文本类型创建的。

我在 Heroku 上运行 - 所以我不完全确定什么操作系统(可能是 Linux)或版本,尽管我知道它至少是 Rails 2.1。 我似乎也找不到 AAF 的版本号 - 但我猜它是相对较新的。

抱歉,我无法提供更多帮助 - 我说的还有用吗?

罗宾

I've removed the index directory, and it seems to have regenerated itself but now my searches on the console are giving no results. Before I deleted the index directory I got results on the console, but not when used from the form in my app.

Title and Body are both columns in my MySQL table. They were created using Rails migrations as type string and text respectively.

I'm running on Heroku - so I'm not entirely sure what OS (probably linux) or versions though I know it is at least rails 2.1. I also can't seem to find a version number for AAF - but I guess it's relatively recent.

Sorry I can't be more help - is what I've said any use?

Robin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文