在lucene索引中加载一个字段

时间:2021-06-18 03:09:59


Whats the fastest way to loading all of the values of a lucene index field in memory, I have large lucene index (1.6 GB) i need to load all of the (ID) field into memory with least overhead on memory I'm getting OutOfMemoryException when i iterate through all of the items and read that field (this is also very slow for loading field of index i need a solution with better performance).

什么最快的方式加载所有lucene索引字段的值在内存中,我有大lucene索引(1.6 GB)我需要(ID)字段的所有加载到内存开销至少在内存我得到OutOfMemoryException当我遍历所有的物品和阅读这一领域(这也是非常缓慢的加载字段的索引我需要一个解决方案与更好的性能)。

1 个解决方案

#1


1  

You may need to address why you need to load of your Fields into memory in the first place?

您可能需要首先解决为什么需要将字段加载到内存中?

Have you tried doing a search using a TermQuery and a Term that simply contains the field you want to load? e.g. new Term("ID").

您是否尝试过使用TermQuery和仅仅包含要加载的字段的术语进行搜索?如新学期(" ID ")。

You then wont need to load all values into memory to iterate over them. Instead, use a FieldSelector to ensure only a single field is loaded when you load each search result.

然后,不需要将所有值加载到内存中以遍历它们。相反,使用FieldSelector确保在加载每个搜索结果时只加载一个字段。

Otherwise, use Lucene's FieldCache to get the values for all your ID fields.

否则,使用Lucene的FieldCache获取所有ID字段的值。

#1


1  

You may need to address why you need to load of your Fields into memory in the first place?

您可能需要首先解决为什么需要将字段加载到内存中?

Have you tried doing a search using a TermQuery and a Term that simply contains the field you want to load? e.g. new Term("ID").

您是否尝试过使用TermQuery和仅仅包含要加载的字段的术语进行搜索?如新学期(" ID ")。

You then wont need to load all values into memory to iterate over them. Instead, use a FieldSelector to ensure only a single field is loaded when you load each search result.

然后,不需要将所有值加载到内存中以遍历它们。相反,使用FieldSelector确保在加载每个搜索结果时只加载一个字段。

Otherwise, use Lucene's FieldCache to get the values for all your ID fields.

否则,使用Lucene的FieldCache获取所有ID字段的值。