Android Lucene OutOfMemoryExceptoin

标签 android memory lucene

我有一个 Lucene 索引,其中包含来自 1740 本书的 50571 个文档。我有两个创建该索引的进程。第一个过程是按文档在设备文档上创建索引。这个过程非常缓慢。另一个过程是在服务器上创建图书索引(与我在设备上创建它的方式完全相同),然后下载并将其与主索引合并。这个创建主索引要快得多。无论哪种方式创建索引都可以正常工作。

问题是,当我搜索下载合并索引时,我收到了 OutOfMemoryException,但是当我使用在设备上创建的索引进行搜索时,我没有收到该错误。我逐本书创建了索引(下载合并),并在每本书编入索引后进行搜索;基于此,当我预订到 ~450 时,我开始收到 OutOfMemoryException

是什么导致我内存不足。

最佳答案

Lucene 是一个内存消耗大户。当将索引“合并”在一起时,它将整个索引集存储在内存中两次。引自lucene documentation .

Note that this requires temporary free space in the Directory up to 2X the sum of all input indexes (including the starting index). If readers/searchers are open against the starting index, then temporary free space required will be higher by the size of the starting index

内存很大。为了缓解这个问题,我们必须通过在索引编写器上调用forceMerge(int)来缩小索引的大小。这是一个缓慢的过程,但它确实缩小了索引的大小。每次索引目录中有 50 个或更多文件时,我都会使用 1 参数来调用此函数。

关于Android Lucene OutOfMemoryExceptoin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12429016/

相关文章:

带有通配符的java黑名单

encryption - 在 solr 和 Lucene 中加密索引

android - Canvas Touch在S4 Android设备中不起作用

android - onPeriodicNotification() 在*一些*设备上有抖动

c - 执行文件时内存布局中的文本段会发生什么?

testing - 具有内存消耗约束的 Java 单元测试

android - 使用 HttpUriRequest 与 HttpURLConnection 的优缺点是什么?

android - Espresso - 每次测试方法后 Activity 都会关闭。有没有办法我们不能停止关闭 Activity 和运行其他测试方法

java - 字符串以位的形式存储在内存中

full-text-search - 如何评估托管全文搜索解决方案?