You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.1 KiB
PHP
80 lines
2.1 KiB
PHP
<?php
|
|
|
|
mb_http_output('UTF-8');
|
|
|
|
class BookSearch
|
|
{
|
|
/** @var SolrClient */
|
|
private $client;
|
|
/** @var SolrQuery */
|
|
private $query;
|
|
private $queryParts = array();
|
|
|
|
public function __construct()
|
|
{
|
|
$options = array
|
|
(
|
|
'hostname' => Configuration::get('solr.server'),
|
|
'port' => Configuration::get('solr.port'),
|
|
'login' => Configuration::get('solr.username'),
|
|
'password' => Configuration::get('solr.password'),
|
|
'path' => 'solr/bsr1',
|
|
);
|
|
|
|
$this->client = new SolrClient($options);
|
|
$this->query = new SolrQuery();
|
|
$this->query->setQuery('*:*');
|
|
$this->query->addField('id');
|
|
$this->query->addField('code');
|
|
$this->query->addParam('q.op', 'AND');
|
|
}
|
|
|
|
public function addQuery($queryText, $queryField = '')
|
|
{
|
|
if ($queryField != '')
|
|
$queryText = "$queryField:($queryText)";
|
|
|
|
$this->queryParts[] = $queryText;
|
|
}
|
|
|
|
public function addResultField($field)
|
|
{
|
|
$this->query->addField($field);
|
|
}
|
|
|
|
public function addSortField($field, $order = SolrQuery::ORDER_DESC)
|
|
{
|
|
$this->query->addSortField($field, $order);
|
|
}
|
|
|
|
public function addFacet($field, $minCount = 2)
|
|
{
|
|
$this->query->setFacet(true);
|
|
$this->query->addFacetField($field);
|
|
$this->query->setFacetMinCount($minCount, $field);
|
|
}
|
|
|
|
public function setYearInterval($beginning = 0, $end = 2500)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @param int $start
|
|
* @param int $count
|
|
* @return SolrObject
|
|
*/
|
|
public function getResults($start = 0, $count = 15)
|
|
{
|
|
if (count($this->queryParts) == 0)
|
|
$query = '*:*';
|
|
else {
|
|
$query = implode(' AND ', $this->queryParts);
|
|
}
|
|
$this->query->setQuery($query);
|
|
$this->query->setStart($start);
|
|
$this->query->setRows($count);
|
|
|
|
return $this->client->query($this->query)->getResponse();
|
|
}
|
|
}
|