Sunspot-Rails无法在生产中重新索引

时间:2015-12-09 18:39:20

标签: ruby-on-rails solr lucene sunspot-rails sunspot-solr

我有以下环境:

Solr 5.3.1 Ubuntu 15.04 Rails 4.4.2 太阳黑子-轨

我的solr实例已启动并正在运行,我的生产集合是通过运行

创建的
/opt/solr/bin/solr create -c production

在我的制作环境中,我进入rake以重新索引并运行如下:rake sunspot:solr:reindex。结果是以下http 400错误:

deploy@vps194508:/opt/www/app1/current/bin$ bundle exec rake sunspot:solr:reindex
(in /opt/www/app1/releases/20151209181633)
Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile
rake aborted!
RSolr::Error::Http: RSolr::Error::Http - 400 Bad Request
Error: {'responseHeader'=>{'status'=>400,'QTime'=>4},'error'=>{'msg'=>'undefined field type','code'=>400}}

URI: http://app1.com:8983/solr/production/update?wt=ruby
Request Headers: {"Content-Type"=>"text/xml"}
Request Data: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><query>type:Event</query></delete>"

Backtrace: /opt/www/app1/shared/bundle/ruby/2.2.0/gems/rsolr-1.0.13/lib/rsolr/client.rb:284:in `adapt_response'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/rsolr-1.0.13/lib/rsolr/client.rb:190:in `execute'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/rsolr-1.0.13/lib/rsolr/client.rb:176:in `send_and_receive'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot_rails-2.2.2/lib/sunspot/rails/solr_instrumentation.rb:16:in `block in send_and_receive_with_as_instrumentation'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.2/lib/active_support/notifications.rb:164:in `block in instrument'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.2/lib/active_support/notifications.rb:164:in `instrument'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot_rails-2.2.2/lib/sunspot/rails/solr_instrumentation.rb:15:in `send_and_receive_with_as_instrumentation'
(eval):2:in `post'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/rsolr-1.0.13/lib/rsolr/client.rb:82:in `update'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/rsolr-1.0.13/lib/rsolr/client.rb:146:in `delete_by_query'/opt/www/app1/shared/bundle/ruby/2.2.0/gems/rsolr-1.0.13/lib/rsolr/client.rb:284:in `adapt_response'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/rsolr-1.0.13/lib/rsolr/client.rb:190:in `execute'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/rsolr-1.0.13/lib/rsolr/client.rb:176:in `send_and_receive'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot_rails-2.2.2/lib/sunspot/rails/solr_instrumentation.rb:16:in `block in send_and_receive_with_as_instrumentation'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.2/lib/active_support/notifications.rb:164:in `block in instrument'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.2/lib/active_support/notifications.rb:164:in `instrument'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot_rails-2.2.2/lib/sunspot/rails/solr_instrumentation.rb:15:in `send_and_receive_with_as_instrumentation'
(eval):2:in `post'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/rsolr-1.0.13/lib/rsolr/client.rb:82:in `update'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/rsolr-1.0.13/lib/rsolr/client.rb:146:in `delete_by_query'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot-2.2.2/lib/sunspot/indexer.rb:68:in `remove_all'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot-2.2.2/lib/sunspot/session.rb:197:in `block in remove_all'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot-2.2.2/lib/sunspot/session.rb:197:in `each'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot-2.2.2/lib/sunspot/session.rb:197:in `remove_all'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot-2.2.2/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `remove_all'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot-2.2.2/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb:17:in `method_missing'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot-2.2.2/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `remove_all'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot-2.2.2/lib/sunspot.rb:502:in `remove_all'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot_rails-2.2.2/lib/sunspot/rails/searchable.rb:190:in `solr_remove_all_from_index'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot_rails-2.2.2/lib/sunspot/rails/searchable.rb:209:in `solr_reindex'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot_rails-2.2.2/lib/sunspot/rails/tasks.rb:60:in `block (4 levels) in <top (required)>'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot-2.2.2/lib/sunspot/class_set.rb:16:in `each'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot-2.2.2/lib/sunspot/class_set.rb:16:in `each'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot_rails-2.2.2/lib/sunspot/rails/tasks.rb:59:in `block (3 levels) in <top (required)>'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot_rails-2.2.2/lib/sunspot/rails/tasks.rb:71:in `with_session'
/opt/www/app1/shared/bundle/ruby/2.2.0/gems/sunspot_rails-2.2.2/lib/sunspot/rails/tasks.rb:19:in `block (2 levels) in <top (required)>'
Tasks: TOP => sunspot:solr:reindex => sunspot:reindex
(See full trace by running task with --trace)

有人可以解释为什么会发生这种情况以及如何解决这个问题。在开发过程中一切正常。在生产中,我的生产集合是空的,因此尝试重新索引,但它失败了,这个错误的请求400错误。

1 个答案:

答案 0 :(得分:0)

好吧,我错过了一个重要的配置点,我在sunspot-rails文档中没有看到。

当您运行sunspot-rails的rake install命令时,它会在rails项目的根目录中创建一个solr目录。

其中有两个重要文件:

<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title></title>
<META NAME="DESCRIPTION" CONTENT=" ">
<META NAME="KEYWORDS" CONTENT="">
<link rel="stylesheet" href="style.css" type="text/css">
</head>

<body>
<?Php
require "config.php";
$confirm_id=$_GET['confirm_id'];

$count=$dbo->prepare("
    select confirm_id,email,email_id,word,status,UNIX_TIMESTAMP(dtt) as stored_time 
    from nl_confirm where confirm_id=:confirm_id");
$count->bindParam(":confirm_id",$confirm_id,PDO::PARAM_INT,4);

if($count->execute()){
    $row = $count->fetch(PDO::FETCH_OBJ);
    if($row->confirm_id >0){
        ///////// checking the input data with record ////////////
        $flag='OK';
        $msg='';
        if($row->email_id <> $_GET['email_id']){
            $flag='NOTOK';
            $msg.='<br>Wrong Email address ';
        }

        if($row->word  <> $_GET['token']){
            $flag='NOTOK';
            $msg.='<br>Wrong Token';
        }

        if($row->email <> $_GET['email']){
            $flag='NOTOK';
            $msg.='<br>Wrong Email address ';
        }
        $present_time=time();
        $stored_time=$row->stored_time;
        //echo 'stored time : '.$row->stored_time.'<br>Present time : '. $present_time.'<br>' ;
        if(($present_time-$stored_time)>300){ 
            //// Within 300 seconds user needs to confirm subscription , you can adjust this duration ////
            $flag='NOTOK';
            $msg.='<br>It is too long. Your confirmation time expired. <a href=subscribe.php>Subscribe again</a> ';
        }

        if($row->status == 'A'){
            $flag='NOTOK';
            $msg.='<br>You have already confirmed your subscription. ' ;
        }

        if($flag=='OK'){
            $count1=$dbo->prepare("update nl_email set status='A' where email_id=$row->email_id");
            if($count1->execute()){
                $count2=$dbo->prepare("delete from  nl_confirm where confirm_id=$row->confirm_id");
                $count2->execute();
                echo "Thank you for confirming your email address. You are a subscriber of our newsletter script.
    <br> Any time you can unsubscribe by visiting a link in your newsletter. ";
            }
        }
        else{echo $msg.'<br>';}

        //////////// end of checking data /////////////
    }else{ // if condition to check confirm_id > 0
        echo " We don't have any record of pending confirmation against your email address,<br>
     you can check by <a href=subscribe.php>subscribing</a> again or contact site admin.";
    } // end of if else to check confirm_id >0
}else{ // if execute() fails 

    print_r($dbo->errorInfo()); 
}

//////////////////////////////////////////////

echo "</body></html>";

这两个xml文件都需要复制到/ var / solr / data / production / conf目录 - 或者您的集合的conf目录。当我这样做,重新启动solr并尝试重新索引它的工作原理!瞧。