use of com.zimbra.cs.index.IndexDocument in project zm-mailbox by Zimbra.
the class MimeHandler method getDocument.
/**
* Returns a Lucene document to index this content.
*
* @return Lucene document
* @throws MimeHandlerException if a MIME parser error occurred
* @throws ObjectHandlerException if a Zimlet error occurred
* @throws ServiceException if other error occurred
*/
public final Document getDocument() throws MimeHandlerException, ObjectHandlerException, ServiceException {
IndexDocument doc = new IndexDocument(new Document());
doc.addMimeType(new MimeTypeTokenStream(getContentType()));
addFields(doc.toDocument());
String content = getContent();
doc.addContent(content);
getObjects(content, doc);
doc.addPartName(partName);
if (dataSource != null) {
String name = dataSource.getName();
if (name != null) {
try {
name = MimeUtility.decodeText(name);
} catch (UnsupportedEncodingException ignore) {
}
doc.addFilename(name);
}
}
return doc.toDocument();
}
use of com.zimbra.cs.index.IndexDocument in project zm-mailbox by Zimbra.
the class IndexItem method redo.
@Override
public void redo() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
MailItem item;
try {
item = mbox.getItemById(null, mId, type);
} catch (MailServiceException.NoSuchItemException e) {
// problem. So just ignore the NoSuchItemException.
return;
}
try {
List<IndexDocument> docList = item.generateIndexData();
mbox.index.redoIndexItem(item, mId, docList);
} catch (Exception e) {
// TODO - update the item and set the item's "unindexed" flag
ZimbraLog.index.info("Caught exception attempting to replay IndexItem for ID " + mId + " item will not be indexed", e);
}
}
use of com.zimbra.cs.index.IndexDocument in project zm-mailbox by Zimbra.
the class ParsedMessage method handleParseError.
/**
* Log the error and index minimum information.
*
* @param mpi MIME info
* @param error error to handle
*/
private void handleParseError(MPartInfo mpi, Throwable error) {
numParseErrors++;
LOG.warn("Unable to parse part=%s filename=%s content-type=%s message-id=%s", mpi.getPartName(), mpi.getFilename(), mpi.getContentType(), getMessageID(), error);
if (ConversionException.isTemporaryCauseOf(error)) {
temporaryAnalysisFailure = true;
}
if (!Strings.isNullOrEmpty(mpi.getFilename())) {
filenames.add(mpi.getFilename());
}
IndexDocument doc = new IndexDocument(new Document());
doc.addMimeType(new MimeTypeTokenStream(mpi.getContentType()));
doc.addPartName(mpi.getPartName());
doc.addFilename(mpi.getFilename());
try {
doc.addSortSize(mpi.getMimePart().getSize());
} catch (MessagingException ignore) {
}
luceneDocuments.add(setLuceneHeadersFromContainer(doc));
}
use of com.zimbra.cs.index.IndexDocument in project zm-mailbox by Zimbra.
the class Document method generateIndexData.
@Override
public List<IndexDocument> generateIndexData() throws TemporaryIndexingException {
try {
MailboxBlob mblob = getBlob();
if (mblob == null) {
ZimbraLog.index.warn("Unable to fetch blob for Document id=%d,ver=%d,vol=%s", mId, mVersion, getLocator());
throw new MailItem.TemporaryIndexingException();
}
ParsedDocument pd = null;
pd = new ParsedDocument(mblob.getLocalBlob(), getName(), getContentType(), getChangeDate(), getCreator(), getDescription(), isDescriptionEnabled());
if (pd.hasTemporaryAnalysisFailure()) {
throw new MailItem.TemporaryIndexingException();
}
IndexDocument doc = pd.getDocument();
if (doc != null) {
List<IndexDocument> toRet = new ArrayList<IndexDocument>(1);
toRet.add(doc);
return toRet;
} else {
return new ArrayList<IndexDocument>(0);
}
} catch (IOException e) {
ZimbraLog.index.warn("Error generating index data for Wiki Document " + getId() + ". Item will not be indexed", e);
return new ArrayList<IndexDocument>(0);
} catch (ServiceException e) {
ZimbraLog.index.warn("Error generating index data for Wiki Document " + getId() + ". Item will not be indexed", e);
return new ArrayList<IndexDocument>(0);
}
}
use of com.zimbra.cs.index.IndexDocument in project zm-mailbox by Zimbra.
the class MessageTest method indexRawMimeMessage.
@Test
public void indexRawMimeMessage() throws Exception {
Account account = Provisioning.getInstance().getAccountById(MockProvisioning.DEFAULT_ACCOUNT_ID);
account.setPrefMailDefaultCharset("ISO-2022-JP");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
byte[] raw = ByteStreams.toByteArray(getClass().getResourceAsStream("raw-jis-msg.txt"));
ParsedMessage pm = new ParsedMessage(raw, false);
Message message = mbox.addMessage(null, pm, dopt, null);
Assert.assertEquals("日本語", pm.getFragment(null));
List<IndexDocument> docs = message.generateIndexData();
Assert.assertEquals(2, docs.size());
String subject = docs.get(0).toDocument().get(LuceneFields.L_H_SUBJECT);
String body = docs.get(0).toDocument().get(LuceneFields.L_CONTENT);
Assert.assertEquals("日本語", subject);
Assert.assertEquals("日本語", body.trim());
}
Aggregations