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.journal.content.search.web.internal.display.context.JournalContentSearchDisplayContext.java

License:Open Source License

public Hits getHits() throws Exception {
    if (_hits != null) {
        return _hits;
    }//from  w  ww  .  ja  v  a2  s  .  c o  m

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

    SearchContext searchContext = SearchContextFactory.getInstance(_request);

    searchContext.setGroupIds(null);
    searchContext.setKeywords(getKeywords());

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.setHighlightEnabled(_journalContentSearchPortletInstanceConfiguration.enableHighlighting());

    _hits = indexer.search(searchContext);

    return _hits;
}

From source file:com.liferay.journal.search.test.JournalArticleIndexableTest.java

License:Open Source License

@Test
public void testJournalArticleIsIndexableByDefault() throws Exception {
    AssetEntryQuery assetEntryQuery = AssetEntryQueryTestUtil.createAssetEntryQuery(_group.getGroupId(),
            JournalArticle.class.getName(), null, null, new long[0], null);

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(_group.getGroupId());

    searchContext.setGroupIds(assetEntryQuery.getGroupIds());

    assertCount(0, assetEntryQuery, searchContext);

    JournalArticle article = JournalTestUtil.addArticle(_group.getGroupId(), RandomTestUtil.randomString(),
            RandomTestUtil.randomString());

    Assert.assertTrue(article.isIndexable());

    assertCount(1, assetEntryQuery, searchContext);
}

From source file:com.liferay.journal.search.test.JournalArticleIndexableTest.java

License:Open Source License

@Test
public void testJournalArticleWithClassNameDDMStructureIsUnindexable() throws Exception {

    AssetEntryQuery assetEntryQuery = AssetEntryQueryTestUtil.createAssetEntryQuery(_group.getGroupId(),
            JournalArticle.class.getName(), null, null, new long[0], null);

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(_group.getGroupId());

    searchContext.setGroupIds(assetEntryQuery.getGroupIds());

    assertCount(0, assetEntryQuery, searchContext);

    JournalTestUtil.addArticle(_group.getGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            PortalUtil.getClassNameId(DDMStructure.class), RandomTestUtil.randomString(),
            RandomTestUtil.randomString(), RandomTestUtil.randomString(), LocaleUtil.getSiteDefault(), false,
            true, ServiceContextTestUtil.getServiceContext(_group.getGroupId()));

    assertCount(0, assetEntryQuery, searchContext);
}

From source file:com.liferay.journal.search.test.JournalIndexerTest.java

License:Open Source License

protected Hits search(long groupId, boolean head, int status, SearchContext searchContext) throws Exception {

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

    searchContext.setAttribute("head", head);
    searchContext.setAttribute("status", status);
    searchContext.setGroupIds(new long[] { groupId });

    return indexer.search(searchContext);
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected SearchContext buildSearchContext(long companyId, long groupId, List<Long> folderIds, long classNameId,
        String articleId, String title, String description, String content, int status, String ddmStructureKey,
        String ddmTemplateKey, LinkedHashMap<String, Object> params, boolean andSearch, int start, int end,
        Sort sort) {/*from w  w  w .  j a  v  a 2 s.  c o m*/

    SearchContext searchContext = new SearchContext();

    searchContext.setAndSearch(andSearch);

    Map<String, Serializable> attributes = new HashMap<>();

    attributes.put(Field.ARTICLE_ID, articleId);
    attributes.put(Field.CLASS_NAME_ID, classNameId);
    attributes.put(Field.CONTENT, content);
    attributes.put(Field.DESCRIPTION, description);
    attributes.put(Field.STATUS, status);
    attributes.put(Field.TITLE, title);
    attributes.put("ddmStructureKey", ddmStructureKey);
    attributes.put("ddmTemplateKey", ddmTemplateKey);
    attributes.put("params", params);

    searchContext.setAttributes(attributes);

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

    if (params != null) {
        searchContext.setIncludeDiscussions(GetterUtil.getBoolean(params.get("includeDiscussions")));

        String keywords = (String) params.remove("keywords");

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

    QueryConfig queryConfig = new QueryConfig();

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

    searchContext.setQueryConfig(queryConfig);

    if (sort != null) {
        searchContext.setSorts(sort);
    }

    searchContext.setStart(start);

    return searchContext;
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected SearchContext buildSearchContext(long groupId, long userId, long creatorUserId, int status, int start,
        int end) throws PortalException {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, status);

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

    if (creatorUserId > 0) {
        searchContext.setAttribute(Field.USER_ID, String.valueOf(creatorUserId));
    }//  w ww .j a  va2  s.c  o  m

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

    return searchContext;
}

From source file:com.liferay.journal.service.test.JournalArticleIndexVersionsTest.java

License:Open Source License

protected void assertSearchArticle(long expectedCount, JournalArticle article) throws Exception {

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

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(_group.getGroupId());

    searchContext.setGroupIds(new long[] { _group.getGroupId() });

    Hits results = indexer.search(searchContext);

    List<JournalArticle> articles = JournalUtil.getArticles(results);

    Assert.assertEquals(articles.toString(), expectedCount, articles.size());

    JournalArticle searchArticle = articles.get(0);

    Assert.assertEquals(searchArticle.toString(), article.getId(), searchArticle.getId());
}

From source file:com.liferay.journal.service.test.JournalArticleIndexVersionsTest.java

License:Open Source License

protected void assertSearchCount(long expectedCount, boolean head) throws Exception {

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

    SearchContext searchContext = SearchContextTestUtil.getSearchContext(_group.getGroupId());

    if (!head) {/* ww  w.  j ava  2  s  . c  o  m*/
        searchContext.setAttribute(Field.STATUS, WorkflowConstants.STATUS_ANY);
        searchContext.setAttribute("head", Boolean.FALSE);
    }

    searchContext.setGroupIds(new long[] { _group.getGroupId() });

    Hits results = indexer.search(searchContext);

    Assert.assertEquals(results.toString(), expectedCount, results.getLength());
}

From source file:com.liferay.journal.test.util.JournalTestUtil.java

License:Open Source License

public static Hits getSearchArticles(long companyId, long groupId) throws Exception {

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

    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(companyId);
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setKeywords(StringPool.BLANK);

    QueryConfig queryConfig = new QueryConfig();

    searchContext.setQueryConfig(queryConfig);

    return indexer.search(searchContext);
}

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

License:Open Source License

protected SearchContext buildSearchContext(long companyId, long groupId, List<java.lang.Long> folderIds,
        long classNameId, String ddmStructureKey, String ddmTemplateKey, String keywords,
        LinkedHashMap<String, Object> params, int start, int end, Sort sort, boolean showVersions) {

    String articleId = null;/*  ww  w .  j av  a2 s.c  o  m*/
    String title = null;
    String description = null;
    String content = null;
    boolean andOperator = false;

    if (Validator.isNotNull(keywords)) {
        articleId = keywords;
        title = keywords;
        description = keywords;
        content = keywords;
    } else {
        andOperator = true;
    }

    if (params != null) {
        params.put("keywords", keywords);
    }

    SearchContext searchContext = new SearchContext();

    searchContext.setAndSearch(andOperator);

    Map<String, Serializable> attributes = new HashMap<>();

    attributes.put(Field.ARTICLE_ID, articleId);
    attributes.put(Field.CLASS_NAME_ID, classNameId);
    attributes.put(Field.CONTENT, content);
    attributes.put(Field.DESCRIPTION, description);
    attributes.put(Field.STATUS, getStatus());
    attributes.put(Field.TITLE, title);
    attributes.put("ddmStructureKey", ddmStructureKey);
    attributes.put("ddmTemplateKey", ddmTemplateKey);
    attributes.put("params", params);

    searchContext.setAttributes(attributes);

    searchContext.setCompanyId(companyId);
    searchContext.setEnd(end);
    searchContext.setFolderIds(folderIds);
    searchContext.setGroupIds(new long[] { groupId });
    searchContext.setIncludeDiscussions(GetterUtil.getBoolean(params.get("includeDiscussions"), true));

    if (params != null) {
        keywords = (String) params.remove("keywords");

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

    searchContext.setAttribute("head", !showVersions);
    searchContext.setAttribute("params", params);
    searchContext.setEnd(end);
    searchContext.setFolderIds(folderIds);
    searchContext.setStart(start);

    QueryConfig queryConfig = new QueryConfig();

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

    searchContext.setQueryConfig(queryConfig);

    if (sort != null) {
        searchContext.setSorts(sort);
    }

    searchContext.setStart(start);

    return searchContext;
}