2008-10-25 4 views
0

J'essaie d'obtenir un formulaire de recherche simple sur mon site RoR. J'ai le code suivant:Erreur "Impossible d'ajouter un tableau à BooleanQuery" avec le furet sur les rails

(en 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 

(en note.rb)

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

(en index.html.erb)

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

(dans 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> 

Comme vous pouvez l'espérer voir de ce qui précède, j'ai un modèle que j'ai dit à acts_as_ferret. J'ai alors une action de recherche dans mon contrôleur, qui essaie de rendre à la vue search.html.erb. J'ai un formulaire dans l'index qui fait une recherche. Cependant, quand je lance ce que je reçois l'erreur suivante:

Cannot add Array to a BooleanQuery

Je suppose que je fais quelque chose de mal avec mon formulaire afin que ferret obtient des données erronées en quelque sorte. Est-ce que la chose form_tag que j'ai fait est la bonne façon de le faire? Toute aide serait très appréciée.

Mise à jour:

Voici le seul bit je peux sembler extraire du journal. J'utilise Heroku et il ne semble pas donner assez de fichiers journaux standards. J'espère que c'est utile.

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

postez les lignes de journal autour de votre erreur, s'il vous plaît? –

Répondre

1

Je ne me souviens pas avoir jamais vu cette erreur de furet. Il y a deux diagnostics de base: allez dans le script/console, et faire

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

Et puis voir ce qui se passe lorsque vous supprimez le répertoire des index (/ appname/index/développement), faire une autre find_with_ferret pour forcer réindexation? Informations sur l'arrière-plan: sont des colonnes "title" et "body" dans une table, ou calculées dans une méthode d'instance, ou des enfants de par ex. a beaucoup? Si les champs dans la table, quels types de colonnes sont "title" et "body" déclarés lors de la migration, et quel type de types de colonne mySQL sont-ils?

Aussi généralement utile d'inclure votre O/S, les versions de ruby, rails, furet et a_a_f que vous utilisez.

0

J'ai supprimé le répertoire d'index, et il semble s'être régénéré mais maintenant mes recherches sur la console ne donnent aucun résultat. Avant que j'ai supprimé le répertoire d'index j'ai eu des résultats sur la console, mais pas quand utilisé du formulaire dans mon application. Title et Body sont les deux colonnes de ma table MySQL. Ils ont été créés à l'aide des migrations Rails en tant que chaîne de caractères et texte respectivement.

Je cours sur Heroku - donc je ne suis pas tout à fait sûr quel système d'exploitation (probablement linux) ou versions si je sais qu'il est au moins rails 2.1. Je n'arrive pas non plus à trouver un numéro de version pour AAF - mais je suppose que c'est relativement récent.

Désolé je ne peux pas être plus d'aide - est ce que j'ai dit toute utilisation?

Robin

Questions connexes