<?php
$options = array
(
'hostname' => 'localhost',
'port' => '8080',
'path' => 'solr/help_category',
'wt' => 'json'
);
$client = new SolrClient($options);
try {
$client->ping();
} Catch (Exception $e) {
exit('未连接');
}
$query = new SolrQuery();
$query->setQuery('title:账户');
$query->setStart(0);
$query->setRows(20);
$query->addField('title')->addField('id');
$query->addHighlightField('title');
$query->setHighlight(true);
$query->setHighlightSimplePre("<span style='color:blue'>");
$query->setHighlightSimplePost('</span>');
$query_response = $client->query($query);
$response = $query_response->getResponse();
var_dump($query_response->getRequestUrl());
var_dump($query_response->getRawRequest());
var_dump($response['highlighting']); //可以通过foreach找出高亮部分
if ($response['response']['numFound'] > 0) {
foreach ($response['response']['docs'] as $doc) {
echo $doc['title'];
echo '<br><br>';
}
}
?>