<i id='rUO9e'><tr id='rUO9e'><dt id='rUO9e'><q id='rUO9e'><span id='rUO9e'><b id='rUO9e'><form id='rUO9e'><ins id='rUO9e'></ins><ul id='rUO9e'></ul><sub id='rUO9e'></sub></form><legend id='rUO9e'></legend><bdo id='rUO9e'><pre id='rUO9e'><center id='rUO9e'></center></pre></bdo></b><th id='rUO9e'></th></span></q></dt></tr></i><div id='rUO9e'><tfoot id='rUO9e'></tfoot><dl id='rUO9e'><fieldset id='rUO9e'></fieldset></dl></div>
    • <bdo id='rUO9e'></bdo><ul id='rUO9e'></ul>
  • <legend id='rUO9e'><style id='rUO9e'><dir id='rUO9e'><q id='rUO9e'></q></dir></style></legend>
    1. <small id='rUO9e'></small><noframes id='rUO9e'>

    2. <tfoot id='rUO9e'></tfoot>

        Lucene.Net 是否管理访问同一索引的多个线程,一个索引而另一个正在搜索?

        时间:2023-09-16
          <bdo id='7Rq3c'></bdo><ul id='7Rq3c'></ul>
            <tbody id='7Rq3c'></tbody>

            <i id='7Rq3c'><tr id='7Rq3c'><dt id='7Rq3c'><q id='7Rq3c'><span id='7Rq3c'><b id='7Rq3c'><form id='7Rq3c'><ins id='7Rq3c'></ins><ul id='7Rq3c'></ul><sub id='7Rq3c'></sub></form><legend id='7Rq3c'></legend><bdo id='7Rq3c'><pre id='7Rq3c'><center id='7Rq3c'></center></pre></bdo></b><th id='7Rq3c'></th></span></q></dt></tr></i><div id='7Rq3c'><tfoot id='7Rq3c'></tfoot><dl id='7Rq3c'><fieldset id='7Rq3c'></fieldset></dl></div>
            <tfoot id='7Rq3c'></tfoot>
              <legend id='7Rq3c'><style id='7Rq3c'><dir id='7Rq3c'><q id='7Rq3c'></q></dir></style></legend>

                  <small id='7Rq3c'></small><noframes id='7Rq3c'>

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

                  问题描述

                  当将 Lucene.Net 与 ASP.NET 一起使用时,我可以想象一个 Web 请求可以触发对索引的更新,而另一个 Web 请求正在执行搜索.Lucene.Net 是否内置了管理并发访问的能力,还是我必须对其进行管理以避免被另一个进程使用"错误?

                  阅读文档和实验后,我认为我学到了:有两个问题,线程安全和并发.多线程是安全的",因为您不能对索引做任何坏事.但是,这是安全的,代价是一次只有一个对象锁定索引.第二个对象会出现并抛出异常.因此,您不能打开搜索并期望另一个线程中的作者能够更新索引.如果一个线程忙于更新索引,那么尝试创建搜索器将会失败.

                  此外,搜索者看到的索引与他们打开时的状态相同,因此如果您保留它们并更新索引,他们将不会看到更新.

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

                  我的设计,而且目前看来是有效的,是我的作者和搜索者共享一个锁,这样他们就不会失败 - 他们只是等待 - 直到当前的写入或搜索完成.

                  解决方案

                  根据本页,p><块引用>

                  索引和搜索不仅线程安全,但过程安全.什么这意味着:

                  • 多个索引搜索者可以阅读lucene 索引文件.
                  • 索引作者或读者可以编辑搜索时的 lucene 索引文件正在进行中
                  • 多个索引编写器或读者可以尝试编辑lucene同时索引文件(它是对索引作者/读者很重要被关闭,所以它会释放文件锁).但是,查询解析器不是线程安全的,所以每个线程使用索引应该有自己的查询解析器.

                  然而,索引编写器是线程安全,因此您可以更新索引当人们在搜索它时.但是,您必须确保具有开放索引的线程搜索者关闭它们并打开新的,以获取最新更新的数据.

                  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?

                  EDIT: 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.

                  解决方案

                  According to this page,

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

                  • Multiple index searchers can read the lucene index files at the same time.
                  • An index writer or reader can edit the lucene index files while searches are ongoing
                  • Multiple index writers or readers can try to edit the lucene index files at the same time (it's important for the index writer/reader to be closed so it will release the file lock). However, the query parser is not thread safe, so each thread using the index should have its own query parser.

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

                  上一篇:为什么过滤器不适用于 Lucene.Net 中的文本/字符串值? 下一篇:Lucene.net 范围查询 + 突出显示

                  相关文章

                    <legend id='KBe1Q'><style id='KBe1Q'><dir id='KBe1Q'><q id='KBe1Q'></q></dir></style></legend>
                      <bdo id='KBe1Q'></bdo><ul id='KBe1Q'></ul>
                  1. <tfoot id='KBe1Q'></tfoot>

                  2. <small id='KBe1Q'></small><noframes id='KBe1Q'>

                    <i id='KBe1Q'><tr id='KBe1Q'><dt id='KBe1Q'><q id='KBe1Q'><span id='KBe1Q'><b id='KBe1Q'><form id='KBe1Q'><ins id='KBe1Q'></ins><ul id='KBe1Q'></ul><sub id='KBe1Q'></sub></form><legend id='KBe1Q'></legend><bdo id='KBe1Q'><pre id='KBe1Q'><center id='KBe1Q'></center></pre></bdo></b><th id='KBe1Q'></th></span></q></dt></tr></i><div id='KBe1Q'><tfoot id='KBe1Q'></tfoot><dl id='KBe1Q'><fieldset id='KBe1Q'></fieldset></dl></div>