From e52f257918dbdc447f0d075f14da5b62380765eb Mon Sep 17 00:00:00 2001 From: ornicar Date: Wed, 27 Apr 2011 15:14:21 -0700 Subject: [PATCH] Add RawFinder --- Finder/RawFinder.php | 59 ++++++++++++++++++++++++++++++++++++ Finder/TransformedFinder.php | 7 ++--- 2 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 Finder/RawFinder.php diff --git a/Finder/RawFinder.php b/Finder/RawFinder.php new file mode 100644 index 0000000..a83fc9c --- /dev/null +++ b/Finder/RawFinder.php @@ -0,0 +1,59 @@ +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); + } +} diff --git a/Finder/TransformedFinder.php b/Finder/TransformedFinder.php index 4c2c94d..745e6e7 100644 --- a/Finder/TransformedFinder.php +++ b/Finder/TransformedFinder.php @@ -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); } /**