gpt4 book ai didi

php - SolrQuery 的 Zend_Paginator 适配器

转载 作者:搜寻专家 更新时间:2023-10-31 21:44:52 27 4
gpt4 key购买 nike

我目前正在 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'];
}
}

最佳答案

您可能希望基于响应的 SolrObject 而不是查询来执行此操作。您需要的所有信息都在这里。

$solrResponse = $solrClient->query($query);
$solrObject = $solrResponse->getResponse();
$paginator = new Zend_Paginator(new Xxx_Paginator_Adapter_SolrQuery($solrObject));

关于php - SolrQuery 的 Zend_Paginator 适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5329823/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com