Merge pull request #358

This commit is contained in:
Jeremy Mikola 2013-08-19 12:02:28 -04:00
commit 2bfb637a00
4 changed files with 55 additions and 1 deletions

View file

@ -29,6 +29,18 @@ class FantaPaginatorAdapter implements AdapterInterface
return $this->adapter->getTotalHits();
}
/**
* Returns Facets
*
* @return mixed
*
* @api
*/
public function getFacets()
{
return $this->adapter->getFacets();
}
/**
* Returns an slice of the results.
*

View file

@ -26,4 +26,11 @@ interface PaginatorAdapterInterface
* @api
*/
function getResults($offset, $length);
/**
* Returns Facets
*
* @return mixed
*/
function getFacets();
}

View file

@ -30,6 +30,11 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
*/
private $totalHits;
/**
* @array for the facets
*/
private $facets;
/**
* @see PaginatorAdapterInterface::__construct
*
@ -71,7 +76,7 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
$resultSet = $this->searchable->search($query);
$this->totalHits = $resultSet->getTotalHits();
$this->facets = $resultSet->getFacets();
return $resultSet;
}
@ -102,4 +107,18 @@ class RawPaginatorAdapter implements PaginatorAdapterInterface
? min($this->totalHits, (integer) $this->query->getParam('size'))
: $this->totalHits;
}
/**
* Returns Facets
*
* @return mixed
*/
public function getFacets()
{
if ( ! isset($this->facets)) {
$this->facets = $this->searchable->search($this->query)->getFacets();
}
return $this->facets;
}
}

View file

@ -409,6 +409,22 @@ still also getting the entity.
$result = $hybridResult->getResult();
}
If you would like to access facets while using Pagerfanta they can be accessed through
the Adapter seen in the example below.
```php
$query = new \Elastica\Query();
$facet = new \Elastica\Facet\Terms('tags');
$facet->setField('companyGroup');
$query->addFacet($facet);
$companies = $finder->findPaginated($query);
$companies->setMaxPerPage($params['limit']);
$companies->setCurrentPage($params['page']);
$facets = $companies->getAdapter()->getFacets());
```
##### Index wide finder
You can also define a finder that will work on the entire index. Adjust your index