* Convert a List of LuceneWork into a byte[]
*/
@Override
public byte[] toSerializedModel(List<LuceneWork> works) {
try {
Serializer serializer = provider.getSerializer();
serializer.luceneWorks( works );
for ( LuceneWork work : works ) {
if ( work instanceof OptimizeLuceneWork ) {
serializer.addOptimizeAll();
}
else if (work instanceof PurgeAllLuceneWork) {
serializer.addPurgeAll( work.getEntityClass().getName() );
}
else if (work instanceof FlushLuceneWork) {
serializer.addFlush();
}
else if (work instanceof DeleteLuceneWork) {
processId( work, serializer );
serializer.addDelete( work.getEntityClass().getName() );
}
else if (work instanceof AddLuceneWork ) {
buildDocument( work.getDocument(), serializer );
processId( work, serializer );
serializer.addAdd( work.getEntityClass().getName(), work.getFieldToAnalyzerMap() );
}
else if (work instanceof UpdateLuceneWork ) {
buildDocument( work.getDocument(), serializer );
processId( work, serializer );
serializer.addUpdate( work.getEntityClass().getName(), work.getFieldToAnalyzerMap() );
}
}
return serializer.serialize();
}
catch (RuntimeException e) {
if ( e instanceof SearchException ) {
throw e;
}