SolrClient::setResponseWriter

(PECL solr >= 0.9.11)

SolrClient::setResponseWriterSets the response writer used to prepare the response from Solr

Описание

public void SolrClient::setResponseWriter ( string $responseWriter )

Sets the response writer used to prepare the response from Solr

Список параметров

responseWriter

One of the following :

- xml
 - phpnative

Возвращаемые значения

Эта функция не возвращает значения после выполнения.

Примеры

Пример #1 SolrClient::setResponseWriter() example

<?php

// This is my custom class for objects
class SolrClass
{
   public 
$_properties = array();

   public function 
__get($property_name) {
      
      if (
property_exists($this$property_name)) {
      
          return 
$this->$property_name;
      
      } else if (isset(
$_properties[$property_name])) {
      
          return 
$_properties[$property_name];
      }
      
      return 
null;
   }
}

$options = array
(
  
'hostname' => 'localhost',
  
'port' => 8983,
  
'path' => '/solr/core1'
);

$client = new SolrClient($options);

// This uses the org.apache.solr.request.PHPNativeResponseWriter class on Solr
// Visit the following pages for more details
// https://issues.apache.org/jira/browse/SOLR-1967
// http://wiki.apache.org/solr/QueryResponseWriter
// http://wiki.apache.org/solr/SolPHP
$client->setResponseWriter("phpnative");

//$response = $client->ping();

$query = new SolrQuery();

$query->setQuery("*:*");

$query->set("objectClassName""SolrClass");

$query->set("objectPropertiesStorageMode"1); // 0 for independent properties, 1 for combined

try
{

$response $client->query($query);

$resp $response->getResponse();

print_r($response);

print_r($resp);

} catch (
Exception $e) {

print_r($e);

}

?>

Результатом выполнения данного примера будет что-то подобное:


Коментарии

i found that 'php' is also supported.

<?php
$solr_server 
= array
(
   
'hostname'     => $solr_hostname,
   
'port'         => $solr_port,
   
'path'         => $solr_path,
);
$solr_client = new SolrClient($solr_server);

$solr_response_writer 'php'// "wt"
$solr_client->setResponseWriter($solr_response_writer);

$solr_response = new SolrObject();

$solr_query = new SolrQuery();
$solr_query->setQuery($solr_query_string); // "q"

try {
   
$query_response $solr_client->query($solr_query);
   
$solr_response $query_response->getResponse();
    return 
'';
} catch (
Exception $e) {
    return (
$e);
}
?>

php_error.log keeps on saying:

[12-Aug-2015 12:34:56 Asia/Hong_Kong] PHP Warning:  SolrClient::setResponseWriter(): Unsupported response writer php. This value will be ignored in C:\www\...\solr.php on line 21

but the returned data is good as expected:

<?php
$html 
.= '<table cellSpacing="1" cellPadding="1" border="1">';
$html .= '<tr>';
$html .= '<td>id</td>';
$html .= '<td>title</td>';
$html .= '<td>score</td>';
$html .= '</tr>';

for (
$i_solr 0$i_solr <= ($solr_rows 1); $i_solr++) {
   
$html .= '<tr>';
   
$html .= '<td>' $solr_response['response']['docs'][$i_solr]['id'] . '</td>';
   
$html .= '<td>' $solr_response['response']['docs'][$i_solr]['title'][0] . '</td>';
   
$html .= '<td>' $solr_response['response']['docs'][$i_solr]['score'] . '</td>';
   
$html .= '</tr>';
}
$html .= '</table>';
echo 
$html;
?>
2015-08-12 10:44:10
http://php5.kiev.ua/manual/ru/solrclient.setresponsewriter.html

    Поддержать сайт на родительском проекте КГБ