【问题标题】:Solr 400 Status: Bad RequestSolr 400 状态:错误请求
【发布时间】:2015-04-01 10:47:27
【问题描述】:

我正在尝试使用 solr PHP 客户端。当我尝试添加文档时,它返回 400 状态。我不知道我做错了什么,而且我是 solr 的新手。下面是我的代码和 schema.xml 文件。

我正在使用 solr 4.10.3 和 tomcat 7

提前致谢

$solr = new Apache_Solr_Service('localhost', '8080', '/solr/#/core0');    
if (!$solr->ping()) {
echo 'Solr service not responding.';
exit;
} else {
$fileContent = $_GET['fileContent'];
$title = trim($_GET['title']);
$desription = $_GET['description'];
$fileId = trim($_GET['fileId']);

$docs = array(
    'doc1' => array(
        'id' => 1,
        'fileid' => 'file1',
        'title' => 'title1'
));

$documents = array();
$part = new Apache_Solr_Document();
foreach ($docs as $item => $fields) {                
    foreach ($fields as $key => $value) {
        if (is_array($value)) {                        
            foreach ($value as $data) {
                $part->setMultiValue($key, $data);
            }
        }                    
        else {                           
            $part->$key = $value;
        }
    }                  

    $documents[] = $part;
}   
// Load the documents into the index

try {
    $a = $solr->addDocuments($documents);                
    $solr->commit();
    $solr->optimize();                    
} catch (Exception $e) {
    echo $e->getMessage();
}
die;
$offset = 0;
$limit = 10;  

$queries = array('id:'.$fileId);

foreach ($queries as $query) {
    $response = $solr->search($query, $offset, $limit);
    if ($response->getHttpStatus() == 200) {
        // print_r( $response->getRawResponse() );
        if ($response->response->numFound > 0) {
            echo "$query <br />";
            foreach ($response->response->docs as $doc) {
                echo "$doc->id $doc->title <br />";
            }
            echo '<br />';
        }
    } else {
        echo $response->getHttpStatusMessage();
    }
}
}
}

schema.xml

<schema name="example core zero" version="1.1">
  <fieldtype name="string"  class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
  <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
  <field name="_version_" type="long" indexed="true" stored="true"/>
  <field name="id" type="long" indexed="true" stored="true"/>
  <field name="fileid"    type="string"   indexed="true"  stored="true"  required="true"/>
  <field name="title"     type="string"   indexed="true"  stored="true" />

 <uniqueKey>id</uniqueKey>

</schema>

【问题讨论】:

  • 您的 Solr 日志中可能包含更多信息(请参阅 Solr 管理 UI 中的“日志记录”选项卡)。
  • Logg 显示为 2/2/2015, 6:19:53 PM WARN RequestHandlers 多个 requestHandler 注册到同名:/update 忽略:org.apache.solr.handler.UpdateRequestHandler 2/2/ 2015 年,下午 6:21:39 错误 ShowFileRequestHandler 找不到:admin-extra.menu-bottom.html [/usr/share/solr/example/multicore/core0/conf/admin-extra.menu-bottom.html]

标签: php solr


【解决方案1】:

至少有一个问题是:

Apache_Solr_Service 中的参数:/solr/#/core0 应该是:

/solr/core0

【讨论】:

猜你喜欢
  • 2019-09-13
  • 2017-09-07
  • 1970-01-01
  • 2018-08-09
  • 1970-01-01
  • 1970-01-01
  • 2015-06-12
  • 2021-09-24
  • 2017-12-20
相关资源
最近更新 更多