lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <>
Subject Re: Get DocID after Document insert?
Date Wed, 24 Dec 2008 13:59:43 GMT
You're really, really playing with fire here. Your document IDs may
change, and in fact *will* change if you delete a document and
then optimize. Say you index 100 docs, delete number 50 and
optimize. Documents that originally had IDs 51-100 will now have
IDs 50-99 and your hierarchy will be messed up.

And saying "I'll never delete and then optimize" is just asking for
trouble <G>...

So just make your own ID that don't change and use *that* to
maintain your hierarchy. You can get at these pretty efficiently with
TermDocs/TermEnum and could, say at startup, read your unique
IDs into a map along with their current Lucene ID if you really care
that much about speed. This could just be a simple counter and
you could find the maximum one currently in your index when you
needed to add more documents to the index using the methods
I mentioned.


On Wed, Dec 24, 2008 at 8:35 AM, Ian Vink <> wrote:

> I am building up an index with documents that are hierarchical in their
> relationship to each other. After I insert a Document into the index, how
> do
> I know its document ID? I need that to pass to the next document as the
> "ParentID"
> Ian

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message