【问题标题】:How to change the request handler using the PECL PHP solr extension如何使用 PECL PHP solr 扩展更改请求处理程序
【发布时间】:2012-07-19 20:00:22
【问题描述】:

我正在使用默认的 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>

请指教, 谢谢!

【问题讨论】:

    标签: php solr cakephp-2.0


    【解决方案1】:

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

    $client = new SolrClient($options);
    $client->setServlet(SolrClient::SEARCH_SERVLET_TYPE, "request_handler_name");
    

    【讨论】:

      【解决方案2】:

      您可以使用 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);
      

      希望对您有所帮助...

      【讨论】:

      • 我知道我可以使用 cURL,但我更喜欢使用实际的库。
      • 我尝试使用 cURL 但也继续使用 Solr 对象响应值,所以我尝试使用:php.net/manual/en/solrutils.digestxmlresponse.php 这反过来导致错误“错误取消序列化响应”以获得有效响应带有 SolrResponse::PARSE_SOLR_OBJ 的 parse_mod 的 XML
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-13
      • 1970-01-01
      • 1970-01-01
      • 2020-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多