Example usage for com.liferay.portal.kernel.search Field VERSION

List of usage examples for com.liferay.portal.kernel.search Field VERSION

Introduction

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

Prototype

String VERSION

To view the source code for com.liferay.portal.kernel.search Field VERSION.

Click Source Link

Usage

From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java

License:Open Source License

protected String getDDMContentSummary(Document document, Locale snippetLocale) {

    String content = StringPool.BLANK;

    try {//  w  w w  .  j  a v a2 s . c  om
        long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
        String articleId = document.get("articleId");
        double version = GetterUtil.getDouble(document.get(Field.VERSION));

        JournalArticle article = JournalArticleLocalServiceUtil.fetchArticle(groupId, articleId, version);

        if (article == null) {
            return content;
        }

        JournalArticleDisplay articleDisplay = JournalArticleLocalServiceUtil.getArticleDisplay(article, null,
                Constants.VIEW, LocaleUtil.toLanguageId(snippetLocale), 1, null, null);

        content = HtmlUtil.escape(articleDisplay.getDescription());
        content = HtmlUtil.replaceNewLine(content);

        if (Validator.isNull(content)) {
            content = HtmlUtil.extractText(articleDisplay.getContent());
        }
    } catch (Exception e) {
        if (_log.isDebugEnabled()) {
            _log.debug(e, e);
        }
    }

    return content;
}

From source file:com.liferay.portlet.journal.util.JournalIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {
    JournalArticle article = (JournalArticle) obj;

    Document document = getBaseModelDocument(PORTLET_ID, article);

    document.addUID(PORTLET_ID, article.getGroupId(), article.getArticleId());

    Locale defaultLocale = LocaleUtil.getDefault();

    String defaultLangaugeId = LocaleUtil.toLanguageId(defaultLocale);

    String[] languageIds = getLanguageIds(defaultLangaugeId, article.getContent());

    for (String languageId : languageIds) {
        String content = extractContent(article.getContentByLocale(languageId));

        if (languageId.equals(defaultLangaugeId)) {
            document.addText(Field.CONTENT, content);
        }/* w  w w  . j  av  a2  s .c o  m*/

        document.addText(Field.CONTENT.concat(StringPool.UNDERLINE).concat(languageId), content);
    }

    document.addLocalizedText(Field.DESCRIPTION, article.getDescriptionMap());
    document.addLocalizedText(Field.TITLE, article.getTitleMap());
    document.addKeyword(Field.TYPE, article.getType());
    document.addKeyword(Field.VERSION, article.getVersion());

    document.addKeyword("articleId", article.getArticleId());
    document.addDate("displayDate", article.getDisplayDate());
    document.addKeyword("layoutUuid", article.getLayoutUuid());
    document.addKeyword("structureId", article.getStructureId());
    document.addKeyword("templateId", article.getTemplateId());

    JournalStructure structure = null;

    if (Validator.isNotNull(article.getStructureId())) {
        try {
            structure = JournalStructureLocalServiceUtil.getStructure(article.getGroupId(),
                    article.getStructureId());
        } catch (NoSuchStructureException nsse1) {
            Group group = GroupLocalServiceUtil.getCompanyGroup(article.getCompanyId());

            try {
                structure = JournalStructureLocalServiceUtil.getStructure(group.getGroupId(),
                        article.getStructureId());
            } catch (NoSuchStructureException nsse2) {
            }
        }
    }

    processStructure(structure, document, article.getContent());

    return document;
}

From source file:com.liferay.portlet.journal.util.JournalIndexer.java

License:Open Source License

@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) {

    String title = document.get(locale, Field.TITLE);

    String content = snippet;/*from   w  w  w . j ava2 s . c o m*/

    if (Validator.isNull(snippet)) {
        content = StringUtil.shorten(document.get(locale, Field.CONTENT), 200);
    }

    String groupId = document.get(Field.GROUP_ID);
    String articleId = document.get("articleId");
    String version = document.get(Field.VERSION);

    portletURL.setParameter("struts_action", "/journal/edit_article");
    portletURL.setParameter("groupId", groupId);
    portletURL.setParameter("articleId", articleId);
    portletURL.setParameter("version", version);

    return new Summary(title, content, portletURL);
}

From source file:com.liferay.portlet.softwarecatalog.util.SCIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {
    SCProductEntry productEntry = (SCProductEntry) obj;

    Document document = getBaseModelDocument(PORTLET_ID, productEntry);

    StringBundler sb = new StringBundler(15);

    String longDescription = HtmlUtil.extractText(productEntry.getLongDescription());

    sb.append(longDescription);// w ww.  j a  v a2s.  c o  m

    sb.append(StringPool.SPACE);
    sb.append(productEntry.getPageURL());
    sb.append(StringPool.SPACE);
    sb.append(productEntry.getRepoArtifactId());
    sb.append(StringPool.SPACE);
    sb.append(productEntry.getRepoGroupId());
    sb.append(StringPool.SPACE);

    String shortDescription = HtmlUtil.extractText(productEntry.getShortDescription());

    sb.append(shortDescription);

    sb.append(StringPool.SPACE);
    sb.append(productEntry.getType());
    sb.append(StringPool.SPACE);
    sb.append(productEntry.getUserId());
    sb.append(StringPool.SPACE);

    String userName = PortalUtil.getUserName(productEntry.getUserId(), productEntry.getUserName());

    sb.append(userName);

    document.addText(Field.CONTENT, sb.toString());

    document.addText(Field.TITLE, productEntry.getName());
    document.addKeyword(Field.TYPE, productEntry.getType());

    String version = StringPool.BLANK;

    SCProductVersion latestProductVersion = productEntry.getLatestVersion();

    if (latestProductVersion != null) {
        version = latestProductVersion.getVersion();
    }

    document.addKeyword(Field.VERSION, version);

    document.addText("longDescription", longDescription);
    document.addText("pageURL", productEntry.getPageURL());
    document.addKeyword("repoArtifactId", productEntry.getRepoArtifactId());
    document.addKeyword("repoGroupId", productEntry.getRepoGroupId());
    document.addText("shortDescription", shortDescription);

    return document;
}

From source file:org.xcolab.portlets.search.Indexer.java

License:Open Source License

public static Document getArticleDocument(long companyId, long groupId, String articleId, double version,
        String title, String description, String content, String type, Date displayDate,
        String[] tagsCategories, String[] tagsEntries, ExpandoBridge expandoBridge) {

    if ((content != null)
            && ((content.indexOf("<dynamic-content") != -1) || (content.indexOf("<static-content") != -1))) {

        content = _getIndexableContent(content);

        content = StringUtil.replace(content, "<![CDATA[", StringPool.BLANK);
        content = StringUtil.replace(content, "]]>", StringPool.BLANK);
    }/*from www .j  a v  a 2s. c  o m*/

    content = StringUtil.replace(content, "&amp;", "&");
    content = StringUtil.replace(content, "&lt;", "<");
    content = StringUtil.replace(content, "&gt;", ">");

    content = HtmlUtil.extractText(content);

    Document doc = new DocumentImpl();

    // check if this is an most recent version of an article
    JournalArticle article;
    boolean isOld = false;
    try {
        article = JournalArticleLocalServiceUtil.getArticle(groupId, articleId);
        if (article.getVersion() != version) {
            isOld = true;
        }
    } catch (Exception e1) {
        e1.printStackTrace();
        // ignore
    }

    if (isOld) {
        doc.addUID(PORTLET_ID, articleId, "old");
    } else {
        doc.addUID(PORTLET_ID, articleId);
    }

    doc.addModifiedDate(displayDate);

    doc.addKeyword(Field.COMPANY_ID, companyId);
    doc.addKeyword(Field.PORTLET_ID, PORTLET_ID);
    doc.addKeyword(Field.GROUP_ID, groupId);

    doc.addText(Field.TITLE, title);
    doc.addText(Field.CONTENT, content);
    doc.addText(Field.DESCRIPTION, description);

    doc.addKeyword(Field.ENTRY_CLASS_PK, articleId);
    doc.addKeyword(Field.VERSION, version);
    doc.addKeyword(Field.TYPE, type);

    ExpandoBridgeIndexerUtil.addAttributes(doc, expandoBridge);

    try {
        Layout pageLayout = getLayoutForContent(articleId);

        if (pageLayout != null) {
            Layout tmp = pageLayout;
            boolean isAbout = false;
            while (tmp != null && !isAbout) {
                if (tmp.getFriendlyURL().toLowerCase().contains("/about")
                        || tmp.getFriendlyURL().toLowerCase().contains("/contests")) {
                    isAbout = true;
                }
                if (tmp.getParentLayoutId() > 0) {
                    try {
                        tmp = LayoutLocalServiceUtil.getLayout(tmp.getGroupId(), tmp.getPrivateLayout(),
                                tmp.getParentLayoutId());

                    } catch (com.liferay.portal.NoSuchLayoutException e) {
                        tmp = null;
                    } catch (PortalException e) {
                        tmp = null;
                    }
                } else {
                    tmp = null;
                }
            }

            if (isAbout) {
                doc.addKeyword("PAGE_URL", pageLayout.getFriendlyURL());
                doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName() + ".index");
            }
        } else {
            doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName());
        }
    } catch (SystemException e) {
        doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName());
        e.printStackTrace();
    }
    return doc;
}

From source file:org.xcolab.portlets.search.Indexer.java

License:Open Source License

@Override
public Document getDocument(Object obj) throws SearchException {
    JournalArticle article = (JournalArticle) obj;

    String articleId = article.getArticleId();
    long groupId = article.getGroupId();
    long companyId = article.getCompanyId();
    double version = article.getVersion();

    String content = article.getContent();
    String title = article.getTitle();
    Date displayDate = article.getDisplayDate();
    String description = article.getDescription();
    String type = article.getType();
    ExpandoBridge expandoBridge = article.getExpandoBridge();

    if ((content != null)
            && ((content.indexOf("<dynamic-content") != -1) || (content.indexOf("<static-content") != -1))) {

        content = _getIndexableContent(content);

        content = StringUtil.replace(content, "<![CDATA[", StringPool.BLANK);
        content = StringUtil.replace(content, "]]>", StringPool.BLANK);
    }/*  w  w w  . ja va  2  s.co  m*/

    content = StringUtil.replace(content, "&amp;", "&");
    content = StringUtil.replace(content, "&lt;", "<");
    content = StringUtil.replace(content, "&gt;", ">");

    content = HtmlUtil.extractText(content);

    Document doc = new DocumentImpl();

    // check if this is an most recent version of an article
    boolean isOld = false;
    try {
        JournalArticle tmpArticle = JournalArticleLocalServiceUtil.getArticle(groupId,
                String.valueOf(articleId));
        if (article.getVersion() != version) {
            isOld = true;
        }
    } catch (Exception e1) {
        e1.printStackTrace();
        // ignore
    }

    if (isOld) {
        doc.addUID(PORTLET_ID, articleId, "old");
    } else {
        doc.addUID(PORTLET_ID, articleId);
    }

    doc.addModifiedDate(displayDate);

    doc.addKeyword(Field.COMPANY_ID, companyId);
    doc.addKeyword(Field.PORTLET_ID, PORTLET_ID);
    doc.addKeyword(Field.GROUP_ID, groupId);

    doc.addText(Field.TITLE, title);
    doc.addText(Field.CONTENT, content);
    doc.addText(Field.DESCRIPTION, description);

    doc.addKeyword(Field.ENTRY_CLASS_PK, articleId);
    doc.addKeyword(Field.VERSION, version);
    doc.addKeyword(Field.TYPE, type);

    ExpandoBridgeIndexerUtil.addAttributes(doc, expandoBridge);

    try {
        Layout pageLayout = getLayoutForContent(articleId);

        if (pageLayout != null) {
            Layout tmp = pageLayout;
            boolean isAbout = false;
            while (tmp != null && !isAbout) {
                if (tmp.getFriendlyURL().toLowerCase().contains("/about")
                        || tmp.getFriendlyURL().toLowerCase().contains("/contests")) {
                    isAbout = true;
                }
                if (tmp.getParentLayoutId() > 0) {
                    try {
                        tmp = LayoutLocalServiceUtil.getLayout(tmp.getGroupId(), tmp.getPrivateLayout(),
                                tmp.getParentLayoutId());

                    } catch (com.liferay.portal.NoSuchLayoutException e) {
                        tmp = null;
                    } catch (PortalException e) {
                        tmp = null;
                    }
                } else {
                    tmp = null;
                }
            }

            if (isAbout) {
                doc.addKeyword("PAGE_URL", pageLayout.getFriendlyURL());
                doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName() + ".index");
            }
        } else {
            doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName());
        }
    } catch (SystemException e) {
        doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName());
        e.printStackTrace();
    }
    return doc;
}