Just add another document (I do something similar). The key is to remember
that documents in the same index do NOT have to have the same fields. So,
say for your "regular" documents, you have fields (f1, f2, f3, f4). For your
meta-data document, you index fields (md1, md2, md3...). The value for one
of these fields should be a known value (note, the value is completely
bogus, just so you remember it). Say index a value of "1" for md1 in your
meta-data document.

Now, to get your meta-data document, do a simple search on your known value
(e.g. md1="1") and read the rest of the document in whatever form is most
convenient. You can stuff anything you want in there, however you want. You
could index one field for everything you care about, or put it in a glob
that you parse. It's completely up to you.

The beauty of this is that, if you want to change your meta-data, all you
have to do is delete your meta-data doc and re-add it with new values, you
don't have to regenerate your index. And since your fields are orthogonal,
there's no danger of getting your meta-data doc as part of your regular
search.

One word of warning. Do NOT depend on the internal Lucene doc IDs (e.g.
reader.doc(idx)) being consistent. These internal numbers are not guaranteed
to be the same across an index optimize.

Hope this helps
Erick

On 9/12/06, Mag Gam <[EMAIL PROTECTED]> wrote:

Tom:

great! Now do you do you add metadata? I am new to Lucene API + Java, but
willing to learn.

Got an example?

TIA

On 9/12/06, Tom Emerson <[EMAIL PROTECTED]> wrote:
>
> As far as I know there isn't a way to do this. What we do is add a
> "metadata" document to each index that includes the creation date, the
> user
> name of the creating user, and various other tidbits. This gets updated
on
> incremental updates to the index as well. Easily done and makes it easy
to
> query.
>
> On 9/9/06, Mag Gam <[EMAIL PROTECTED]> wrote:
> >
> > Hi All,
> >
> > I am trying to get the exact date when my index was created. I am
> assuming
> > getCurrentVersion() is the right way of doing it. However, I am
getting
> a
> > result something like this: 1157817833085
> >
> > According to the API reference,
> > "Reads version number from segments files. The version number is
> > initialized
> > with a timestamp and then increased by one for each change of the
> index."
> >
> > So, to get the date of this, I should be doing something like this:
> > date=1157817833085-1;
> >
> > Any thoughts?
> > tia
> >
> >
>
>
> --
> Tom Emerson
> [EMAIL PROTECTED]
> http://www.dreamersrealm.net/~tree
>
>


Reply via email to