如何使用 sunspot solr 索引文本(大数据)字段
Posted
技术标签:
【中文标题】如何使用 sunspot solr 索引文本(大数据)字段【英文标题】:How to index a text(large data) field using sunspot solr 【发布时间】:2014-10-26 17:23:47 【问题描述】:在 rails 4.0.2 中,我使用 sunspot solr 作为搜索引擎。在这里,有一个文本字段包含带有特殊字符的大文本(数据)。
在运行重新索引命令时,我收到类似 Backtrace: /home/shruthi/.rvm/gems/ruby-2.1.2/gems/rsolr-1.0.10/lib/rsolr/client.rb:283:in 'adapt_response'...
的错误
在模型中,
searchable do
string :cv_content
end
使用宝石是,
sunspot (2.1.1)
sunspot_rails (2.1.1)
sunspot_solr (2.1.1)
如何解决重新索引问题?
完全错误:
Backtrace: /home/shruthi/.rvm/gems/ruby-2.1.2/gems/rsolr-1.0.10/lib/rsolr/client.rb:283:in
adapt_response'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rsolr-1.0.10/lib/rsolr/client.rb:190:in execute'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rsolr-1.0.10/lib/rsolr/client.rb:176:in
send_and_receive'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot_rails-2.1.1/lib/sunspot/rails/solr_instrumentation.rb:16:in block in send_and_receive_with_as_instrumentation'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/activesupport-4.0.2/lib/active_support/notifications.rb:159:in
block in instrument'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in instrument'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/activesupport-4.0.2/lib/active_support/notifications.rb:159:in
instrument'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot_rails-2.1.1/lib/sunspot/rails/solr_instrumentation.rb:15:in send_and_receive_with_as_instrumentation'
(eval):2:in
post'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rsolr-1.0.10/lib/rsolr/client.rb:82:in update'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rsolr-1.0.10/lib/rsolr/client.rb:102:in
add'/home/shruthi/.rvm/gems/ ruby-2.1.2/gems/rsolr-1.0.10/lib/rsolr/client.rb:283:in adapt_response'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rsolr-1.0.10/lib/rsolr/client.rb:190:in
execute'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rsolr-1.0.10/lib/rsolr/client.rb:176:in send_and_receive'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot_rails-2.1.1/lib/sunspot/rails/solr_instrumentation.rb:16:in
block in send_and_receive_with_as_instrumentation'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/activesupport-4.0.2/lib/active_support/notifications.rb:159:in block in instrument'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in
instrument'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/activesupport-4.0.2/lib/active_support/notifications.rb:159:in instrument'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot_rails-2.1.1/lib/sunspot/rails/solr_instrumentation.rb:15:in
send_and_receive_with_as_instrumentation'
(eval):2:in post'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rsolr-1.0.10/lib/rsolr/client.rb:82:in
update'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rsolr-1.0.10/lib/rsolr/client.rb:102:in add'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot-2.1.1/lib/sunspot/indexer.rb:107:in
add_documents'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot-2.1.1/lib/sunspot/indexer.rb:30:in add'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot-2.1.1/lib/sunspot/session.rb:91:in
index'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot-2.1.1/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in index'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot-2.1.1/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb:17:in
method_missing'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot-2.1.1/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in index'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot-2.1.1/lib/sunspot.rb:184:in
index'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot_rails-2.1.1/lib/sunspot/rails/searchable.rb:257:in block (2 levels) in solr_index'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot_rails-2.1.1/lib/sunspot/rails/searchable.rb:360:in
solr_benchmark'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot_rails-2.1.1/lib/sunspot/rails/searchable.rb:256:in block in solr_index'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/activerecord-4.0.2/lib/active_record/relation/batches.rb:75:in
find_in_batches'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/activerecord-deprecated_finders-1.0.3/lib/active_record/deprecated_finders/relation.rb:70:in find_in_batches'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot_rails-2.1.1/lib/sunspot/rails/searchable.rb:254:in
solr_index'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot_rails-2.1.1/lib/sunspot/rails/searchable.rb:203:in solr_reindex'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot_rails-2.1.1/lib/sunspot/rails/tasks.rb:57:in
block (4 级) in '
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot-2.1.1/lib/sunspot/class_set.rb:16:in each'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot-2.1.1/lib/sunspot/class_set.rb:16:in
each'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot_rails-2.1.1/lib/sunspot/rails/tasks.rb:56:in block (3 levels) in <top (required)>'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot_rails-2.1.1/lib/sunspot/rails/tasks.rb:68:in
with_session'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/sunspot_rails-2.1.1/lib/sunspot/rails/tasks.rb:19:in block (2 levels) in <top (required)>'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:240:in
call'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:240:in block in execute'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:235:in
each'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:235:in execute'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:179:in
block in invoke_with_call_chain'
/home/shruthi/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in mon_synchronize'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:172:in
invoke_with_call_chain'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/task.rb:165:in invoke'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:150:in
invoke_task'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:106:in block (2 levels) in top_level'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:106:in
each'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:106:in block in top_level'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:115:in
run_with_threads'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:100:in top_level'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:78:in
block in run'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:176:in standard_exception_handling'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/lib/rake/application.rb:75:in
run'
/home/shruthi/.rvm/gems/ruby-2.1.2/gems/rake-10.3.2/bin/rake:33:in <top (required)>'
/home/shruthi/.rvm/gems/ruby-2.1.2/bin/rake:23:in
load'
/home/shruthi/.rvm/gems/ruby-2.1.2/bin/rake:23:in <main>'
/home/shruthi/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in
eval'
/home/shruthi/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in <main>'
Tasks: TOP => sunspot:reindex
【问题讨论】:
我们可以得到完整的错误吗?将有助于排除故障。 【参考方案1】:从票 solr, sunspot, bad request, illegal character 推荐我使用建议的代码创建了 config/initializers/sunspot.rb,它成功了。
这是该票证中首次建议代码的问题。 https://github.com/sunspot/sunspot/issues/570
【讨论】:
以上是关于如何使用 sunspot solr 索引文本(大数据)字段的主要内容,如果未能解决你的问题,请参考以下文章