Hi Ningshan,
If you want to make sure the deletes are applied after you call
maybeRefresh() then you need to set the applyAllDeletes to be true.

A bit more details:
The constructor of SearcherManager actually internally passes the
applyAllDeletes to the IndexWriter, which then will pass it to the
StandardDirectoryReader here
<https://github.com/apache/lucene-solr/blob/branch_7_4/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java#L524>
Then whenever you make a maybeRefresh call, the reader will try to refresh
itself using the parameters it is init'd with (src
<https://github.com/apache/lucene-solr/blob/branch_7_4/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java#L288>
)
So basically the applyAllDeletes you passed into SearcherManager will
affect every call to the maybeRefresh.

Best
Patrick

On Thu, Mar 2, 2023 at 3:03 PM Ningshan Li <ningshan...@rubrik.com> wrote:

> Hi!
>
> Hope you are all doing well! We are using searcherManager (
>
> https://lucene.apache.org/core/7_4_0/core/org/apache/lucene/search/SearcherManager.html
> )
> and get a little confused on applyAllDeletes parameter in the constructor
> and the method maybeRefresh(). In our case, we need to search over
> refreshed docs before we call writer.Commit(). So we are thinking of
> constructing the SearcherManager with applyAllDeletes true. However, we
> find there is another method ReferenceManager.maybeRefresh()
> <
> https://lucene.apache.org/core/7_4_0/core/org/apache/lucene/search/ReferenceManager.html#maybeRefresh--
> >
> where
> we refresh instances.
>
> My question is if we periodically call maybeRefresh(), and make sure the
> manager is refreshed every time before we acquire a new searcher, do we
> still need to set applyAllDeletes to true when constructing the manager?
>
> For example, I wrote a simple test like:
>
> > val manager = new SearcherManager(writer, false /*applyAllDeletes*/,
> > false, null)
> > writer.deleteDocuments(term) // delete some docs
> >
> > manager.maybeRefresh()
> > val searcher = manager.acquire()
>
> val hits = searcher.search(...)
>
> hits.totalHits shouldBe 0
>
> and the test would pass (deletes are applied)
>
>
> Sincerely,
> Ningshan
>

Reply via email to