You can add a serialized object easily as a stored field to a document, just
serialize the object to an byte[] array and store this in the index, e.g.:
ByteArrayOutputStream serData=new ByteArrayOutputStream();
ObjectOutputStream out=new ObjectOutputStream(serData);
try {
out.writeObject(dataStringContents);
} finally {
out.close();
serData.close();
}
doc.add(new Field("fieldname", serData.toByteArray(),
Field.Store.COMPRESS));
When have done a Lucene search, you can retrieve the object like this from
an Document instance:
byte[] serData=ldoc.getBinaryValue("fieldname");
if (serData!=null) {
ObjectInputStream in=new ObjectInputStream(new
ByteArrayInputStream(serData));
try {
bla = in.readObject();
} finally {
in.close();
}
}
But this is only stored content, you cannot search inside the object,
because it is a) stored and b) Lucene does not know what terms are in it.
-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: [email protected]
> -----Original Message-----
> From: MilleBii [mailto:[email protected]]
> Sent: Friday, July 03, 2009 9:32 PM
> To: [email protected]
> Subject: Storing a serialized object ?
>
> I want to store in the index a data structure and load it back at search
> time.
>
> Is it safe to serialize the java object store it and load it back later ?
> Presumably I need to store it binary, right ?
>
> Otherwise I need to create my own store & load methods, waste of time.
>
> --
> -MilleBii-
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]