gpt4 book ai didi

Lucene.NET 生命周期管理

转载 作者:行者123 更新时间:2023-12-01 05:40:41 25 4
gpt4 key购买 nike

假设我对添加和搜索文档有基本的了解。

管理 IndexWriter 和 IndexReader 实例的最佳实践是什么?

目前,我的应用程序创建了一个 IndexWriter 的单例实例。当我需要进行搜索时,我只需使用以下命令从 IndexWriter 创建一个 IndexSearcher

var searcher = new IndexSearcher(writer.GetReader())

我这样做是因为创建一个新的 IndexReader 会导致索引加载到内存中,然后等待 GC 重新分配内存。这导致了内存不足错误。

这个当前的实现被认为是理想的吗?这个实现解决了内存问题,但是write.lock文件总是存在的问题(因为IndexWriter总是被实例化和打开)。这是我在应用程序中遇到的错误的堆栈跟踪。

Lock obtain timed out: NativeFSLock@C:\inetpub\wwwroot\htdocs_beta\App_Data\products3\write.lock: System.IO.IOException: The process cannot access the file 'C:\inetpub\wwwroot\htdocs_beta\App_Data\products3\write.lock' because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at Lucene.Net.Store.NativeFSLock.Obtain()



我在想也许最好创建一个 IndexSearcher 的单例实例进行搜索,然后根据需要在内存中创建一个 IndexWriter。这样,在更新索引时将创建/删除 write.lock 文件。我看到的唯一问题是 IndexSearcher 实例将过时,如果索引已更新,我需要运行一个任务来重新加载 IndexSearcher。

你怎么认为?

您如何通过实时更新处理大型索引?

最佳答案

您应该只使用一个索引编写器,以避免出现锁定问题。看看:Lucene.Net writing/reading synchronization

关于Lucene.NET 生命周期管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5731502/

25 4 0
文章推荐: jquery - 如何结合使用 MaterializeCSS 和 AngularJS 来初始化