Example usage for com.liferay.portal.kernel.search Document addUID

List of usage examples for com.liferay.portal.kernel.search Document addUID

Introduction

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

Prototype

public void addUID(String portletId, String field1, String field2);

Source Link

Usage

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);
        }//from  ww w  .  jav  a 2s.  c  om

        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.wiki.util.WikiIndexer.java

License:Open Source License

@Override
protected void doDelete(Object obj) throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setSearchEngineId(SearchEngineUtil.SYSTEM_ENGINE_ID);

    if (obj instanceof Object[]) {
        Object[] array = (Object[]) obj;

        long companyId = (Long) array[0];
        long nodeId = (Long) array[1];
        String title = (String) array[2];

        Document document = new DocumentImpl();

        document.addUID(PORTLET_ID, nodeId, title);

        SearchEngineUtil.deleteDocument(companyId, document.get(Field.UID));

    } else if (obj instanceof WikiNode) {
        WikiNode node = (WikiNode) obj;// ww  w.ja va  2s. c o m

        BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);

        booleanQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);

        booleanQuery.addRequiredTerm("nodeId", node.getNodeId());

        Hits hits = SearchEngineUtil.search(node.getCompanyId(), booleanQuery, QueryUtil.ALL_POS,
                QueryUtil.ALL_POS);

        for (int i = 0; i < hits.getLength(); i++) {
            Document document = hits.doc(i);

            SearchEngineUtil.deleteDocument(node.getCompanyId(), document.get(Field.UID));
        }
    } else if (obj instanceof WikiPage) {
        WikiPage page = (WikiPage) obj;

        Document document = new DocumentImpl();

        document.addUID(PORTLET_ID, page.getNodeId(), page.getTitle());

        SearchEngineUtil.deleteDocument(page.getCompanyId(), document.get(Field.UID));
    }
}

From source file:com.liferay.portlet.wiki.util.WikiIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {
    WikiPage page = (WikiPage) obj;//from  w  w w  .  j  a  v a  2  s. c  o m

    Document document = getBaseModelDocument(PORTLET_ID, page);

    document.addUID(PORTLET_ID, page.getNodeId(), page.getTitle());

    String content = HtmlUtil.extractText(WikiUtil.convert(page, null, null, null));

    document.addText(Field.CONTENT, content);

    document.addKeyword(Field.NODE_ID, page.getNodeId());
    document.addText(Field.TITLE, page.getTitle());

    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 w  w  w  . j av a  2 s  . 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

public static String getArticleUID(String articleId, boolean isOld) {
    Document doc = new DocumentImpl();

    if (isOld) {/*from   w w  w  . j  a  va2  s  . co  m*/
        doc.addUID(PORTLET_ID, articleId, "old");
    } else {
        doc.addUID(PORTLET_ID, articleId);
    }

    return doc.get(Field.UID);
}

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);
    }/*from www  .jav  a2  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;
}