Example usage for com.liferay.portal.kernel.search SearchContext setGroupIds

List of usage examples for com.liferay.portal.kernel.search SearchContext setGroupIds

Introduction

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

Prototype

public void setGroupIds(long[] groupIds) 

Source Link

Usage

From source file:com.liferay.bookmarks.service.impl.BookmarksEntryLocalServiceImpl.java

License:Open Source License

@Override
public Hits search(long groupId, long userId, long creatorUserId, int status, int start, int end)
        throws PortalException {

    Indexer<BookmarksEntry> indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class.getName());

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, status);

    if (creatorUserId > 0) {
        searchContext.setAttribute(Field.USER_ID, String.valueOf(creatorUserId));
    }//from w ww. jav a  2 s  .com

    searchContext.setAttribute("paginationType", "none");

    Group group = groupLocalService.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    searchContext.setEnd(end);
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setSorts(new Sort(Field.MODIFIED_DATE, true));
    searchContext.setStart(start);
    searchContext.setUserId(userId);

    QueryConfig queryConfig = searchContext.getQueryConfig();

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

    return indexer.search(searchContext);
}

From source file:com.liferay.bookmarks.util.test.BookmarksTestUtil.java

License:Open Source License

public static SearchContext getSearchContext(long companyId, long groupId, long folderId, String keywords,
        boolean highlight, boolean score) {

    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(highlight);
    queryConfig.setScoreEnabled(score);/*from ww  w .  j av  a  2 s .  co m*/

    searchContext.setQueryConfig(queryConfig);

    return searchContext;
}

From source file:com.liferay.calendar.search.test.CalendarSearchFixture.java

License:Open Source License

public SearchContext getSearchContext(String keywords, Locale locale) {
    SearchContext searchContext = new SearchContext();

    try {// w w  w .java 2s  . c o  m
        searchContext.setCompanyId(TestPropsValues.getCompanyId());
        searchContext.setUserId(getUserId());
    } catch (PortalException pe) {
        throw new RuntimeException(pe);
    }

    searchContext.setGroupIds(new long[] { _group.getGroupId() });
    searchContext.setKeywords(keywords);
    searchContext.setLocale(Objects.requireNonNull(locale));

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setSelectedFieldNames(StringPool.STAR);

    return searchContext;
}

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

protected Hits search(ThemeDisplay themeDisplay, String keywords) throws Exception {

    SearchContext searchContext = new SearchContext();

    keywords = StringUtil.toLowerCase(keywords);

    searchContext.setAttribute(Field.NAME, keywords);
    searchContext.setAttribute("resourceName", keywords);

    searchContext.setCompanyId(themeDisplay.getCompanyId());
    searchContext.setEnd(SearchContainer.DEFAULT_DELTA);
    searchContext.setGroupIds(new long[0]);

    Group group = themeDisplay.getScopeGroup();

    searchContext.setIncludeStagingGroups(group.isStagingGroup());

    searchContext.setStart(0);//from   www.  j  ava 2  s  . co  m
    searchContext.setUserId(themeDisplay.getUserId());

    Indexer<?> indexer = CalendarSearcher.getInstance();

    return indexer.search(searchContext);
}

From source file:com.liferay.content.targeting.service.impl.CampaignLocalServiceImpl.java

License:Open Source License

protected SearchContext buildSearchContext(long groupId, String keywords, int start, int end)
        throws PortalException, SystemException {

    SearchContext searchContext = new SearchContext();

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());
    searchContext.setEnd(end);/*  w ww.  j a  va 2  s.c  o  m*/
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setKeywords(keywords);
    searchContext.setStart(start);

    return searchContext;
}

From source file:com.liferay.content.targeting.service.impl.UserSegmentLocalServiceImpl.java

License:Open Source License

protected SearchContext buildSearchContext(long groupId, String keywords, int start, int end)
        throws PortalException, SystemException {

    SearchContext searchContext = new SearchContext();

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    searchContext.setEnd(end);//from   ww  w.  j  a va2 s  .com
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setKeywords(keywords);
    searchContext.setStart(start);

    return searchContext;
}

From source file:com.liferay.content.targeting.service.test.service.ServiceTestUtil.java

License:Open Source License

public static SearchContext getSearchContext(long groupId) throws Exception {

    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(TestPropsValues.getCompanyId());
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setUserId(TestPropsValues.getUserId());

    return searchContext;
}

From source file:com.liferay.document.library.service.test.DLAppServiceTest.java

License:Open Source License

protected static void search(FileEntry fileEntry, String keywords, boolean expected) throws Exception {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute("paginationType", "regular");
    searchContext.setCompanyId(fileEntry.getCompanyId());
    searchContext.setFolderIds(new long[] { fileEntry.getFolderId() });
    searchContext.setGroupIds(new long[] { fileEntry.getRepositoryId() });
    searchContext.setKeywords(keywords);

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setHighlightEnabled(false);
    queryConfig.setScoreEnabled(false);/*  www.ja v a2 s  . co  m*/

    Indexer<DLFileEntry> indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName());

    Hits hits = indexer.search(searchContext);

    boolean found = false;

    for (Document document : hits.getDocs()) {
        long fileEntryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

        if (fileEntryId == fileEntry.getFileEntryId()) {
            found = true;

            break;
        }
    }

    Assert.assertEquals(hits.toString(), expected, found);
}

From source file:com.liferay.dynamic.data.mapping.test.util.search.TestOrderHelper.java

License:Open Source License

protected Hits search(AssetEntryQuery assetEntryQuery) throws Exception {
    SearchContext searchContext = SearchContextTestUtil.getSearchContext();

    searchContext.setGroupIds(assetEntryQuery.getGroupIds());

    Bundle bundle = FrameworkUtil.getBundle(TestOrderHelper.class);

    return OSGiServiceUtil.callService(bundle.getBundleContext(), AssetHelper.class, assetHelper -> assetHelper
            .search(searchContext, assetEntryQuery, QueryUtil.ALL_POS, QueryUtil.ALL_POS));
}

From source file:com.liferay.experts.service.impl.QuestionLocalServiceImpl.java

License:Open Source License

public Hits search(long companyId, long groupId, String keywords, LinkedHashMap<String, Object> params,
        int start, int end, Sort sort) throws SystemException {

    try {//from w ww  . j  a va 2 s .  c om
        SearchContext searchContext = new SearchContext();

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

        if (params != null) {
            if (Validator.isNull(keywords)) {
                keywords = (String) params.get("keywords");
            }

            params.remove("keywords");
        }

        if (Validator.isNotNull(keywords)) {
            searchContext.setKeywords(keywords);
        }

        QueryConfig queryConfig = new QueryConfig();

        queryConfig.setHighlightEnabled(false);

        searchContext.setQueryConfig(queryConfig);

        if (sort != null) {
            searchContext.setSorts(new Sort[] { sort });
        }

        searchContext.setStart(start);

        Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(Question.class);

        return indexer.search(searchContext);
    } catch (Exception e) {
        throw new SystemException(e);
    }
}