您好,欢迎访问一九零五行业门户网

Solr + php 报400

初学solr从网上下载了一个例子,但是运行时报以下错误:
fatal error: uncaught exception 'apache_solr_httptransportexception' with message ''400' status: bad request' in /applications/xampp/xamppfiles/htdocs/phpsolr/solrphpclient/apache/solr/service.php:338 stack trace: #0 /applications/xampp/xamppfiles/htdocs/phpsolr/solrphpclient/apache/solr/service.php(1170): apache_solr_service->_sendrawget('http://localhos...') #1 /applications/xampp/xamppfiles/htdocs/phpsolr/index.php(78): apache_solr_service->search('name: ', 0, 10) #2 {main} thrown in /applications/xampp/xamppfiles/htdocs/phpsolr/solrphpclient/apache/solr/service.php on line 338

从网上找过答案,大部分都说是schema.xml中没有定义field,但是我确认我使用的field都说定义了,实在是不知道为什么了,希望有人知道!!
回复内容: 初学solr从网上下载了一个例子,但是运行时报以下错误:
fatal error: uncaught exception 'apache_solr_httptransportexception' with message ''400' status: bad request' in /applications/xampp/xamppfiles/htdocs/phpsolr/solrphpclient/apache/solr/service.php:338 stack trace: #0 /applications/xampp/xamppfiles/htdocs/phpsolr/solrphpclient/apache/solr/service.php(1170): apache_solr_service->_sendrawget('http://localhos...') #1 /applications/xampp/xamppfiles/htdocs/phpsolr/index.php(78): apache_solr_service->search('name: ', 0, 10) #2 {main} thrown in /applications/xampp/xamppfiles/htdocs/phpsolr/solrphpclient/apache/solr/service.php on line 338

从网上找过答案,大部分都说是schema.xml中没有定义field,但是我确认我使用的field都说定义了,实在是不知道为什么了,希望有人知道!!
首先我要说的是 ... 并不是所有的牛奶都叫某某苏 ... 也并不是所有的错误都叫 404 ...
你的这个错误是 '400' status: bad request ... 而不是 404 ...
一般来说这个错误出现的原因就如你所说 ... 是 schema.xml 中没有定义 field ...
但是具体如何还要分析 ...
apache_solr_service 这个类不会回传 solr 的内部错误 ... 所以我们要用其他方式解决 ...
第一种方式比较简单 ... 查看 solr 的 log ... 会有类似于下面一行的内容 ...
severe: org.apache.solr.common.solrexception: ****其中 **** 就是具体造成错误的原因 ...
第二种方法 ... 使用 solr 自带的一个工具叫 solr admin ...
在这个工具里你可以手动输入查询 ... 如果查询无效的话也会显示出详细的错误信息 ...
以你描述的情况来说 ... 只需要输入 name: 然后点确定就好 ...
有了错误信息才能知道如何解决这个问题 ... 不然只能靠东一榔头西一棒子的猜测 ... 费时费力 ...
只说 solr 报了错 ... 你也不知道为什么只希望别人知道 ... 很遗憾 ... 我觉得没有人会知道 ...
话可能说的有点重 ... 抱歉 ... 但道理是这样 ...
先要学会良好的描述自己遇到的问题才能希望别人可以准确高效的解决问题 ... 你说是不是 ..?
注意你在调用 apache_solr_service() 构造函数时的传参。有一个陷阱是第五个参数即 $compatibilitylayer 需传递的参数应根据你的 solr 服务器版本进行变化,如你是 solr 4.0+ 应传递 new apache_solr_compatibility_solr4compatibilitylayer。
原因是 solr3 和 solr4 生成的 xml 格式不同,有一些参数在使用时有兼容问题,从而触发 http 400 bad request 问题。目前的 solr-php-client 默认使用的是 solr3 标准。
希望能帮助到你。
其它类似信息

推荐信息