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

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

Introduction

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

Prototype

String PROPERTIES

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

Click Source Link

Usage

From source file:com.liferay.portlet.documentlibrary.util.DLFileEntryIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {
    DLFileEntry dlFileEntry = (DLFileEntry) obj;

    _log.info("COGNIZANT@@@@doGetDocument::::: TILE::::" + dlFileEntry.getTitle() + "FileEntryID::::"
            + dlFileEntry.getFileEntryId());

    if (_log.isDebugEnabled()) {
        _log.debug("Indexing document " + dlFileEntry);
    }/*from  w w  w  .  ja v  a2s.  c o  m*/

    boolean indexContent = true;

    InputStream is = null;

    try {
        if (PropsValues.DL_FILE_INDEXING_MAX_SIZE == 0) {
            indexContent = false;
        } else if (PropsValues.DL_FILE_INDEXING_MAX_SIZE != -1) {
            if (dlFileEntry.getSize() > PropsValues.DL_FILE_INDEXING_MAX_SIZE) {

                indexContent = false;
            }
        }

        if (indexContent) {
            String[] ignoreExtensions = PrefsPropsUtil
                    .getStringArray(PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA);

            if (ArrayUtil.contains(ignoreExtensions, StringPool.PERIOD + dlFileEntry.getExtension())) {

                indexContent = false;
            }
        }

        if (indexContent) {
            is = dlFileEntry.getFileVersion().getContentStream(false);
        }
    } catch (Exception e) {
        _log.error("COGNIZANT@@@@doGetDocument@@CATCH1:::::" + dlFileEntry.getFileEntryId() + "@@@@@"
                + dlFileEntry.getTitle() + "@@@@", e);
        fileLog.error("FileEntry ID" + dlFileEntry.getFileEntryId());
        try {
            fileWriter = generateCsvFile(dlFileEntry.getFileEntryId(), fileCsvpath);
        } catch (IOException e1) {
            _log.error("Error Generating CSV", e1);
        }
    }

    DLFileVersion dlFileVersion = dlFileEntry.getFileVersion();

    try {
        Document document = getBaseModelDocument(PORTLET_ID, dlFileEntry, dlFileVersion);

        if (indexContent) {
            if (is != null) {
                try {
                    document.addFile(Field.CONTENT, is, dlFileEntry.getTitle());
                } catch (IOException ioe) {
                    throw new SearchException("Cannot extract text from file" + dlFileEntry);
                }
            } else if (_log.isDebugEnabled()) {
                _log.debug("Document " + dlFileEntry + " does not have any content");
            }
        }

        document.addKeyword(Field.CLASS_TYPE_ID, dlFileEntry.getFileEntryTypeId());
        document.addText(Field.DESCRIPTION, dlFileEntry.getDescription());
        document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId());
        document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder());
        document.addText(Field.PROPERTIES, dlFileEntry.getLuceneProperties());
        document.addText(Field.TITLE, dlFileEntry.getTitle());
        document.addKeyword(Field.TREE_PATH, StringUtil.split(dlFileEntry.getTreePath(), CharPool.SLASH));

        document.addKeyword("dataRepositoryId", dlFileEntry.getDataRepositoryId());
        document.addText("ddmContent", extractContent(dlFileVersion, LocaleUtil.getSiteDefault()));
        document.addKeyword("extension", dlFileEntry.getExtension());
        document.addKeyword("fileEntryTypeId", dlFileEntry.getFileEntryTypeId());
        document.addKeyword("mimeType",
                StringUtil.replace(dlFileEntry.getMimeType(), CharPool.FORWARD_SLASH, CharPool.UNDERLINE));
        document.addKeyword("path", dlFileEntry.getTitle());
        document.addKeyword("readCount", dlFileEntry.getReadCount());
        document.addKeyword("size", dlFileEntry.getSize());

        ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(dlFileEntry.getCompanyId(),
                DLFileEntry.class.getName(), dlFileVersion.getFileVersionId());

        ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge);

        addFileEntryTypeAttributes(document, dlFileVersion);

        if (dlFileEntry.isInHiddenFolder()) {
            try {
                Repository repository = RepositoryLocalServiceUtil.getRepository(dlFileEntry.getRepositoryId());

                String portletId = repository.getPortletId();

                for (Indexer indexer : IndexerRegistryUtil.getIndexers()) {
                    if (portletId.equals(indexer.getPortletId())) {
                        indexer.addRelatedEntryFields(document, obj);
                    }
                }
            } catch (Exception e) {
                _log.error("COGNIZANT@@@@doGetDocument@@CATCH2:::" + dlFileEntry.getFileEntryId() + "@@@@"
                        + dlFileEntry.getTitle() + "@@@@", e);
                fileLog.error("FileEntry ID" + dlFileEntry.getFileEntryId());
                try {
                    fileWriter = generateCsvFile(dlFileEntry.getFileEntryId(), fileCsvpath);
                } catch (IOException e1) {
                    _log.error("Error Generating CSV", e1);
                }
            }
        }

        if (_log.isDebugEnabled()) {
            _log.debug("Document " + dlFileEntry + " indexed successfully");
        }

        return document;
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ioe) {
                _log.error("COGNIZANT@@@@doGetDocument@@CATCH3:::" + dlFileEntry.getFileEntryId() + "@@@@"
                        + dlFileEntry.getTitle() + "@@@@", ioe);
                fileLog.error("FileEntry ID" + dlFileEntry.getFileEntryId());
                try {
                    fileWriter = generateCsvFile(dlFileEntry.getFileEntryId(), fileCsvpath);
                } catch (IOException e1) {
                    _log.error("Error Generating CSV", e1);
                }
            }
        }
    }
}

From source file:com.liferay.portlet.documentlibrary.util.DLIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {
    DLFileEntry dlFileEntry = (DLFileEntry) obj;

    if (_log.isDebugEnabled()) {
        _log.debug("Indexing document " + dlFileEntry);
    }/*from  w w  w  .ja va 2 s. com*/

    boolean indexContent = true;

    InputStream is = null;

    try {
        if (PropsValues.DL_FILE_INDEXING_MAX_SIZE == 0) {
            indexContent = false;
        } else if (PropsValues.DL_FILE_INDEXING_MAX_SIZE != -1) {
            if (dlFileEntry.getSize() > PropsValues.DL_FILE_INDEXING_MAX_SIZE) {

                indexContent = false;
            }
        }

        if (indexContent) {
            String[] ignoreExtensions = PrefsPropsUtil
                    .getStringArray(PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA);

            if (ArrayUtil.contains(ignoreExtensions, StringPool.PERIOD + dlFileEntry.getExtension())) {

                indexContent = false;
            }
        }

        if (indexContent) {
            is = dlFileEntry.getFileVersion().getContentStream(false);
        }
    } catch (Exception e) {
    }

    if (indexContent && (is == null)) {
        if (_log.isDebugEnabled()) {
            _log.debug("Document " + dlFileEntry + " does not have any content");
        }

        return null;
    }

    try {
        Document document = new DocumentImpl();

        long fileEntryId = dlFileEntry.getFileEntryId();

        document.addUID(PORTLET_ID, fileEntryId);

        List<AssetCategory> assetCategories = AssetCategoryLocalServiceUtil
                .getCategories(DLFileEntry.class.getName(), fileEntryId);

        long[] assetCategoryIds = StringUtil
                .split(ListUtil.toString(assetCategories, AssetCategory.CATEGORY_ID_ACCESSOR), 0L);

        document.addKeyword(Field.ASSET_CATEGORY_IDS, assetCategoryIds);

        String[] assetCategoryNames = StringUtil
                .split(ListUtil.toString(assetCategories, AssetCategory.NAME_ACCESSOR));

        document.addKeyword(Field.ASSET_CATEGORY_NAMES, assetCategoryNames);

        String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(DLFileEntry.class.getName(), fileEntryId);

        document.addKeyword(Field.ASSET_TAG_NAMES, assetTagNames);

        document.addKeyword(Field.COMPANY_ID, dlFileEntry.getCompanyId());

        if (indexContent) {
            try {
                document.addFile(Field.CONTENT, is, dlFileEntry.getTitle());
            } catch (IOException ioe) {
                throw new SearchException("Cannot extract text from file" + dlFileEntry);
            }
        }

        document.addText(Field.DESCRIPTION, dlFileEntry.getDescription());
        document.addKeyword(Field.ENTRY_CLASS_NAME, DLFileEntry.class.getName());
        document.addKeyword(Field.ENTRY_CLASS_PK, fileEntryId);
        document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId());
        document.addKeyword(Field.GROUP_ID, getParentGroupId(dlFileEntry.getGroupId()));
        document.addDate(Field.MODIFIED_DATE, dlFileEntry.getModifiedDate());
        document.addKeyword(Field.PORTLET_ID, PORTLET_ID);
        document.addText(Field.PROPERTIES, dlFileEntry.getLuceneProperties());
        document.addKeyword(Field.SCOPE_GROUP_ID, dlFileEntry.getGroupId());

        DLFileVersion dlFileVersion = dlFileEntry.getFileVersion();

        document.addKeyword(Field.STATUS, dlFileVersion.getStatus());
        document.addText(Field.TITLE, dlFileEntry.getTitle());

        long userId = dlFileEntry.getUserId();

        document.addKeyword(Field.USER_ID, userId);
        document.addKeyword(Field.USER_NAME, PortalUtil.getUserName(userId, dlFileEntry.getUserName()), true);

        document.addKeyword("dataRepositoryId", dlFileEntry.getDataRepositoryId());
        document.addKeyword("extension", dlFileEntry.getExtension());
        document.addKeyword("fileEntryTypeId", dlFileEntry.getFileEntryTypeId());
        document.addKeyword("path", dlFileEntry.getTitle());

        ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(dlFileEntry.getCompanyId(),
                DLFileEntry.class.getName(), dlFileVersion.getFileVersionId());

        ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge);

        addFileEntryTypeAttributes(document, dlFileVersion);

        if (_log.isDebugEnabled()) {
            _log.debug("Document " + dlFileEntry + " indexed successfully");
        }

        return document;
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ioe) {
            }
        }
    }
}

From source file:com.liferay.portlet.tags.service.impl.TagsAssetLocalServiceImpl.java

License:Open Source License

public Hits search(long companyId, String portletId, String keywords, int start, int end)
        throws SystemException {

    try {//  w  w  w .  j  a va 2  s.  c o m
        BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();

        if (Validator.isNotNull(portletId)) {
            contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId);
        } else {
            BooleanQuery portletIdsQuery = BooleanQueryFactoryUtil.create();

            for (String assetTypePortletId : TagsUtil.ASSET_TYPE_PORTLET_IDS) {

                TermQuery termQuery = TermQueryFactoryUtil.create(Field.PORTLET_ID, assetTypePortletId);

                portletIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD);
            }

            contextQuery.add(portletIdsQuery, BooleanClauseOccur.MUST);
        }

        BooleanQuery searchQuery = BooleanQueryFactoryUtil.create();

        if (Validator.isNotNull(keywords)) {
            searchQuery.addTerm(Field.TITLE, keywords);
            searchQuery.addTerm(Field.CONTENT, keywords);
            searchQuery.addTerm(Field.DESCRIPTION, keywords);
            searchQuery.addTerm(Field.PROPERTIES, keywords);
            searchQuery.addTerm(Field.TAGS_ENTRIES, keywords);
        }

        BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();

        fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

        if (searchQuery.clauses().size() > 0) {
            fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
        }

        return SearchEngineUtil.search(companyId, fullQuery, start, end);
    } catch (Exception e) {
        throw new SystemException(e);
    }
}