如何让 zend_lucene 和 zend_paginator 工作

发布于 2024-10-17 04:46:14 字数 882 浏览 2 评论 0原文

我使用 Zend Framework 已有几个月了。所以,我的知识很好,但还不是专家。我正在尝试将 zend_lucene 与 zend_paginator 一起使用,但到目前为止尚未成功。我能够成功地使用 zend_lucene 和索引数据本身,并且能够在查询数据库时使用 zend_paginator,但我似乎无法将两者结合起来。这是我正在做的事情的示例:

尝试 { $searchresults = $index->​​find($lucenequery); } 捕获(Zend_Search_Lucene_Exception $e){ echo "无法{$e->getMessage()}"; }

    $page = $this->_getParam('page',1);
    $paginator = Zend_Paginator::factory($searchresults);
    $paginator->setItemCountPerPage(20);
    $paginator->setCurrentPageNumber($page);
    $this->view->paginator = $paginator;

我需要对 lucene 和 zend_paginator 执行不同的步骤吗?我真的很不确定。我得到的结果是第一页结果显示正确。但是当我点击第二页或第三页时,我的结果是空白的。不确定可能出了什么问题,因为我找不到将两者一起使用的文档或教程。任何帮助将不胜感激。

I've been using Zend Framework for a few months now. So, my knowledge is pretty good but I'm not quite an expert yet. I am trying to use zend_lucene with zend_paginator and so far not successful. I am able to use zend_lucene and index data successfully by itself and able to do use zend_paginator when querying the database, but I can't seem to combine the two. Here is a sample of what I am doing:


try {
$searchresults = $index->find($lucenequery);
}
catch (Zend_Search_Lucene_Exception $e) {
echo "Unable {$e->getMessage()}";
}

    $page = $this->_getParam('page',1);
    $paginator = Zend_Paginator::factory($searchresults);
    $paginator->setItemCountPerPage(20);
    $paginator->setCurrentPageNumber($page);
    $this->view->paginator = $paginator;

Is there a different step I need to do with lucene and zend_paginator? I am really uncertain. The result I get is that for the first page results display properly. But when I hit the second page or third my results are blank. So uncertain what might be wrong as I can't find docs or tutorials in using the two together. Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时常饿 2024-10-24 04:46:14

我认为这可能适用于迭代器适配器:

public function searchAction() {
   $index = Zend_Search_Lucene::open('/path/to/lucene');
   $results = $index->find($this->_getParam('q'));
   $paginator = Zend_Paginator::factory($results);
   $paginator->setCurrentPageNumber($this->_getParam('page', 1));
   $paginator->setItemCountPerPage(10);
   $this->view->results = $paginator;
}

也许您遇到的问题是 $paginator 不知道有多少搜索结果。

所以您可能需要手动执行此操作:

$paginator->setDefaultPageRange($results->count());

I think this may work with the iterator adapter:

public function searchAction() {
   $index = Zend_Search_Lucene::open('/path/to/lucene');
   $results = $index->find($this->_getParam('q'));
   $paginator = Zend_Paginator::factory($results);
   $paginator->setCurrentPageNumber($this->_getParam('page', 1));
   $paginator->setItemCountPerPage(10);
   $this->view->results = $paginator;
}

Perhaps the problem you are having is that $paginator doesn't know how many search results there are..

So you may need to do that manually:

$paginator->setDefaultPageRange($results->count());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文