Add RawFinder
This commit is contained in:
parent
cb3fae7925
commit
e52f257918
2 changed files with 62 additions and 4 deletions
59
Finder/RawFinder.php
Normal file
59
Finder/RawFinder.php
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace FOQ\ElasticaBundle\Finder;
|
||||
|
||||
use FOQ\ElasticaBundle\Paginator\RawPaginatorAdapter;
|
||||
use Zend\Paginator\Paginator;
|
||||
use Elastica_Searchable;
|
||||
use Elastica_Query;
|
||||
|
||||
/**
|
||||
* Finds elastica documents
|
||||
*/
|
||||
class RawFinder implements FinderInterface, PaginatedFinderInterface
|
||||
{
|
||||
protected $searchable;
|
||||
|
||||
public function __construct(Elastica_Searchable $searchable)
|
||||
{
|
||||
$this->searchable = $searchable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a query string
|
||||
*
|
||||
* @return array of elastica objects
|
||||
**/
|
||||
public function find($query, $limit)
|
||||
{
|
||||
$queryObject = Elastica_Query::create($query);
|
||||
$queryObject->setLimit($limit);
|
||||
|
||||
return $this->searchable->search($queryObject)->getResults();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a paginator wrapping the result of a search
|
||||
*
|
||||
* @return Paginator
|
||||
**/
|
||||
public function findPaginated($query)
|
||||
{
|
||||
$queryObject = Elastica_Query::create($query);
|
||||
$results = $this->searchable->search($queryObject)->getResults();
|
||||
$paginatorAdapter = $this->createPaginatorAdapter($queryObject);
|
||||
|
||||
return new Paginator($paginatorAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a paginator adapter for this query
|
||||
*
|
||||
* @param Elastica_Query $query
|
||||
* @return RawPaginatorAdapter
|
||||
*/
|
||||
protected function createPaginatorAdapter(Elastica_Query $query)
|
||||
{
|
||||
return new RawPaginatorAdapter($this->searchable, $query);
|
||||
}
|
||||
}
|
||||
|
|
@ -23,9 +23,9 @@ class TransformedFinder implements FinderInterface, PaginatedFinderInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* Search for a query string in the food searchable
|
||||
* Search for a query string
|
||||
*
|
||||
* @return array of Food documents
|
||||
* @return array of model objects
|
||||
**/
|
||||
public function find($query, $limit)
|
||||
{
|
||||
|
|
@ -46,9 +46,8 @@ class TransformedFinder implements FinderInterface, PaginatedFinderInterface
|
|||
$queryObject = Elastica_Query::create($query);
|
||||
$results = $this->searchable->search($queryObject)->getResults();
|
||||
$paginatorAdapter = $this->createPaginatorAdapter($queryObject);
|
||||
$paginator = new Paginator($paginatorAdapter);
|
||||
|
||||
return $paginator;
|
||||
return new Paginator($paginatorAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue