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

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

问题描述

在使用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的
      在同一时间索引文件(它是
      该指数作家/读者重要
      被关闭,以便将释放
      文件锁)。但是,查询解析器
      不是线程安全的,所以每个线程
      使用索引应该有它自己的
      查询分析器。

  •   

的索引作家然而,螺纹
  安全的,所以你可以更新索引
  当人们正在寻找它。
  但是,你则必须确保
  与开放式指数螺纹
  搜索关闭,并开辟新的
  的人,获得新的更新数据。

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管理多个线程访问相同的索引,1的索引,而另一种是搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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