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

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

Introduction

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

Prototype

String GROUP_ID

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

Click Source Link

Usage

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

License:Open Source License

public MBMessageIndexer() {
    setDefaultSelectedFieldNames(Field.ASSET_TAG_NAMES, Field.CLASS_NAME_ID, Field.CLASS_PK, Field.COMPANY_ID,
            Field.CONTENT, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID, Field.MODIFIED_DATE,
            Field.SCOPE_GROUP_ID, Field.TITLE, Field.UID);
    setFilterSearch(true);//from www  . j ava  2s.c  om
    setPermissionAware(true);
}

From source file:com.liferay.polls.internal.search.PollsQuestionIndexer.java

License:Open Source License

public PollsQuestionIndexer() {
    setDefaultSelectedFieldNames(Field.ASSET_TAG_NAMES, Field.CREATE_DATE, Field.COMPANY_ID, Field.DESCRIPTION,
            Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID, Field.SCOPE_GROUP_ID, Field.TITLE,
            Field.UID);//from   w w w  . j  av a  2 s .  co  m
    setFilterSearch(true);
}

From source file:com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.java

License:Open Source License

protected AssetEntry getEntry(Document document) throws PortalException, SystemException {
    String portletId = GetterUtil.getString(document.get(Field.PORTLET_ID));

    if (portletId.equals(PortletKeys.BLOGS)) {
        long entryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

        long classNameId = PortalUtil.getClassNameId(BlogsEntry.class.getName());
        long classPK = entryId;

        return assetEntryPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.BOOKMARKS)) {
        long entryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

        long classNameId = PortalUtil.getClassNameId(BookmarksEntry.class.getName());
        long classPK = entryId;

        return assetEntryPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY)) {
        long fileEntryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

        long classNameId = PortalUtil.getClassNameId(DLFileEntry.class.getName());
        long classPK = fileEntryId;

        return assetEntryPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.JOURNAL)) {
        long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
        String articleId = document.get("articleId");
        //double version = GetterUtil.getDouble(document.get("version"));

        long articleResourcePrimKey = journalArticleResourceLocalService.getArticleResourcePrimKey(groupId,
                articleId);/*from w ww  .j a  va  2s. c  om*/

        long classNameId = PortalUtil.getClassNameId(JournalArticle.class.getName());
        long classPK = articleResourcePrimKey;

        return assetEntryPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.MESSAGE_BOARDS)) {
        long messageId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

        long classNameId = PortalUtil.getClassNameId(MBMessage.class.getName());
        long classPK = messageId;

        return assetEntryPersistence.findByC_C(classNameId, classPK);
    } else if (portletId.equals(PortletKeys.WIKI)) {
        long nodeId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));
        String title = document.get(Field.TITLE);

        long pageResourcePrimKey = wikiPageResourceLocalService.getPageResourcePrimKey(nodeId, title);

        long classNameId = PortalUtil.getClassNameId(WikiPage.class.getName());
        long classPK = pageResourcePrimKey;

        return assetEntryPersistence.findByC_C(classNameId, classPK);
    }

    return null;
}

From source file:com.liferay.portlet.bookmarks.service.BookmarksFolderServiceTest.java

License:Open Source License

public void testSearch() throws Exception {
    BookmarksEntry entry = addEntry();//  www  . ja  v a  2s  . co m

    Thread.sleep(1000);

    long companyId = entry.getCompanyId();
    long groupId = entry.getFolder().getGroupId();
    long folderId = entry.getFolderId();
    String keywords = "test";

    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(companyId);
    searchContext.setFolderIds(new long[] { folderId });
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setKeywords(keywords);

    QueryConfig queryConfig = new QueryConfig();

    queryConfig.setHighlightEnabled(false);
    queryConfig.setScoreEnabled(false);

    searchContext.setQueryConfig(queryConfig);

    Indexer indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class);

    Hits hits = indexer.search(searchContext);

    assertEquals(1, hits.getLength());

    List<Document> results = hits.toList();

    for (Document doc : results) {
        assertEquals(companyId, GetterUtil.getLong(doc.get(Field.COMPANY_ID)));

        assertEquals(groupId, GetterUtil.getLong(doc.get(Field.GROUP_ID)));

        assertEqualsIgnoreCase(entry.getName(), doc.get(Field.TITLE));
        assertEquals(entry.getUrl(), doc.get(Field.URL));
        assertEqualsIgnoreCase(entry.getDescription(), doc.get(Field.DESCRIPTION));

        assertEquals(folderId, GetterUtil.getLong(doc.get("folderId")));
        assertEquals(entry.getEntryId(), GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK)));
    }

    BookmarksFolderLocalServiceUtil.deleteFolder(folderId);

    Thread.sleep(1000);

    hits = indexer.search(searchContext);

    Query query = hits.getQuery();

    assertEquals(query.toString(), 0, hits.getLength());

    addEntry();
    addEntry();
    addEntry();
    addEntry();

    Thread.sleep(1000);

    searchContext.setEnd(3);
    searchContext.setFolderIds(null);
    searchContext.setStart(1);

    hits = indexer.search(searchContext);

    assertEquals(4, hits.getLength());
    assertEquals(2, hits.getDocs().length);
}

From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java

License:Open Source License

public Hits search(long companyId, long userId, String portletId, long groupId, long[] repositoryIds,
        String keywords, int start, int end) throws SystemException {

    try {//w w w.j  av  a2  s .com
        SearchContext searchContext = new SearchContext();

        searchContext.setCompanyId(companyId);
        searchContext.setEnd(end);
        searchContext.setEntryClassNames(new String[] { DLFileEntryConstants.getClassName() });
        searchContext.setGroupIds(new long[] { groupId });

        Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName());

        searchContext.setSearchEngineId(indexer.getSearchEngineId());

        searchContext.setStart(start);
        searchContext.setUserId(userId);

        BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext);

        contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId);

        if (groupId > 0) {
            Group group = groupLocalService.getGroup(groupId);

            if (group.isLayout()) {
                contextQuery.addRequiredTerm(Field.SCOPE_GROUP_ID, groupId);

                groupId = group.getParentGroupId();
            }

            contextQuery.addRequiredTerm(Field.GROUP_ID, groupId);
        }

        if ((repositoryIds != null) && (repositoryIds.length > 0)) {
            BooleanQuery repositoryIdsQuery = BooleanQueryFactoryUtil.create(searchContext);

            for (long repositoryId : repositoryIds) {
                try {
                    if (userId > 0) {
                        PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();

                        DLFolderPermission.check(permissionChecker, groupId, repositoryId, ActionKeys.VIEW);
                    }

                    if (repositoryId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

                        repositoryId = groupId;
                    }

                    TermQuery termQuery = TermQueryFactoryUtil.create(searchContext, "repositoryId",
                            repositoryId);

                    repositoryIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD);
                } catch (Exception e) {
                }
            }

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

        BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);

        searchQuery.addTerms(_KEYWORDS_FIELDS, keywords);

        BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);

        fullQuery.add(contextQuery, BooleanClauseOccur.MUST);

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

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

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.  j av 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) {
    }

    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.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"));
    }/* w  ww . ja va  2  s. c o  m*/

    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);
}

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 {//from w ww  . 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 Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) {

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

    String content = snippet;/*  ww w .j  a va 2s .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.journal.util.JournalUtil.java

License:Open Source License

public static Tuple getArticles(Hits hits) throws PortalException, SystemException {

    List<JournalArticle> articles = new ArrayList<JournalArticle>();
    boolean corruptIndex = false;

    List<com.liferay.portal.kernel.search.Document> documents = hits.toList();

    for (com.liferay.portal.kernel.search.Document document : documents) {
        long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
        String articleId = document.get("articleId");

        try {/*ww  w.  j  a v  a 2s.  c o m*/
            JournalArticle article = JournalArticleLocalServiceUtil.getArticle(groupId, articleId);

            articles.add(article);
        } catch (NoSuchArticleException nsae) {
            corruptIndex = true;

            Indexer indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class);

            long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID));

            indexer.delete(companyId, document.getUID());
        }
    }

    return new Tuple(articles, corruptIndex);
}