Mailing List Archive

How to replace deprecated document(i)
Hi

I recently noctived that

IndexReader.document(int)

is deprecated, whereas my code is currently

TopDocs topDocs = searcher.search(query, k);
for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
??? Document doc = indexReader.document(scoreDoc.doc);
}

How do I best replace document(int)?

Thanks

Michael

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: How to replace deprecated document(i) [ In reply to ]
Hi Michael,

You could replace this with
*indexReader.storedFields().document(scoreDoc.doc)*

Docs -
https://lucene.apache.org/core/9_7_0/core/org/apache/lucene/index/StoredFields.html#document(int)

- Shubham

On Mon, Sep 25, 2023 at 1:59?AM Michael Wechner <michael.wechner@wyona.com>
wrote:

> Hi
>
> I recently noctived that
>
> IndexReader.document(int)
>
> is deprecated, whereas my code is currently
>
> TopDocs topDocs = searcher.search(query, k);
> for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
> Document doc = indexReader.document(scoreDoc.doc);
> }
>
> How do I best replace document(int)?
>
> Thanks
>
> Michael
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
Re: How to replace deprecated document(i) [ In reply to ]
Hi Shubham

Great, thank you very much!

Michael

Am 25.09.23 um 02:14 schrieb Shubham Chaudhary:
> Hi Michael,
>
> You could replace this with
> *indexReader.storedFields().document(scoreDoc.doc)*
>
> Docs -
> https://lucene.apache.org/core/9_7_0/core/org/apache/lucene/index/StoredFields.html#document(int)
>
> - Shubham
>
> On Mon, Sep 25, 2023 at 1:59?AM Michael Wechner <michael.wechner@wyona.com>
> wrote:
>
>> Hi
>>
>> I recently noctived that
>>
>> IndexReader.document(int)
>>
>> is deprecated, whereas my code is currently
>>
>> TopDocs topDocs = searcher.search(query, k);
>> for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
>> Document doc = indexReader.document(scoreDoc.doc);
>> }
>>
>> How do I best replace document(int)?
>>
>> Thanks
>>
>> Michael
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: How to replace deprecated document(i) [ In reply to ]
Background: For performance, it is advisable to get the storedFields()
*once* to process all documents in the search result. The resason for
the change was the problem of accessing stored fields would otherwise
need to use ThreadLocals to keep state.

Issue: https://github.com/apache/lucene/pull/11998

This was introduced in Lucene 9.5.

It is also listed in MIGRATE.txt:

### Removed deprecated IndexSearcher.doc, IndexReader.document,
IndexReader.getTermVectors (GITHUB#11998)

The deprecated Stored Fields and Term Vectors apis relied upon
threadlocal storage and have been removed.

Instead, call storedFields()/termVectors() to return an instance
which can fetch data for multiple documents,
and will be garbage-collected as usual.

For example:
```java
TopDocs hits = searcher.search(query, 10);
StoredFields storedFields = reader.storedFields();
for (ScoreDoc hit : hits.scoreDocs) {
  Document doc = storedFields.document(hit.doc);
}
```

Note that these StoredFields and TermVectors instances should only
be consumed in the thread where
they were acquired. For instance, it is illegal to share them across
threads.

Uwe

Am 25.09.2023 um 07:53 schrieb Michael Wechner:
> Hi Shubham
>
> Great, thank you very much!
>
> Michael
>
> Am 25.09.23 um 02:14 schrieb Shubham Chaudhary:
>> Hi Michael,
>>
>> You could replace this with
>> *indexReader.storedFields().document(scoreDoc.doc)*
>>
>> Docs -
>> https://lucene.apache.org/core/9_7_0/core/org/apache/lucene/index/StoredFields.html#document(int)
>>
>>
>> - Shubham
>>
>> On Mon, Sep 25, 2023 at 1:59?AM Michael Wechner
>> <michael.wechner@wyona.com>
>> wrote:
>>
>>> Hi
>>>
>>> I recently noctived that
>>>
>>> IndexReader.document(int)
>>>
>>> is deprecated, whereas my code is currently
>>>
>>> TopDocs topDocs = searcher.search(query, k);
>>> for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
>>>       Document doc = indexReader.document(scoreDoc.doc);
>>> }
>>>
>>> How do I best replace document(int)?
>>>
>>> Thanks
>>>
>>> Michael
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>>
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
--
Uwe Schindler
Achterdiek 19, D-28357 Bremen
https://www.thetaphi.de
eMail:uwe@thetaphi.de
Re: How to replace deprecated document(i) [ In reply to ]
you mean once per search request?

I mean for example

GET https://localhost:8080/search?q=Lucene

and the following would be executed

IndexReader reader = DirectoryReader.open(...);
StoredFields  storedfields = reader.storedFields();
IndexSearcher searcher = new IndexSearcher(reader)
TopDocs topDocs = searcher.search(query, k)
for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
      Document doc = storedFields.document(scoreDoc.doc);
}

Like this?

Thanks

Michael


Am 25.09.23 um 10:28 schrieb Uwe Schindler:
> Background: For performance, it is advisable to get the storedFields()
> *once* to process all documents in the search result. The resason for
> the change was the problem of accessing stored fields would otherwise
> need to use ThreadLocals to keep state.
>
> Issue: https://github.com/apache/lucene/pull/11998
>
> This was introduced in Lucene 9.5.
>
> It is also listed in MIGRATE.txt:
>
>    ### Removed deprecated IndexSearcher.doc, IndexReader.document,
>    IndexReader.getTermVectors (GITHUB#11998)
>
>    The deprecated Stored Fields and Term Vectors apis relied upon
>    threadlocal storage and have been removed.
>
>    Instead, call storedFields()/termVectors() to return an instance
>    which can fetch data for multiple documents,
>    and will be garbage-collected as usual.
>
>    For example:
>    ```java
>    TopDocs hits = searcher.search(query, 10);
>    StoredFields storedFields = reader.storedFields();
>    for (ScoreDoc hit : hits.scoreDocs) {
>       Document doc = storedFields.document(hit.doc);
>    }
>    ```
>
>    Note that these StoredFields and TermVectors instances should only
>    be consumed in the thread where
>    they were acquired. For instance, it is illegal to share them across
>    threads.
>
> Uwe
>
> Am 25.09.2023 um 07:53 schrieb Michael Wechner:
>> Hi Shubham
>>
>> Great, thank you very much!
>>
>> Michael
>>
>> Am 25.09.23 um 02:14 schrieb Shubham Chaudhary:
>>> Hi Michael,
>>>
>>> You could replace this with
>>> *indexReader.storedFields().document(scoreDoc.doc)*
>>>
>>> Docs -
>>> https://lucene.apache.org/core/9_7_0/core/org/apache/lucene/index/StoredFields.html#document(int)
>>>
>>>
>>> - Shubham
>>>
>>> On Mon, Sep 25, 2023 at 1:59?AM Michael Wechner
>>> <michael.wechner@wyona.com>
>>> wrote:
>>>
>>>> Hi
>>>>
>>>> I recently noctived that
>>>>
>>>> IndexReader.document(int)
>>>>
>>>> is deprecated, whereas my code is currently
>>>>
>>>> TopDocs topDocs = searcher.search(query, k);
>>>> for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
>>>>       Document doc = indexReader.document(scoreDoc.doc);
>>>> }
>>>>
>>>> How do I best replace document(int)?
>>>>
>>>> Thanks
>>>>
>>>> Michael
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>>>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>>>
>>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: How to replace deprecated document(i) [ In reply to ]
Hi,

yes once per search request is the best to start with.

You can reuse the instance for multiple requests, but you cannot use it
from multiple threads. So it is up to you to make sure you reuse it at
best effort.

See also the documentation I posted from MIGRATE.txt.

If the documentation is missing, maybe let's open a pull request that
gives the missing information in 9.x Javadocs, too.

Uwe

Am 25.09.2023 um 11:02 schrieb Michael Wechner:
> you mean once per search request?
>
> I mean for example
>
> GET https://localhost:8080/search?q=Lucene
>
> and the following would be executed
>
> IndexReader reader = DirectoryReader.open(...);
> StoredFields  storedfields = reader.storedFields();
> IndexSearcher searcher = new IndexSearcher(reader)
> TopDocs topDocs = searcher.search(query, k)
> for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
>       Document doc = storedFields.document(scoreDoc.doc);
> }
>
> Like this?
>
> Thanks
>
> Michael
>
>
> Am 25.09.23 um 10:28 schrieb Uwe Schindler:
>> Background: For performance, it is advisable to get the
>> storedFields() *once* to process all documents in the search result.
>> The resason for the change was the problem of accessing stored fields
>> would otherwise need to use ThreadLocals to keep state.
>>
>> Issue: https://github.com/apache/lucene/pull/11998
>>
>> This was introduced in Lucene 9.5.
>>
>> It is also listed in MIGRATE.txt:
>>
>>    ### Removed deprecated IndexSearcher.doc, IndexReader.document,
>>    IndexReader.getTermVectors (GITHUB#11998)
>>
>>    The deprecated Stored Fields and Term Vectors apis relied upon
>>    threadlocal storage and have been removed.
>>
>>    Instead, call storedFields()/termVectors() to return an instance
>>    which can fetch data for multiple documents,
>>    and will be garbage-collected as usual.
>>
>>    For example:
>>    ```java
>>    TopDocs hits = searcher.search(query, 10);
>>    StoredFields storedFields = reader.storedFields();
>>    for (ScoreDoc hit : hits.scoreDocs) {
>>       Document doc = storedFields.document(hit.doc);
>>    }
>>    ```
>>
>>    Note that these StoredFields and TermVectors instances should only
>>    be consumed in the thread where
>>    they were acquired. For instance, it is illegal to share them across
>>    threads.
>>
>> Uwe
>>
>> Am 25.09.2023 um 07:53 schrieb Michael Wechner:
>>> Hi Shubham
>>>
>>> Great, thank you very much!
>>>
>>> Michael
>>>
>>> Am 25.09.23 um 02:14 schrieb Shubham Chaudhary:
>>>> Hi Michael,
>>>>
>>>> You could replace this with
>>>> *indexReader.storedFields().document(scoreDoc.doc)*
>>>>
>>>> Docs -
>>>> https://lucene.apache.org/core/9_7_0/core/org/apache/lucene/index/StoredFields.html#document(int)
>>>>
>>>>
>>>> - Shubham
>>>>
>>>> On Mon, Sep 25, 2023 at 1:59?AM Michael Wechner
>>>> <michael.wechner@wyona.com>
>>>> wrote:
>>>>
>>>>> Hi
>>>>>
>>>>> I recently noctived that
>>>>>
>>>>> IndexReader.document(int)
>>>>>
>>>>> is deprecated, whereas my code is currently
>>>>>
>>>>> TopDocs topDocs = searcher.search(query, k);
>>>>> for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
>>>>>       Document doc = indexReader.document(scoreDoc.doc);
>>>>> }
>>>>>
>>>>> How do I best replace document(int)?
>>>>>
>>>>> Thanks
>>>>>
>>>>> Michael
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>>>>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>>>>
>>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
--
Uwe Schindler
Achterdiek 19, D-28357 Bremen
https://www.thetaphi.de
eMail: uwe@thetaphi.de


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: How to replace deprecated document(i) [ In reply to ]
cool, thank you very much!

I will try to do a pull request re the javadoc documentation, because I
think it currently does not tell explicitely how to replace the
deprecated method.

Thanks

Michael

Am 25.09.23 um 11:11 schrieb Uwe Schindler:
> Hi,
>
> yes once per search request is the best to start with.
>
> You can reuse the instance for multiple requests, but you cannot use
> it from multiple threads. So it is up to you to make sure you reuse it
> at best effort.
>
> See also the documentation I posted from MIGRATE.txt.
>
> If the documentation is missing, maybe let's open a pull request that
> gives the missing information in 9.x Javadocs, too.
>
> Uwe
>
> Am 25.09.2023 um 11:02 schrieb Michael Wechner:
>> you mean once per search request?
>>
>> I mean for example
>>
>> GET https://localhost:8080/search?q=Lucene
>>
>> and the following would be executed
>>
>> IndexReader reader = DirectoryReader.open(...);
>> StoredFields  storedfields = reader.storedFields();
>> IndexSearcher searcher = new IndexSearcher(reader)
>> TopDocs topDocs = searcher.search(query, k)
>> for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
>>       Document doc = storedFields.document(scoreDoc.doc);
>> }
>>
>> Like this?
>>
>> Thanks
>>
>> Michael
>>
>>
>> Am 25.09.23 um 10:28 schrieb Uwe Schindler:
>>> Background: For performance, it is advisable to get the
>>> storedFields() *once* to process all documents in the search result.
>>> The resason for the change was the problem of accessing stored
>>> fields would otherwise need to use ThreadLocals to keep state.
>>>
>>> Issue: https://github.com/apache/lucene/pull/11998
>>>
>>> This was introduced in Lucene 9.5.
>>>
>>> It is also listed in MIGRATE.txt:
>>>
>>>    ### Removed deprecated IndexSearcher.doc, IndexReader.document,
>>>    IndexReader.getTermVectors (GITHUB#11998)
>>>
>>>    The deprecated Stored Fields and Term Vectors apis relied upon
>>>    threadlocal storage and have been removed.
>>>
>>>    Instead, call storedFields()/termVectors() to return an instance
>>>    which can fetch data for multiple documents,
>>>    and will be garbage-collected as usual.
>>>
>>>    For example:
>>>    ```java
>>>    TopDocs hits = searcher.search(query, 10);
>>>    StoredFields storedFields = reader.storedFields();
>>>    for (ScoreDoc hit : hits.scoreDocs) {
>>>       Document doc = storedFields.document(hit.doc);
>>>    }
>>>    ```
>>>
>>>    Note that these StoredFields and TermVectors instances should only
>>>    be consumed in the thread where
>>>    they were acquired. For instance, it is illegal to share them across
>>>    threads.
>>>
>>> Uwe
>>>
>>> Am 25.09.2023 um 07:53 schrieb Michael Wechner:
>>>> Hi Shubham
>>>>
>>>> Great, thank you very much!
>>>>
>>>> Michael
>>>>
>>>> Am 25.09.23 um 02:14 schrieb Shubham Chaudhary:
>>>>> Hi Michael,
>>>>>
>>>>> You could replace this with
>>>>> *indexReader.storedFields().document(scoreDoc.doc)*
>>>>>
>>>>> Docs -
>>>>> https://lucene.apache.org/core/9_7_0/core/org/apache/lucene/index/StoredFields.html#document(int)
>>>>>
>>>>>
>>>>> - Shubham
>>>>>
>>>>> On Mon, Sep 25, 2023 at 1:59?AM Michael Wechner
>>>>> <michael.wechner@wyona.com>
>>>>> wrote:
>>>>>
>>>>>> Hi
>>>>>>
>>>>>> I recently noctived that
>>>>>>
>>>>>> IndexReader.document(int)
>>>>>>
>>>>>> is deprecated, whereas my code is currently
>>>>>>
>>>>>> TopDocs topDocs = searcher.search(query, k);
>>>>>> for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
>>>>>>       Document doc = indexReader.document(scoreDoc.doc);
>>>>>> }
>>>>>>
>>>>>> How do I best replace document(int)?
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>> Michael
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>>
>>>>>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>>>>>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>>>>>
>>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>>>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org