Hey,

Use a StringField instead of a TextField for the title and your test will
pass.
Tokenization which is enabled for TextFields, is breaking your fancy title
into tokens split by spaces, which is causing your docs to not match.
https://lucene.apache.org/core/9_11_0/core/org/apache/lucene/document/StringField.html

Best,
Gautam Worah.


On Sat, Aug 10, 2024 at 12:05 AM Wojtek <woj...@unir.se> wrote:

> Hi Froh,
>
> thank you for the information.
>
> I updated the code and re-open the reader - it seems that the update
> is reflected and search for old document doesn't yield anything but
> the search for new term fails.
>
> I output all documents (there are 2) and the second one has new title
> but when searching for it no document is found even though it's the
> same string that has been used to update the title.
>
> On 2024-08-10T01:21:39.000+02:00, Michael Froh <msf...@gmail.com>
> wrote:
>
> > Hi Wojtek,
> >
> > Thank you for linking to your test code!
> >
> > When you open an IndexReader, it is locked to the view of the Lucene
> >
> > directory at the time that it's opened.
> >
> > If you make changes, you'll need to open a new IndexReader before those
> >
>
> > changes are visible. I see that you tried creating a new IndexSearcher, but
> >
> > unfortunately that's not sufficient.
> >
> > Hope that helps!
> >
> > Froh
> >
> > On Fri, Aug 9, 2024 at 3:25 PM Wojtek <woj...@unir.se> wrote:
> >
> >>  Hi all!
> >>
> >>   There is an effort in Apache James to update to a more modern
> >>  version of
> >>
> >>   Lucene (ref:
> >>
> >>   https://github.com/apache/james-project/pull/2342). I'm digging
> >>  into the
> >>
> >>   issue as other have done
> >>
> >>   but I'm stumped - it seems that
> >>
> >>   `org.apache.lucene.index.IndexWriter#updateDocument` doesn't
> >>  update
> >>
> >>   the document.
> >>
> >>   Documentation
> >>
> >>   (
> >>
> >>
> https://lucene.apache.org/core/9_10_0/core/org/apache/lucene/index/IndexWriter.html#updateDocument(org.apache.lucene.index.Term,java.lang.Iterable)
> )
> >>
> >>   states:
> >>
> >>   Updates a document by first deleting the document(s) containing
> >>  term
> >>
> >>   and then adding the new
> >>
> >>   document. The delete and then add are atomic as seen by a reader
> >>  on the
> >>
> >>   same index (flush may happen
> >>
> >>   only after the add).
> >>
> >>   Here is a simple test with it:
> >>
> >>
> https://github.com/woj-tek/lucene-update-test/blob/master/src/test/java/se/unir/AppTest.java
> >>
> >>   but it fails.
> >>
> >>   Any guidance would be appreciated because I (and others) have
> >>  been hitting
> >>
> >>   wall with it :)
> >>
> >>   --
> >>
> >>   Wojtek
> >>
> >>   ---------------------------------------------------------------------
> >>
> >>   To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
> >>
> >>   For additional commands, e-mail: java-user-h...@lucene.apache.org
>
>

Reply via email to