Lucene.Net管理多个线程访问相同的索引,一个索引,而另一个正在搜索? [英] Does Lucene.Net manage multiple threads accessing the same index, one indexing while the other is searching?

查看:161
本文介绍了Lucene.Net管理多个线程访问相同的索引,一个索引,而另一个正在搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用Lucene.Net和ASP.NET时,我可以想象一个Web请求可以触发更新索引,而另一个Web请求正在执行搜索。 Lucene.Net已经内置了管理并发访问的能力,或者我必须管理它,以避免被另一个进程使用错误?

When using Lucene.Net with ASP.NET, I can imagine that one web request can trigger an update to the index while another web request is performing a search. Does Lucene.Net have built in it the ability to manage concurrent access, or do I have to manage it, to avoid "being used by another process" errors?

编辑:阅读文档和实验后,这是我认为我学到了:有两个问题,线程安全和并发。多线程是安全的,因为你不能做任何坏的索引。但是,它是安全的,只有一个对象有一个锁索引一次。第二个对象将会出现并抛出异常。所以,你不能让搜索打开,并期望另一个线程中的作者能够更新索引。如果线程正忙于更新索引,则尝试创建搜索器将失败。

After reading docs and experimentation, this is what I think I've learned: There are two issues, thread safety and concurrency. Multithreading is "safe" in that you can't do anything bad to the index. But, it's safe at the cost of just one object having a lock on the index at one time. The second object will come along and throw an exception. So, you can't leave a search open and expect a writer in another thread to be able to update the index. And if a thread is busy updating the index, then trying to create a searcher will fail.

此外,搜索器看到的索引,因为它是在它们打开它,所以如果你保留它们,并更新索引,他们将不会看到更新。

Also, Searchers see the index as it was at the time that they open it, so if you keep them around, and update the index, they won't see the updates.

我希望我的搜索者看到最新的更新。

I wanted my searchers to see the latest updates.

我的设计,似乎工作到目前为止,是我的作家和搜索者共享一个锁,所以他们不会失败,他们只是等待 - 直到

My design, and it seems to be working so far, is that my writers and searchers share a lock, so that they don't fail - they just wait - until the current write or search is done.

推荐答案

根据此页面


索引和搜索不仅是
线程安全,但过程安全。
意味着:

Indexing and searching are not only thread safe, but process safe. What this means is that:


  • 多个索引搜索器可以同时读取
    lucene索引文件。

  • 索引编写者或读者可以编辑
    lucene索引文件,而搜索结果是
    正在进行

  • 多个索引编写者或
    读者可以尝试同时编辑lucene
    索引文件(对于索引编写器/阅读器
    来说,
    很重要,因此它将释放
    文件锁)。然而,查询解析器
    不是线程安全的,因此每个线程
    使用索引应该有自己的
    查询解析器。

然而,索引编写器是线程
safe,所以你可以更新索引
,而人们正在搜索它。
然而,你必须确保
,打开索引的线程
搜索器关闭它们并打开新的
,以获得新更新的数据。

The index writer however, is thread safe, so you can update the index while people are searching it. However, you then have to make sure that the threads with open index searchers close them and open new ones, to get the newly updated data.

这篇关于Lucene.Net管理多个线程访问相同的索引,一个索引,而另一个正在搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆