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

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

Introduction

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

Prototype

public void setOwnerUserId(long ownerUserId) 

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   w ww.j av  a  2s  . 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//  w  w  w .  ja va  2s  .co 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);

}