SolrClient::setResponseWriter

(PECL solr >= 0.9.11)

SolrClient::setResponseWriterEstablece el autor de la respuesta usado para preparar la respuesta de Solr

Descripción

public SolrClient::setResponseWriter(string $responseWriter): void

Establece el autor de la respuesta usado para preparar la respuesta de Solr

Parámetros

responseWriter

Uno de los siguientes autores:

  • json
  • phps
  • xml

Valores devueltos

No devuelve ningún valor.

Ejemplos

Ejemplo #1 Ejemplo de SolrClient::setResponseWriter()

<?php

// Esta es mi clase personalizada para los objetos
class SolrClass
{
public
$_propiedades = array();

public function
__get($nombre_propiedad) {

if (
property_exists($this, $nombre_propiedad)) {

return
$this->$nombre_propiedad;

} else if (isset(
$_propiedades[$nombre_propiedad])) {

return
$_propiedades[$nombre_propiedad];
}

return
null;
}
}

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

$cliente = new SolrClient($opciones);

$cliente->setResponseWriter("json");

//$respuesta = $cliente->ping();

$consulta = new SolrQuery();

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

$consulta->set("objectClassName", "SolrClass");

$consulta->set("objectPropertiesStorageMode", 1); // 0 para propiedades independientes, 1 para combinadas

try
{

$respuesta = $cliente->query($consulta);

$resp = $respuesta->getResponse();

print_r($respuesta);

print_r($resp);

} catch (
Exception $e) {

print_r($e);

}

?>

add a note

User Contributed Notes 1 note

up
-2
edwardtam at et-it dot net
9 years ago
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 21but 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;?>
To Top