【发布时间】:2011-07-16 20:01:45
【问题描述】:
我目前正在使用 Zend_Paginator 的 PECL SolrQuery 适配器。我想不出避免重复查询的方法。有没有人有更好的实现方式?
<?php
require_once 'Zend/Paginator/Adapter/Interface.php';
class Xxx_Paginator_Adapter_SolrQuery implements Zend_Paginator_Adapter_Interface
{
private $query;
private $client;
public function __construct(SolrQuery $query, $client) {
$this->query = $query;
$this->client = $client instanceof SolrClient ? $client : new SolrClient($client);
}
public function count() {
$this->query->setRows(0);
return $this->execute()->numFound;
}
public function getItems($offset, $itemCountPerPage) {
$this->query->setStart($offset)->setRows($itemCountPerPage);
return $this->execute()->docs;
}
private function execute() {
$response = $this->client->query($this->query)->getResponse();
return $response['response'];
}
}
【问题讨论】:
-
能解释一下重复的查询吗?
标签: php zend-framework solr pagination zend-paginator