Example usage for com.liferay.portal.kernel.search RelatedEntryIndexer addRelatedEntryFields

List of usage examples for com.liferay.portal.kernel.search RelatedEntryIndexer addRelatedEntryFields

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.search RelatedEntryIndexer addRelatedEntryFields.

Prototype

public void addRelatedEntryFields(Document document, Object obj) throws Exception;

Source Link

Usage

From source file:com.liferay.message.boards.internal.search.MBMessageIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(MBMessage mbMessage) throws Exception {
    Document document = getBaseModelDocument(CLASS_NAME, mbMessage);

    document.addKeyword(Field.CATEGORY_ID, mbMessage.getCategoryId());
    document.addText(Field.CONTENT, processContent(mbMessage));
    document.addKeyword(Field.ROOT_ENTRY_CLASS_PK, mbMessage.getRootMessageId());
    document.addText(Field.TITLE, mbMessage.getSubject());

    if (mbMessage.isAnonymous()) {
        document.remove(Field.USER_NAME);
    }//from  ww w.java 2 s . c  om

    MBDiscussion discussion = mbDiscussionLocalService.fetchThreadDiscussion(mbMessage.getThreadId());

    if (discussion == null) {
        document.addKeyword("discussion", false);
    } else {
        document.addKeyword("discussion", true);
    }

    document.addKeyword("threadId", mbMessage.getThreadId());

    if (mbMessage.isDiscussion()) {
        List<RelatedEntryIndexer> relatedEntryIndexers = RelatedEntryIndexerRegistryUtil
                .getRelatedEntryIndexers(mbMessage.getClassName());

        if (relatedEntryIndexers != null) {
            for (RelatedEntryIndexer relatedEntryIndexer : relatedEntryIndexers) {

                Comment comment = commentManager.fetchComment(mbMessage.getMessageId());

                if (comment != null) {
                    relatedEntryIndexer.addRelatedEntryFields(document, comment);

                    document.addKeyword(Field.RELATED_ENTRY, true);
                }
            }
        }
    }

    return document;
}