use of org.apache.cxf.jaxrs.ext.search.tika.LuceneDocumentMetadata in project cxf by apache.
the class BookCatalog method addBook.
@POST
@Consumes("multipart/form-data")
public Response addBook(final MultipartBody body) throws Exception {
for (final Attachment attachment : body.getAllAttachments()) {
final DataHandler handler = attachment.getDataHandler();
if (handler != null) {
final String source = handler.getName();
final LuceneDocumentMetadata metadata = new LuceneDocumentMetadata().withSource(source).withField("modified", Date.class).withField("dcterms:modified", Date.class);
final Document document = extractor.extract(handler.getInputStream(), metadata);
if (document != null) {
try (IndexWriter writer = getIndexWriter()) {
writer.addDocument(document);
writer.commit();
}
}
}
}
return Response.ok().build();
}
Aggregations