SolrClient::setResponseWriter
(PECL solr >= 0.9.11)
SolrClient::setResponseWriter — Sets 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:
- json
- phps
- xml
Возвращаемые значения
Эта функция не возвращает значения после выполнения.
Примеры
Пример #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);
$client->setResponseWriter("json");
//$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);
}
?>
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с поисковыми системами
- Apache Solr
- Функция SolrClient::addDocument() - Adds a document to the index
- Функция SolrClient::addDocuments() - Adds a collection of SolrInputDocument instances to the index
- Функция SolrClient::commit() - Finalizes all add/deletes made to the index
- Функция SolrClient::__construct() - Constructor for the SolrClient object
- Функция SolrClient::deleteById() - Delete by Id
- Функция SolrClient::deleteByIds() - Deletes by Ids
- Функция SolrClient::deleteByQueries() - Removes all documents matching any of the queries
- Функция SolrClient::deleteByQuery() - Deletes all documents matching the given query
- Функция SolrClient::__destruct() - Destructor for SolrClient
- SolrClient::getById
- SolrClient::getByIds
- Функция SolrClient::getDebug() - Returns the debug data for the last connection attempt
- Функция SolrClient::getOptions() - Returns the client options set internally
- Функция SolrClient::optimize() - Defragments the index
- Функция SolrClient::ping() - Checks if Solr server is still up
- Функция SolrClient::query() - Sends a query to the server
- Функция SolrClient::request() - Sends a raw update request
- Функция SolrClient::rollback() - Rollbacks all add/deletes made to the index since the last commit
- Функция SolrClient::setResponseWriter() - Sets the response writer used to prepare the response from Solr
- Функция SolrClient::setServlet() - Changes the specified servlet type to a new value
- SolrClient::system
- Функция SolrClient::threads() - Checks the threads status
Коментарии
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;
?>