|
|
|
|
@ -3,14 +3,15 @@
|
|
|
|
|
namespace BSR\Lib\Search;
|
|
|
|
|
|
|
|
|
|
use BSR\Lib\Configuration;
|
|
|
|
|
use BSR\Lib\Exception\WebException;
|
|
|
|
|
|
|
|
|
|
mb_http_output('UTF-8');
|
|
|
|
|
|
|
|
|
|
class BookSearch
|
|
|
|
|
{
|
|
|
|
|
/** @var SolrClient */
|
|
|
|
|
/** @var \SolrClient */
|
|
|
|
|
private $client;
|
|
|
|
|
/** @var SolrQuery */
|
|
|
|
|
/** @var \SolrQuery */
|
|
|
|
|
private $query;
|
|
|
|
|
private $queryParts = array();
|
|
|
|
|
|
|
|
|
|
@ -25,8 +26,8 @@ class BookSearch
|
|
|
|
|
'path' => Configuration::get('solr.path'),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->client = new SolrClient($options);
|
|
|
|
|
$this->query = new SolrQuery();
|
|
|
|
|
$this->client = new \SolrClient($options);
|
|
|
|
|
$this->query = new \SolrQuery();
|
|
|
|
|
$this->query->setQuery('*:*');
|
|
|
|
|
|
|
|
|
|
$this->query->addField('*');
|
|
|
|
|
@ -37,7 +38,7 @@ class BookSearch
|
|
|
|
|
public function addQuery($queryText, $queryField = null, $escape = true)
|
|
|
|
|
{
|
|
|
|
|
if($escape) {
|
|
|
|
|
$queryText = SolrUtils::escapeQueryChars($queryText);
|
|
|
|
|
$queryText = \SolrUtils::escapeQueryChars($queryText);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strlen($queryField) > 0) {
|
|
|
|
|
@ -47,7 +48,7 @@ class BookSearch
|
|
|
|
|
$this->queryParts[] = $queryText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addSortField($field, $order = SolrQuery::ORDER_DESC)
|
|
|
|
|
public function addSortField($field, $order = \SolrQuery::ORDER_DESC)
|
|
|
|
|
{
|
|
|
|
|
$this->query->addSortField($field, $order);
|
|
|
|
|
}
|
|
|
|
|
@ -71,7 +72,7 @@ class BookSearch
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$results = $this->client->query($this->query)->getResponse();
|
|
|
|
|
} catch(SolrClientException $e) {
|
|
|
|
|
} catch(\SolrClientException $e) {
|
|
|
|
|
throw new WebException ("SolrError", $e->getMessage(), -700);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|