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.dynamic.data.lists.internal.search.DDLRecordIndexer.java

License:Open Source License

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

    DDLRecordVersion recordVersion = ddlRecord.getRecordVersion();

    DDLRecordSet recordSet = recordVersion.getRecordSet();

    document.addKeyword(Field.CLASS_NAME_ID, classNameLocalService.getClassNameId(DDLRecordSet.class));
    document.addKeyword(Field.CLASS_PK, recordSet.getRecordSetId());
    document.addKeyword(Field.CLASS_TYPE_ID, recordVersion.getRecordSetId());
    document.addKeyword(Field.RELATED_ENTRY, true);
    document.addKeyword(Field.STATUS, recordVersion.getStatus());
    document.addKeyword(Field.VERSION, recordVersion.getVersion());

    document.addText("ddmContent", extractDDMContent(recordVersion, LocaleUtil.getSiteDefault()));
    document.addKeyword("recordSetId", recordSet.getRecordSetId());
    document.addKeyword("recordSetScope", recordSet.getScope());

    DDMStructure ddmStructure = recordSet.getDDMStructure();

    DDMFormValues ddmFormValues = storageEngine.getDDMFormValues(recordVersion.getDDMStorageId());

    ddmIndexer.addAttributes(document, ddmStructure, ddmFormValues);

    return document;
}

From source file:com.liferay.dynamic.data.mapping.internal.search.DDMFormInstanceRecordIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(DDMFormInstanceRecord ddmFormInstanceRecord) throws Exception {

    Document document = getBaseModelDocument(CLASS_NAME, ddmFormInstanceRecord);

    DDMFormInstanceRecordVersion ddmFormInstanceRecordVersion = ddmFormInstanceRecord
            .getFormInstanceRecordVersion();

    DDMFormInstance ddmFormInstance = ddmFormInstanceRecordVersion.getFormInstance();

    document.addKeyword(Field.CLASS_NAME_ID, classNameLocalService.getClassNameId(DDMFormInstance.class));
    document.addKeyword(Field.CLASS_PK, ddmFormInstance.getFormInstanceId());
    document.addKeyword(Field.CLASS_TYPE_ID, ddmFormInstanceRecordVersion.getFormInstanceId());
    document.addKeyword(Field.RELATED_ENTRY, true);
    document.addKeyword(Field.STATUS, ddmFormInstanceRecordVersion.getStatus());
    document.addKeyword(Field.VERSION, ddmFormInstanceRecordVersion.getVersion());

    document.addKeyword("formInstanceId", ddmFormInstance.getFormInstanceId());

    DDMStructure ddmStructure = ddmFormInstance.getStructure();

    DDMFormValues ddmFormValues = storageEngine.getDDMFormValues(ddmFormInstanceRecordVersion.getStorageId());

    addContent(ddmFormInstanceRecordVersion, ddmFormValues, document);

    ddmIndexer.addAttributes(document, ddmStructure, ddmFormValues);

    return document;
}

From source file:com.liferay.journal.search.JournalArticleIndexer.java

License:Open Source License

public JournalArticleIndexer() {
    setDefaultSelectedFieldNames(Field.ASSET_TAG_NAMES, Field.ARTICLE_ID, Field.COMPANY_ID,
            Field.DEFAULT_LANGUAGE_ID, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID,
            Field.MODIFIED_DATE, Field.SCOPE_GROUP_ID, Field.VERSION, Field.UID);
    setDefaultSelectedLocalizedFieldNames(Field.CONTENT, Field.DESCRIPTION, Field.TITLE);
    setFilterSearch(true);//from w  w w.j a  v a 2s . c  o  m
    setPermissionAware(true);
    setSelectAllLocales(true);
}

From source file:com.liferay.journal.search.JournalArticleIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(JournalArticle journalArticle) throws Exception {

    Document document = getBaseModelDocument(CLASS_NAME, journalArticle);

    long classPK = journalArticle.getId();

    if (!isIndexAllArticleVersions()) {
        classPK = journalArticle.getResourcePrimKey();
    }//from  w  w  w  . j  a  va2 s. co  m

    document.addUID(CLASS_NAME, classPK);

    String articleDefaultLanguageId = LocalizationUtil.getDefaultLanguageId(journalArticle.getDocument());

    String[] languageIds = LocalizationUtil.getAvailableLanguageIds(journalArticle.getDocument());

    for (String languageId : languageIds) {
        String content = extractDDMContent(journalArticle, languageId);

        String description = journalArticle.getDescription(languageId);

        String title = journalArticle.getTitle(languageId);

        if (languageId.equals(articleDefaultLanguageId)) {
            document.addText(Field.CONTENT, content);
            document.addText(Field.DESCRIPTION, description);
            document.addText("defaultLanguageId", languageId);
        }

        document.addText(LocalizationUtil.getLocalizedName(Field.CONTENT, languageId), content);
        document.addText(LocalizationUtil.getLocalizedName(Field.DESCRIPTION, languageId), description);
        document.addText(LocalizationUtil.getLocalizedName(Field.TITLE, languageId), title);
    }

    document.addKeyword(Field.FOLDER_ID, journalArticle.getFolderId());

    String articleId = journalArticle.getArticleId();

    if (journalArticle.isInTrash()) {
        articleId = TrashUtil.getOriginalTitle(articleId);
    }

    document.addKeywordSortable(Field.ARTICLE_ID, articleId);

    document.addKeyword(Field.LAYOUT_UUID, journalArticle.getLayoutUuid());
    document.addKeyword(Field.TREE_PATH, StringUtil.split(journalArticle.getTreePath(), CharPool.SLASH));
    document.addKeyword(Field.VERSION, journalArticle.getVersion());

    document.addKeyword("ddmStructureKey", journalArticle.getDDMStructureKey());
    document.addKeyword("ddmTemplateKey", journalArticle.getDDMTemplateKey());
    document.addDate("displayDate", journalArticle.getDisplayDate());
    document.addKeyword("head", JournalUtil.isHead(journalArticle));

    boolean headListable = JournalUtil.isHeadListable(journalArticle);

    document.addKeyword("headListable", headListable);

    // Scheduled listable articles should be visible in asset browser

    if (journalArticle.isScheduled() && headListable) {
        boolean visible = GetterUtil.getBoolean(document.get("visible"));

        if (!visible) {
            document.addKeyword("visible", true);
        }
    }

    addDDMStructureAttributes(document, journalArticle);

    return document;
}

From source file:com.liferay.journal.search.JournalArticleIndexer.java

License:Open Source License

protected String getDDMContentSummary(Document document, Locale snippetLocale, PortletRequest portletRequest,
        PortletResponse portletResponse) {

    String content = StringPool.BLANK;

    if ((portletRequest == null) || (portletResponse == null)) {
        return content;
    }/*from  ww  w.  ja  v  a 2s  .c  o  m*/

    try {
        String articleId = document.get(Field.ARTICLE_ID);
        long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
        double version = GetterUtil.getDouble(document.get(Field.VERSION));
        PortletRequestModel portletRequestModel = new PortletRequestModel(portletRequest, portletResponse);
        ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

        JournalArticleDisplay articleDisplay = _journalContent.getDisplay(groupId, articleId, version, null,
                Constants.VIEW, LocaleUtil.toLanguageId(snippetLocale), 1, portletRequestModel, themeDisplay);

        content = 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.journal.search.SearchResultUtilJournalArticleTest.java

License:Open Source License

protected Document createDocument() {
    Document document = SearchTestUtil.createDocument(_JOURNAL_ARTICLE_CLASS_NAME);

    document.add(new Field(Field.VERSION, _DOCUMENT_VERSION));

    return document;
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

public SearchContainer getSearchContainer(boolean showVersions) throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    SearchContainer articleSearchContainer = new SearchContainer(_liferayPortletRequest, getPortletURL(), null,
            null);//w  ww.j a  v  a2 s . c om

    if (!isSearch()) {
        articleSearchContainer
                .setEmptyResultsMessageCssClass("taglib-empty-result-message-header-has-plus-btn");
    } else {
        articleSearchContainer.setSearch(true);
    }

    OrderByComparator<JournalArticle> orderByComparator = JournalPortletUtil
            .getArticleOrderByComparator(getOrderByCol(), getOrderByType());

    articleSearchContainer.setOrderByCol(getOrderByCol());
    articleSearchContainer.setOrderByComparator(orderByComparator);
    articleSearchContainer.setOrderByType(getOrderByType());

    EntriesChecker entriesChecker = new EntriesChecker(_liferayPortletRequest, _liferayPortletResponse);

    entriesChecker.setCssClass("entry-selector");
    entriesChecker.setRememberCheckBoxStateURLRegex(
            "^(?!.*" + _liferayPortletResponse.getNamespace() + "redirect).*(folderId=" + getFolderId() + ")");

    articleSearchContainer.setRowChecker(entriesChecker);

    EntriesMover entriesMover = new EntriesMover(themeDisplay.getScopeGroupId());

    articleSearchContainer.setRowMover(entriesMover);

    if (isNavigationMine() || isNavigationRecent()) {
        boolean includeOwner = true;

        if (isNavigationMine()) {
            includeOwner = false;
        }

        if (isNavigationRecent()) {
            articleSearchContainer.setOrderByCol("create-date");
            articleSearchContainer.setOrderByType(getOrderByType());
        }

        int total = JournalArticleServiceUtil.getGroupArticlesCount(themeDisplay.getScopeGroupId(),
                themeDisplay.getUserId(), getFolderId(), getStatus(), includeOwner);

        articleSearchContainer.setTotal(total);

        List results = JournalArticleServiceUtil.getGroupArticles(themeDisplay.getScopeGroupId(),
                themeDisplay.getUserId(), getFolderId(), getStatus(), includeOwner,
                articleSearchContainer.getStart(), articleSearchContainer.getEnd(),
                articleSearchContainer.getOrderByComparator());

        articleSearchContainer.setResults(results);
    } else if (Validator.isNotNull(getDDMStructureKey())) {
        int total = JournalArticleServiceUtil.getArticlesCountByStructureId(themeDisplay.getScopeGroupId(),
                getDDMStructureKey(), getStatus());

        articleSearchContainer.setTotal(total);

        List results = JournalArticleServiceUtil.getArticlesByStructureId(themeDisplay.getScopeGroupId(),
                getDDMStructureKey(), getStatus(), articleSearchContainer.getStart(),
                articleSearchContainer.getEnd(), articleSearchContainer.getOrderByComparator());

        articleSearchContainer.setResults(results);
    } else if (Validator.isNotNull(getDDMTemplateKey())) {
        List<Long> folderIds = new ArrayList<>(1);

        if (getFolderId() != JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

            folderIds.add(getFolderId());
        }

        int total = JournalArticleServiceUtil.searchCount(themeDisplay.getCompanyId(),
                themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT,
                getKeywords(), -1.0, getDDMStructureKey(), getDDMTemplateKey(), null, null, getStatus(), null);

        articleSearchContainer.setTotal(total);

        List results = JournalArticleServiceUtil.search(themeDisplay.getCompanyId(),
                themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT,
                getKeywords(), -1.0, getDDMStructureKey(), getDDMTemplateKey(), null, null, getStatus(), null,
                articleSearchContainer.getStart(), articleSearchContainer.getEnd(),
                articleSearchContainer.getOrderByComparator());

        articleSearchContainer.setResults(results);
    } else if (isSearch()) {
        List<Long> folderIds = new ArrayList<>(1);

        if (getFolderId() != JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

            folderIds.add(getFolderId());
        }

        JournalWebConfiguration journalWebConfiguration = (JournalWebConfiguration) _request
                .getAttribute(JournalWebConfiguration.class.getName());

        if (journalWebConfiguration.journalArticlesSearchWithIndex()) {
            boolean orderByAsc = false;

            if (Objects.equals(getOrderByType(), "asc")) {
                orderByAsc = true;
            }

            Sort sort = null;

            if (Objects.equals(getOrderByCol(), "display-date")) {
                sort = new Sort("displayDate", Sort.LONG_TYPE, orderByAsc);
            } else if (Objects.equals(getOrderByCol(), "id")) {
                sort = new Sort(DocumentImpl.getSortableFieldName(Field.ARTICLE_ID), Sort.STRING_TYPE,
                        !orderByAsc);
            } else if (Objects.equals(getOrderByCol(), "modified-date")) {
                sort = new Sort(Field.MODIFIED_DATE, Sort.LONG_TYPE, orderByAsc);
            } else if (Objects.equals(getOrderByCol(), "title")) {
                sort = new Sort("title", Sort.STRING_TYPE, !orderByAsc);
            }

            LinkedHashMap<String, Object> params = new LinkedHashMap<>();

            params.put("expandoAttributes", getKeywords());

            Indexer indexer = JournalSearcher.getInstance();

            SearchContext searchContext = buildSearchContext(themeDisplay.getCompanyId(),
                    themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT,
                    getDDMStructureKey(), getDDMTemplateKey(), getKeywords(), params,
                    articleSearchContainer.getStart(), articleSearchContainer.getEnd(), sort, showVersions);

            Hits hits = indexer.search(searchContext);

            int total = hits.getLength();

            articleSearchContainer.setTotal(total);

            List results = new ArrayList<>();

            Document[] documents = hits.getDocs();

            for (int i = 0; i < documents.length; i++) {
                Document document = documents[i];

                JournalArticle article = null;
                JournalFolder folder = null;

                String className = document.get(Field.ENTRY_CLASS_NAME);
                long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

                if (className.equals(JournalArticle.class.getName())) {
                    if (!showVersions) {
                        article = JournalArticleLocalServiceUtil.fetchLatestArticle(classPK,
                                WorkflowConstants.STATUS_ANY, false);
                    } else {
                        String articleId = document.get(Field.ARTICLE_ID);
                        long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
                        double version = GetterUtil.getDouble(document.get(Field.VERSION));

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

                    results.add(article);
                } else if (className.equals(JournalFolder.class.getName())) {
                    folder = JournalFolderLocalServiceUtil.getFolder(classPK);

                    results.add(folder);
                }
            }

            articleSearchContainer.setResults(results);
        } else {
            int total = JournalArticleServiceUtil.searchCount(themeDisplay.getCompanyId(),
                    themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT,
                    getKeywords(), -1.0, getDDMStructureKey(), getDDMTemplateKey(), null, null, getStatus(),
                    null);

            articleSearchContainer.setTotal(total);

            List results = JournalArticleServiceUtil.search(themeDisplay.getCompanyId(),
                    themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT,
                    getKeywords(), -1.0, getDDMStructureKey(), getDDMTemplateKey(), null, null, getStatus(),
                    null, articleSearchContainer.getStart(), articleSearchContainer.getEnd(),
                    articleSearchContainer.getOrderByComparator());

            articleSearchContainer.setResults(results);
        }
    } else {
        int total = JournalFolderServiceUtil.getFoldersAndArticlesCount(themeDisplay.getScopeGroupId(), 0,
                getFolderId(), getStatus());

        articleSearchContainer.setTotal(total);

        OrderByComparator<Object> folderOrderByComparator = null;

        boolean orderByAsc = false;

        if (Objects.equals(getOrderByType(), "asc")) {
            orderByAsc = true;
        }

        if (Objects.equals(getOrderByCol(), "display-date")) {
            folderOrderByComparator = new FolderArticleDisplayDateComparator(orderByAsc);
        } else if (Objects.equals(getOrderByCol(), "id")) {
            folderOrderByComparator = new FolderArticleArticleIdComparator(orderByAsc);
        } else if (Objects.equals(getOrderByCol(), "modified-date")) {
            folderOrderByComparator = new FolderArticleModifiedDateComparator(orderByAsc);
        } else if (Objects.equals(getOrderByCol(), "title")) {
            folderOrderByComparator = new FolderArticleTitleComparator(orderByAsc);
        }

        List results = JournalFolderServiceUtil.getFoldersAndArticles(themeDisplay.getScopeGroupId(), 0,
                getFolderId(), getStatus(), themeDisplay.getLocale(), articleSearchContainer.getStart(),
                articleSearchContainer.getEnd(), folderOrderByComparator);

        articleSearchContainer.setResults(results);
    }

    return articleSearchContainer;
}

From source file:com.liferay.journal.web.internal.search.JournalSearcher.java

License:Open Source License

public JournalSearcher() {
    setDefaultSelectedFieldNames(Field.ARTICLE_ID, Field.COMPANY_ID, Field.DEFAULT_LANGUAGE_ID,
            Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID, Field.VERSION, Field.UID);
    setDefaultSelectedLocalizedFieldNames(Field.CONTENT, Field.DESCRIPTION, Field.TITLE);
    setFilterSearch(true);/*w w  w.  java2  s  .c o  m*/
    setPermissionAware(true);
    setSelectAllLocales(true);
}

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

License:Open Source License

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

    Document document = getBaseModelDocument(PORTLET_ID, article);

    long classPK = article.getId();

    if (!PropsValues.JOURNAL_ARTICLE_INDEX_ALL_VERSIONS) {
        classPK = article.getResourcePrimKey();
    }/*from  w w w .  j a  v a 2  s. c  om*/

    document.addUID(PORTLET_ID, classPK);

    String articleDefaultLanguageId = LocalizationUtil.getDefaultLanguageId(article.getContent());

    Locale defaultLocale = LocaleUtil.getSiteDefault();

    String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

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

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

        String description = article.getDescription(languageId);

        String title = article.getTitle(languageId);

        if (languageId.equals(articleDefaultLanguageId)) {
            document.addText(Field.CONTENT, content);
            document.addText(Field.DESCRIPTION, description);
            document.addText(Field.TITLE, title);
            document.addText("defaultLanguageId", languageId);
        }

        document.addText(Field.CONTENT.concat(StringPool.UNDERLINE).concat(languageId), content);
        document.addText(Field.DESCRIPTION.concat(StringPool.UNDERLINE).concat(languageId), description);
        document.addText(Field.TITLE.concat(StringPool.UNDERLINE).concat(languageId), title);
    }

    document.addKeyword(Field.FOLDER_ID, article.getFolderId());
    document.addKeyword(Field.LAYOUT_UUID, article.getLayoutUuid());
    document.addKeyword(Field.TREE_PATH, StringUtil.split(article.getTreePath(), CharPool.SLASH));
    document.addKeyword(Field.TYPE, article.getType());
    document.addKeyword(Field.VERSION, article.getVersion());

    String articleId = article.getArticleId();

    if (article.isInTrash()) {
        articleId = TrashUtil.getOriginalTitle(articleId);
    }

    document.addKeyword("articleId", articleId);
    document.addKeyword("ddmStructureKey", article.getStructureId());
    document.addKeyword("ddmTemplateKey", article.getTemplateId());
    document.addDate("displayDate", article.getDisplayDate());

    addDDMStructureAttributes(document, article);

    addStatusHeads(document, article);

    return document;
}

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

License:Open Source License

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

    Locale snippetLocale = getSnippetLocale(document, locale);

    String localizedTitleName = DocumentImpl.getLocalizedName(locale, Field.TITLE);

    if ((snippetLocale == null) || (document.getField(localizedTitleName) == null)) {

        snippetLocale = LocaleUtil.fromLanguageId(document.get("defaultLanguageId"));
    }/*from  w w w. ja  va  2s.  c  om*/

    String title = document.get(snippetLocale, Field.SNIPPET + StringPool.UNDERLINE + Field.TITLE, Field.TITLE);

    String content = StringPool.BLANK;

    String ddmStructureKey = document.get("ddmStructureKey");

    if (Validator.isNotNull(ddmStructureKey)) {
        content = getDDMContentSummary(document, snippetLocale);
    } else {
        content = getBasicContentSummary(document, snippetLocale);
    }

    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(snippetLocale, title, content, portletURL);
}