|
|
|
@ -13,7 +13,10 @@ class BookSearch
|
|
|
|
private $client;
|
|
|
|
private $client;
|
|
|
|
/** @var \SolrQuery */
|
|
|
|
/** @var \SolrQuery */
|
|
|
|
private $query;
|
|
|
|
private $query;
|
|
|
|
|
|
|
|
/** @var array parts of the query, parameter 'q' */
|
|
|
|
private $queryParts = array();
|
|
|
|
private $queryParts = array();
|
|
|
|
|
|
|
|
/** @var array parts of the filter query, parameter 'fq' */
|
|
|
|
|
|
|
|
private $filterQueryParts = array();
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct($edismax = true)
|
|
|
|
public function __construct($edismax = true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -79,12 +82,20 @@ class BookSearch
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (strlen($queryField) > 0) {
|
|
|
|
if (strlen($queryField) > 0) {
|
|
|
|
$queryText = "$queryField:\"$queryText\"";
|
|
|
|
$queryText = sprintf('%s:"%s"', $queryField, $queryText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->queryParts[] = $queryText;
|
|
|
|
$this->queryParts[] = $queryText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function addFilterQuery($text, $field, $escape = true)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if($escape) {
|
|
|
|
|
|
|
|
$text = \SolrUtils::escapeQueryChars($text);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->filterQueryParts[] = sprintf('%s:"%s"', $field, $text);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function addRange($field, $min = '*', $max = '*')
|
|
|
|
public function addRange($field, $min = '*', $max = '*')
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->queryParts[] = sprintf('%s:[%s TO %s]', $field, $min, $max);
|
|
|
|
$this->queryParts[] = sprintf('%s:[%s TO %s]', $field, $min, $max);
|
|
|
|
@ -136,6 +147,9 @@ class BookSearch
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
$query = implode(' AND ', $this->queryParts);
|
|
|
|
$query = implode(' AND ', $this->queryParts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($this->filterQueryParts as $fq) {
|
|
|
|
|
|
|
|
$this->query->addFilterQuery($fq);
|
|
|
|
|
|
|
|
}
|
|
|
|
$this->query->setQuery($query);
|
|
|
|
$this->query->setQuery($query);
|
|
|
|
$this->query->setStart($start);
|
|
|
|
$this->query->setStart($start);
|
|
|
|
$this->query->setRows($count);
|
|
|
|
$this->query->setRows($count);
|
|
|
|
@ -279,7 +293,7 @@ class BookSearch
|
|
|
|
|
|
|
|
|
|
|
|
public static function GetTerms($field) {
|
|
|
|
public static function GetTerms($field) {
|
|
|
|
$s = new BookSearch();
|
|
|
|
$s = new BookSearch();
|
|
|
|
$s->addQuery(1, 'visible');
|
|
|
|
$s->addFilterQuery(1, 'visible');
|
|
|
|
$s->addFacetField($field);
|
|
|
|
$s->addFacetField($field);
|
|
|
|
$s->setFacetLimits(2000, 10);
|
|
|
|
$s->setFacetLimits(2000, 10);
|
|
|
|
$results = $s->getResults(0, 0);
|
|
|
|
$results = $s->getResults(0, 0);
|
|
|
|
@ -290,7 +304,7 @@ class BookSearch
|
|
|
|
|
|
|
|
|
|
|
|
public static function GetTermsRange($field) {
|
|
|
|
public static function GetTermsRange($field) {
|
|
|
|
$s = new BookSearch();
|
|
|
|
$s = new BookSearch();
|
|
|
|
$s->addQuery(1, 'visible');
|
|
|
|
$s->addFilterQuery(1, 'visible');
|
|
|
|
$s->setFacetRangeField($field);
|
|
|
|
$s->setFacetRangeField($field);
|
|
|
|
$s->setFacetRange(0, 250, 1);
|
|
|
|
$s->setFacetRange(0, 250, 1);
|
|
|
|
// to avoid useless calculation, only set this 'normal' facet
|
|
|
|
// to avoid useless calculation, only set this 'normal' facet
|
|
|
|
|