如何在 Code Igniter 中缓存 Zend Lucene 搜索结果?

发布于 2024-11-16 01:23:07 字数 239 浏览 4 评论 0原文

我不确定这是否是最好的方法,但我的目标是对我的 lucene 搜索结果进行分页。

我认为运行搜索,将所有结果存储在缓存中,然后在结果控制器上有一个页面函数,可以从缓存的结果返回任何特定的结果子集是有意义的。

这是一个不好的方法吗?我从未使用过任何类型的缓存,所以不知道从哪里开始。 CI 缓存驱动程序看起来很有前途,但一切都会引发服务器错误。我不知道是否需要安装APC,或者Memcached,或者该怎么做。

帮助!

I'm not sure if this is the best way to go about this, but my aim is to have pagination of my lucene search results.

I thought it would make sense to run the search, store all the results in the cache, and then have a page function on my results controller that could return any particular subset of results from the cached results.

Is this a bad approach? I've never used caching of any sort, so don't know where to begin. The CI Caching Driver looked promising, but everything throws a server error. I don't know if I need to install APC, or Memcached, or what to do.

Help!

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

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

发布评论

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

评论(2

薄凉少年不暖心 2024-11-23 01:23:07

Lucene 是一个专为规模化而构建的搜索引擎。您可以将其推得很远,直到需要缓存搜索结果为止。我建议您使用默认设置并运行它。

如果您仍然觉得需要缓存,请首先查看Lucene FAQ然后下一个级别可能是内存缓存方面的东西。

希望有帮助!

Lucene is a search engine that is built for scale. You can push it pretty far till the need arises to cache the search results. I would suggest you use the default settings and run it.

If you still feel the need for cache, first look at this Lucene FAQ and then the next level would perhaps be something on the lines of memcache.

Hope it helps!

青芜 2024-11-23 01:23:07

Zend Search Lucene 在文件系统上建立索引,正如上面的用户所说,是为了扩展而构建的。除非您要索引数十万个文档,否则缓存并不是真正必要的 - 特别是因为您实际上要做的就是从一个文件中获取数据并将其存储在另一个文件中。

另一方面,如果您仅将产品 ID 存储在搜索索引中,然后在获得结果时从数据库中选择产品,则非常值得进行缓存。通过使用 Zend_Cache 可以轻松实现这一点。

Zend Db 缓存的基本示例如下:

$frontendOptions = array(
    'automatic_serialization' => true
);

$backendOptions = array(
    'cache_dir' => YOUR_CACHE_PATH_ON_THE_FILE_SYSTEM,
    'file_name_prefix' => 'my_cache_prefix',
);

$cache = Zend_Cache::factory('Core',
    'File',
    $frontendOptions,
    $backendOptions
);
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);

这应该添加到 _initDbCache(无论你想怎么称呼它)方法中的引导文件中。

当然,这是一个非常简单的实现,并没有实现完整的结果缓存,有关 Zend Db 的 Zend 缓存的更多信息可以找到 此处

Zend Search Lucene is indexed on the file system and as the user above has stated, built for scale. Unless you are indexing hundreds of thousands of documents, then caching is not really necessary - especially since all you would effectively be doing is taking data from one file and storing it in another.

On the other hand, if you are only storing, say, product Id in your search index and then selecting the products from the database when you get a result, it's well worth caching. This can easily be achived by using Zend_Cache.

A basic example of Zend Db caching is here:

$frontendOptions = array(
    'automatic_serialization' => true
);

$backendOptions = array(
    'cache_dir' => YOUR_CACHE_PATH_ON_THE_FILE_SYSTEM,
    'file_name_prefix' => 'my_cache_prefix',
);

$cache = Zend_Cache::factory('Core',
    'File',
    $frontendOptions,
    $backendOptions
);
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);

This should be added to your bootstrap file in an _initDbCache (call it whatever you want) method.

Of course that is a very simple implementation and does not achieve full result caching, more information on Zend Caching with Zend Db can be found here.

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