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:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java

License:Open Source License

protected SearchContext buildSearchContext(long userId, long groupId, long ownerUserId, String company,
        String fullName, int status, LinkedHashMap<String, Object> params, boolean andSearch, int start,
        int end, Sort sort) throws PortalException {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, status);

    if (Validator.isNotNull(company)) {
        searchContext.setAttribute("company", company);
    }//from   ww w.j ava2 s  .c o m

    if (Validator.isNotNull(fullName)) {
        searchContext.setAttribute("fullName", fullName);
    }

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

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    if (ownerUserId > 0) {
        searchContext.setOwnerUserId(ownerUserId);
    }

    searchContext.setEnd(end);
    if (groupId > 0) {
        searchContext.setGroupIds(new long[] { groupId });
    }
    searchContext.setSorts(sort);
    searchContext.setStart(start);
    searchContext.setUserId(userId);

    searchContext.setAndSearch(andSearch);

    if (params != null) {

        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:ch.inofix.referencemanager.service.impl.BibliographyServiceImpl.java

License:Open Source License

/**
 * @param userId/*from  w  ww  .j  a  v  a2s  .  c o m*/
 *            the userId of the current user
 * @param groupId
 *            the scopeGroupId of the bibliography. 0 means: any scope.
 * @param ownerUserId
 *            the userId of the bibliography owner. -1 means: ignore
 *            ownerUserId parameter.
 * @param keywords
 * @param start
 * @param end
 * @param sort
 * @return the hits for the given parameters
 * @since 1.0.0
 * @throws PortalException
 */
public Hits search(long userId, long groupId, long ownerUserId, String keywords, int start, int end, Sort sort)
        throws PortalException {

    if (sort == null) {
        sort = new Sort(Field.MODIFIED_DATE, true);
    }

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

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, WorkflowConstants.STATUS_ANY);

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

    User user = UserLocalServiceUtil.getUser(userId);

    searchContext.setCompanyId(user.getCompanyId());

    searchContext.setEnd(end);

    if (groupId > 0) {
        searchContext.setGroupIds(new long[] { groupId });
    }
    searchContext.setSorts(sort);
    searchContext.setStart(start);
    searchContext.setUserId(userId);
    searchContext.setOwnerUserId(ownerUserId);

    return indexer.search(searchContext);

}

From source file:ch.inofix.referencemanager.service.impl.ReferenceLocalServiceImpl.java

License:Open Source License

protected SearchContext buildSearchContext(long userId, long groupId, long bibliographyId, String author,
        String title, String year, int status, LinkedHashMap<String, Object> params, boolean andSearch,
        int start, int end, Sort sort) throws PortalException {

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, status);

    if (Validator.isNotNull(author)) {
        searchContext.setAttribute("author", author);
    }//from www .  j a v  a2 s . com

    if (bibliographyId > 0) {
        searchContext.setAttribute("bibliographyId", bibliographyId);
    }

    if (Validator.isNotNull(title)) {
        searchContext.setAttribute("title", title);
    }

    if (Validator.isNotNull(year)) {
        searchContext.setAttribute("year", year);
    }

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

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    searchContext.setEnd(end);
    if (groupId > 0) {
        searchContext.setGroupIds(new long[] { groupId });
    }
    searchContext.setSorts(sort);
    searchContext.setStart(start);
    searchContext.setUserId(userId);

    searchContext.setAndSearch(andSearch);

    if (params != null) {

        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:ch.inofix.timetracker.service.impl.TaskRecordLocalServiceImpl.java

License:Open Source License

@Override
public Hits search(long userId, long groupId, String keywords, int start, int end, Sort sort)
        throws PortalException {

    if (sort == null) {
        sort = new Sort(Field.MODIFIED_DATE, true);
    }/*from   w w  w . j ava2 s . c o m*/

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

    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.STATUS, WorkflowConstants.STATUS_ANY);

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

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    searchContext.setCompanyId(group.getCompanyId());

    searchContext.setEnd(end);
    if (groupId > 0) {
        searchContext.setGroupIds(new long[] { groupId });
    }
    searchContext.setSorts(sort);
    searchContext.setStart(start);
    searchContext.setUserId(userId);

    searchContext.setKeywords(keywords);

    return indexer.search(searchContext);

}

From source file:com.idetronic.eprint.service.impl.EprintLocalServiceImpl.java

License:Open Source License

public Hits getHits(String keyword, long companyId, long groupId) {
    // 1. Preparing a Search Context
    SearchContext searchContext = new SearchContext();
    searchContext.setCompanyId(companyId);
    String[] CLASS_NAMES = { Eprint.class.getName() };
    searchContext.setEntryClassNames(CLASS_NAMES);
    long[] groupIds = { groupId };
    searchContext.setGroupIds(groupIds);
    // 2. Preparing a Query to search
    BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);
    String[] terms = { Field.DESCRIPTION, Field.TITLE };
    try {/*from   www  . ja  va2  s.co m*/
        searchQuery.addTerms(terms, keyword);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    // 3. Firing the query to get hits
    Hits hits = null;
    try {
        hits = SearchEngineUtil.search(searchContext, searchQuery);
    } catch (SearchException e) {
        e.printStackTrace();
    }
    return hits;
}

From source file:com.liferay.alloy.mvc.BaseAlloyControllerImpl.java

License:Open Source License

protected AlloySearchResult search(Indexer indexer, AlloyServiceInvoker alloyServiceInvoker,
        HttpServletRequest request, PortletRequest portletRequest,
        SearchContainer<? extends BaseModel<?>> searchContainer, Map<String, Serializable> attributes,
        String keywords, Sort[] sorts) throws Exception {

    if (indexer == null) {
        throw new Exception("No indexer found for " + controllerPath);
    }/*w w  w.j  ava 2s  .c om*/

    AlloySearchResult alloySearchResult = new AlloySearchResult();

    alloySearchResult.setAlloyServiceInvoker(alloyServiceInvoker);

    if (searchContainer == null) {
        searchContainer = new SearchContainer<BaseModel<?>>(portletRequest, portletURL, null, null);
    }

    SearchContext searchContext = SearchContextFactory.getInstance(request);

    boolean andOperator = ParamUtil.getBoolean(request, "andOperator");

    searchContext.setAndSearch(andOperator);

    if ((attributes != null) && !attributes.isEmpty()) {
        searchContext.setAttributes(attributes);
    }

    searchContext.setEnd(searchContainer.getEnd());

    Class<?> indexerClass = Class.forName(indexer.getClassNames()[0]);

    if (!GroupedModel.class.isAssignableFrom(indexerClass)) {
        searchContext.setGroupIds(null);
    } else if (searchContext.getAttribute(Field.GROUP_ID) != null) {
        long groupId = GetterUtil.getLong(searchContext.getAttribute(Field.GROUP_ID));

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

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

    if (ArrayUtil.isNotEmpty(sorts)) {
        searchContext.setSorts(sorts);
    }

    searchContext.setStart(searchContainer.getStart());

    Hits hits = indexer.search(searchContext);

    alloySearchResult.setHits(hits);

    alloySearchResult.setPortletURL(portletURL, searchContext.getAttributes());

    alloySearchResult.afterPropertiesSet();

    return alloySearchResult;
}

From source file:com.liferay.asset.internal.util.AssetHelperImpl.java

License:Open Source License

private AssetSearcher _getAssetSearcher(SearchContext searchContext, AssetEntryQuery assetEntryQuery, int start,
        int end) throws Exception {

    Indexer<?> searcher = AssetSearcher.getInstance();

    AssetSearcher assetSearcher = (AssetSearcher) searcher;

    assetSearcher.setAssetEntryQuery(assetEntryQuery);

    Layout layout = assetEntryQuery.getLayout();

    if (layout != null) {
        searchContext.setAttribute(Field.LAYOUT_UUID, layout.getUuid());
    }/*from   ww w .  jav a 2 s .  c o  m*/

    String ddmStructureFieldName = (String) assetEntryQuery.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = assetEntryQuery.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

        searchContext.setAttribute("ddmStructureFieldName", ddmStructureFieldName);
        searchContext.setAttribute("ddmStructureFieldValue", ddmStructureFieldValue);
    }

    String paginationType = GetterUtil.getString(assetEntryQuery.getPaginationType(), "more");

    if (!paginationType.equals("none") && !paginationType.equals("simple")) {

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

    searchContext.setClassTypeIds(assetEntryQuery.getClassTypeIds());
    searchContext.setEnd(end);
    searchContext.setGroupIds(assetEntryQuery.getGroupIds());

    if (Validator.isNull(assetEntryQuery.getKeywords())) {
        QueryConfig queryConfig = searchContext.getQueryConfig();

        queryConfig.setScoreEnabled(false);
    } else {
        searchContext.setLike(true);
    }

    searchContext.setSorts(_getSorts(assetEntryQuery, searchContext.getLocale()));
    searchContext.setStart(start);

    return assetSearcher;
}

From source file:com.liferay.asset.search.test.AssetSearcherStagingTest.java

License:Open Source License

@Test
public void testSiteRolePermissions() throws Exception {
    Role role = addRole(RoleConstants.TYPE_SITE);

    String className = "com.liferay.journal.model.JournalArticle";

    RoleTestUtil.addResourcePermission(role, className, ResourceConstants.SCOPE_GROUP_TEMPLATE, "0",
            ActionKeys.VIEW);//from w  ww.  j  av  a  2  s .  c o  m

    User user = addUser();

    ServiceTestUtil.setUser(user);

    addUserGroupRole(user, role);

    addJournalArticle();

    GroupTestUtil.enableLocalStaging(_group);

    SearchContext searchContext = getSearchContext();

    Group stagingGroup = _group.getStagingGroup();

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

    searchContext.setUserId(user.getUserId());

    QueryConfig queryConfig = searchContext.getQueryConfig();

    queryConfig.addSelectedFieldNames(Field.GROUP_ID, Field.STAGING_GROUP);

    AssetEntryQuery assetEntryQuery = getAssetEntryQuery(className);

    Hits hits = search(assetEntryQuery, searchContext);

    Document[] documents = hits.getDocs();

    DocumentsAssert.assertCount(hits.toString(), documents, Field.COMPANY_ID, 1);

    Document document = documents[0];

    assertField(document, Field.GROUP_ID, String.valueOf(stagingGroup.getGroupId()));
    assertField(document, Field.STAGING_GROUP, StringPool.TRUE);
}

From source file:com.liferay.asset.search.test.AssetSearcherTest.java

License:Open Source License

protected SearchContext getSearchContext() {
    SearchContext searchContext = new SearchContext();

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

    return searchContext;
}

From source file:com.liferay.asset.search.test.AssetUtilSearchSortTest.java

License:Open Source License

protected SearchContext createSearchContext() {
    SearchContext searchContext = new SearchContext();

    searchContext.setAttribute(Field.GROUP_ID, _group.getGroupId());
    searchContext.setCompanyId(_group.getCompanyId());
    searchContext.setGroupIds(new long[] { _group.getGroupId() });
    searchContext.setKeywords(StringPool.BLANK);
    searchContext.setUserId(_group.getCreatorUserId());

    return searchContext;
}