Search in sources :

Example 1 with LuceneDocumentMetadata

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();
}
Also used : LuceneDocumentMetadata(org.apache.cxf.jaxrs.ext.search.tika.LuceneDocumentMetadata) IndexWriter(org.apache.lucene.index.IndexWriter) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) DataHandler(javax.activation.DataHandler) Document(org.apache.lucene.document.Document) Date(java.util.Date) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

Date (java.util.Date)1 DataHandler (javax.activation.DataHandler)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Attachment (org.apache.cxf.jaxrs.ext.multipart.Attachment)1 LuceneDocumentMetadata (org.apache.cxf.jaxrs.ext.search.tika.LuceneDocumentMetadata)1 Document (org.apache.lucene.document.Document)1 IndexWriter (org.apache.lucene.index.IndexWriter)1