• <bdo id='jgfMf'></bdo><ul id='jgfMf'></ul>

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

      <legend id='jgfMf'><style id='jgfMf'><dir id='jgfMf'><q id='jgfMf'></q></dir></style></legend>

    1. <small id='jgfMf'></small><noframes id='jgfMf'>

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

        时间:2023-09-30

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

            • <bdo id='Zrppq'></bdo><ul id='Zrppq'></ul>

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

              <legend id='Zrppq'><style id='Zrppq'><dir id='Zrppq'><q id='Zrppq'></q></dir></style></legend>
                <tfoot id='Zrppq'></tfoot>

                    <tbody id='Zrppq'></tbody>
                1. 本文介绍了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 良好实践和线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

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

                  相关文章

                  最新文章

                  <tfoot id='F0Nmw'></tfoot>

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

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

                      <bdo id='F0Nmw'></bdo><ul id='F0Nmw'></ul>
                    <legend id='F0Nmw'><style id='F0Nmw'><dir id='F0Nmw'><q id='F0Nmw'></q></dir></style></legend>