• <tfoot id='mafBQ'></tfoot>

    <small id='mafBQ'></small><noframes id='mafBQ'>

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

      <bdo id='mafBQ'></bdo><ul id='mafBQ'></ul>

      1. lucene 良好实践和线程安全

        时间:2023-06-29

        1. <tfoot id='pcvPv'></tfoot>

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

              • <small id='pcvPv'></small><noframes id='pcvPv'>

                  <bdo id='pcvPv'></bdo><ul id='pcvPv'></ul>
                  <legend id='pcvPv'><style id='pcvPv'><dir id='pcvPv'><q id='pcvPv'></q></dir></style></legend>
                  本文介绍了lucene 良好实践和线程安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 lucene 来索引文档并执行搜索,然后我立即删除它们.所有这些都可以被认为是一个有点原子的动作,包括以下步骤:

                  i'm using lucene to index documents and perform a search after which, i immediately delete them. all this can be considered as a somewhat atomic action that includes the following steps:

                  index (writer) --> search (searcher) --> 按分数获取文档(读者)-->删除文档(读者)

                  index (writer) --> search (searcher) --> get docs by score (reader) --> delete docs (reader)

                  这个动作可以由多个并发线程在同一个索引上执行(使用FSDirectory).

                  this action can be performed by multiple concurrent threads on the same index (using FSDirectory).

                  重要提示:每个线程处理一组单独的文档,因此一个线程不会接触另一个线程的文档

                  IMPORTANT NOTE: each thread handles a separate set of documents so one thread will not touch another thread's documents

                  为此,我有几个问题:

                  1) 我应该使用 IndexWriterIndexReaderIndexSearcher 的单个实例(用于所有线程)吗?(它们应该是线程安全的)

                  1) should i use a single instances (for all threads) of IndexWriter, IndexReader and IndexSearcher? (they're supposed to be thread safe)

                  2) IndexWriter 可以在 IndexReader 删除文档时操作索引吗?我需要关闭一个让另一个做它的事情吗?意思是,一个线程可以写入索引而另一个线程从中删除(正如我之前提到的,我可以保证它们处理单独的数据集)

                  2) can an IndexWriter manipulate an index while and IndexReader deletes documents? do i need to close one for the other to do its thing? meaning, can one thread write to an index while another one deletes from it (as i mentioned earlier, i can guarantee that they handle separate sets of data)

                  3) 您可能提出的任何其他良好做法和建议将不胜感激.

                  3) any other good practices and suggestions you might have will be most appreciated.

                  非常感谢!

                  推荐答案

                  IndexWriter, IndexReaderIndexSearcher 根据 api javadoc 线程安全:

                  IndexWriter, IndexReader and IndexSearcher are thread-safe according to the api javadoc:

                  注意:IndexSearcher 实例是完全线程安全的,这意味着多个线程可以同时调用它的任何方法

                  NOTE: IndexSearcher instances are completely thread safe, meaning multiple threads can call any of its methods, concurrently

                  注意:IndexReader 实例是完全线程安全的,这意味着多个线程可以同时调用它的任何方法.

                  NOTE: IndexReader instances are completely thread safe, meaning multiple threads can call any of its methods, concurrently.

                  注意:IndexWriter 实例是完全线程安全的,这意味着多个线程可以同时调用它的任何方法

                  NOTE: IndexWriter instances are completely thread safe, meaning multiple threads can call any of its methods, concurrently

                  可以打开多个只读IndexReader,但最好共享一个(出于性能原因).

                  Multiple read-only IndexReaders can be opened, but it's better to share one (for performance reasons).

                  只能打开一个IndexWriter(它会创建一个写锁来防止其他人在同一个索引上被打开).您可以使用 IndexReader 删除文档,而 IndexWriter 持有此锁.IndexReader 将始终看到打开时的索引,编写器所做的更改只有在编写器提交后才可见,阅读器重新打开.

                  Only a single IndexWriter can be opened (and it will create a write lock to prevent others from being opened on the same index). You can use IndexReader to delete documents while IndexWriter holds this lock. IndexReader will always see the index as it was at the time when it was opened, changes done by the writer will be visible only after the writer commits them the reader is reopened.

                  可以打开任意数量的 IndexSearcher,但最好还是共享一个.即使在修改索引时也可以使用它们.与 IndexReader 的工作方式相同(在重新打开搜索器之前,更改不可见).

                  Any number of IndexSearchers can be opened, but again it's better to share one. They can be used even while the index is being modified. Works the same as for IndexReader (the changes are not visible until the searcher is reopened).

                  这篇关于lucene 良好实践和线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:lucene 在查询中获得匹配的术语 下一篇:Lucene 中的 {Filter} 比 {Query} 快吗?

                  相关文章

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