activate search components on a per usage basis

This commit is contained in:
Gilles Crettenand
2015-06-19 11:57:58 +02:00
parent 9790f4a456
commit 85c1c5d785
2 changed files with 16 additions and 8 deletions

View File

@@ -137,10 +137,13 @@ class BookSearch
/**
* @param int $start
* @param int $count
* @param bool $facets activate faceting ?
* @param bool $spellcheck activate spellcheck ?
* @param bool $highlight activate highlighting ?
* @return array
* @throws WebException
*/
public function getResults($start = 0, $count = 15)
public function getResults($start = 0, $count = 15, $facets = false, $spellcheck = false, $highlight = false)
{
if (count($this->queryParts) == 0)
$query = '*:*';
@@ -154,6 +157,11 @@ class BookSearch
$this->query->setStart($start);
$this->query->setRows($count);
$this->query->setParam('facet', $facets ? 'true' : 'false');
$this->query->setParam('hl', $highlight ? 'true' : 'false');
$this->query->setParam('spellcheck', $spellcheck ? 'true' : 'false');
try {
$results = $this->client->query($this->query)->getArrayResponse();
} catch(\SolrException $e) {
@@ -227,9 +235,6 @@ class BookSearch
$this->query->setStart(0);
$this->query->setRows(0);
$this->query->setParam('suggest', 'true');
$this->query->setParam('facet', 'false');
$this->query->setParam('hl', 'false');
$this->query->setParam('spellcheck', 'false');
try {
$results = $this->client->query($this->query)->getArrayResponse();
@@ -296,7 +301,7 @@ class BookSearch
$s->addFilterQuery(1, 'visible');
$s->addFacetField($field);
$s->setFacetLimits(2000, 10);
$results = $s->getResults(0, 0);
$results = $s->getResults(0, 0, true);
return $results['facets']['facets'][$field];
}
@@ -309,7 +314,7 @@ class BookSearch
$s->setFacetRange(0, 250 * 60, 30);
// to avoid useless calculation, only set this 'normal' facet
$s->addFacetField('visible');
$results = $s->getResults(0, 0);
$results = $s->getResults(0, 0, true);
return $results['facets']['facets'][$field];
}