2

我正在使用默认的 PHP Solr 客户端: http ://php.net/manual/en/book.solr.php 到现在为止,结果令人惊叹,所以我决定继续使用 Solr,并开发“建议”服务:

我是根据: http ://wiki.apache.org/solr/Suggester/ 它也很好用 - 但我不知道如何使用 PHP 客户端查询它。

这就是我查询文档的方式:

http://localhost:8080/solr/subject_offers/select/?q=string_to_search

这就是我查询建议的方式:

http://localhost:8080/solr/subject_offers/suggest/?q=string_to_suggest

如您所见,建议服务具有不同的 RequestHandler(称为“建议”)。如何在客户端更改它?

更新: 我使用 cURL 从 Solr 检索响应 XML。但我仍然想返回一个 Solr 响应对象,所以我使用“SolrUtils::digestXmlResponse($xml, SolrResponse::PARSE_SOLR_OBJ)”。不幸的是,对于有效的 XML,我收到“错误取消序列化响应”的错误:

<response><lst name="responseHeader"><int name="status">0</int><int name="QTime">2</int></lst><lst name="spellcheck"><lst name="suggestions"><lst name="the"><int name="numFound">1</int><int name="startOffset">9</int><int name="endOffset">12</int><arr name="suggestion"><str>the</str></arr></lst><lst name="the"><int name="numFound">1</int><int name="startOffset">33</int><int name="endOffset">36</int><arr name="suggestion"><str>the</str></arr></lst><lst name="collation"><str name="collationQuery">name:for the d^5 description:for the d^0.4</str><int name="hits">1</int><lst name="misspellingsAndCorrections"><str name="the">the</str><str name="the">the</str></lst></lst></lst></lst><result name="response" numFound="1" start="0"><doc><str name="1_on_1_price">9,USD</str><float name="avarage_rating">0.0</float><arr name="categories"><str>2,2,3</str></arr><int name="category_id">3</int><arr name="description"><str>was named for the directo</str><str>The Manchesowned by Peel Ports</str></arr><bool name="is_public">true</bool><str name="language">he</str><int name="lesson_type">0</int><str name="name">was named for the directo</str><int name="subject_id">12</int></doc></result></response>

请指教,谢谢!

4

2 回答 2

5

我有同样的问题,我在源代码中找到了答案。解决方案是:

$client = new SolrClient($options);
$client->setServlet(SolrClient::SEARCH_SERVLET_TYPE, "request_handler_name");
于 2013-02-02T23:32:36.190 回答
0

您可以使用 PHP 的 CURL 扩展来执行此操作。一个小例子是:

$url = 'http://localhost:8080/solr/subject_offers/select/?';
$to_post = array('q' => urlencode('string_to_search'),
                 'other'=> urlencode('somthing_else'));
foreach($to_post as $key=>$value) {
    $string .= $key.'='.$value.'&';
}
rtrim($string, '&');

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($to_post));
curl_setopt($ch,CURLOPT_POSTFIELDS,$string);

$result = curl_exec($ch);
curl_close($ch);

希望有帮助...

于 2012-07-19T20:10:28.630 回答