Example usage for com.liferay.portal.kernel.search Sort Sort

List of usage examples for com.liferay.portal.kernel.search Sort Sort

Introduction

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

Prototype

public Sort(String fieldName, boolean reverse) 

Source Link

Usage

From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.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 ww  . j  av a  2s  . c om*/

    String company = null;
    String fullName = null;
    boolean andOperator = false;

    if (Validator.isNotNull(keywords)) {

        company = keywords;
        fullName = keywords;

    } else {
        andOperator = true;
    }

    return search(userId, groupId, 0, company, fullName, WorkflowConstants.STATUS_ANY, null, andOperator, start,
            end, sort);

}

From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java

License:Open Source License

@Override
public Hits search(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 {

    if (sort == null) {
        sort = new Sort(Field.MODIFIED_DATE, true);
    }/* w ww  .j  av  a  2s . co  m*/

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

    SearchContext searchContext = buildSearchContext(userId, groupId, ownerUserId, company, fullName, status,
            params, andSearch, start, end, sort);

    return indexer.search(searchContext);

}

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

License:Open Source License

/**
 * @param userId/*w w  w . ja  v  a 2 s.  com*/
 *            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

@Override
public Hits search(long userId, long groupId, long bibliographyId, 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 av  a 2 s .  c o  m

    String author = null;
    String title = null;
    String year = null;

    boolean andOperator = false;

    if (Validator.isNotNull(keywords)) {

        author = keywords;
        title = keywords;
        year = keywords;

    } else {
        andOperator = true;
    }

    return search(userId, groupId, bibliographyId, author, title, year, WorkflowConstants.STATUS_ANY, null,
            andOperator, start, end, sort);

}

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

License:Open Source License

@Override
public Hits search(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 {

    if (sort == null) {
        sort = new Sort(Field.MODIFIED_DATE, true);
    }/*  www  .j ava 2s .  c o m*/

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

    SearchContext searchContext = buildSearchContext(userId, groupId, bibliographyId, author, title, year,
            status, params, andSearch, start, end, sort);

    return indexer.search(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  ww . ja  va  2s.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.library.slayer.service.impl.LMSBookLocalServiceImpl.java

License:Open Source License

public List<LMSBook> advanceSearchAll(long companyId, long groupId, String title, String author, String desc,
        String type) {/*from  ww  w.  j a  v a2  s.  c  o m*/

    SearchContext searchContext = new SearchContext();
    searchContext.setCompanyId(companyId);
    searchContext.setEntryClassNames(CLASS_NAMES);

    BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext);
    contextQuery.addRequiredTerm(Field.COMPANY_ID, companyId);
    contextQuery.addRequiredTerm(Field.PORTLET_ID,
            Long.toString(ClassNameLocalServiceUtil.getClassNameId(LMSBook.class)));

    BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext);
    fullQuery.setQueryConfig(searchContext.getQueryConfig());
    try {
        fullQuery.add(contextQuery, BooleanClauseOccur.MUST);
    } catch (ParseException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext);
    Hits hits = null;

    if (Validator.isNotNull(title)) {
        Sort sort = new Sort(Field.TITLE, true);
        searchContext.setSorts(new Sort[] { sort });

        fullQuery = createQuery(Field.TITLE, title, searchContext, fullQuery);

    }
    if (Validator.isNotNull(author)) {
        fullQuery = createQuery(Field.NAME, author, searchContext, fullQuery);
    }
    if (Validator.isNotNull(desc)) {
        fullQuery = createQuery(Field.DESCRIPTION, desc, searchContext, fullQuery);
    }

    if (searchQuery.clauses().size() > 0) {
        try {
            fullQuery.add(searchQuery, BooleanClauseOccur.MUST);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    try {
        hits = SearchEngineUtil.search(searchContext, fullQuery);
    } catch (SearchException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    List<LMSBook> books = new ArrayList<LMSBook>();

    if (hits != null && hits.getLength() > 0) {
        for (Document document : hits.getDocs()) {

            long bookId = Long.parseLong(document.get(Field.ENTRY_CLASS_PK));
            try {
                LMSBook book = LMSBookLocalServiceUtil.getLMSBook(bookId);
                books.add(book);
            } catch (PortalException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SystemException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return books;
}

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

License:Open Source License

protected static String executeSearch(BaseAlloyControllerImpl baseAlloyControllerImpl,
        ActionRequest actionRequest) throws Exception {

    if (baseAlloyControllerImpl.permissioned) {
        AlloyPermission.check(baseAlloyControllerImpl.themeDisplay, baseAlloyControllerImpl.controllerPath,
                "index");
    }//from www .  ja  v  a 2 s . co  m

    Map<String, Serializable> attributes = null;

    String attributesString = ParamUtil.getString(actionRequest, "attributes");

    if (Validator.isNotNull(attributesString)) {
        attributes = JSONFactoryUtil.looseDeserialize(attributesString, HashMap.class);
    }

    String keywords = ParamUtil.getString(actionRequest, "keywords");

    Sort[] sorts = null;

    String sortsString = ParamUtil.getString(actionRequest, "sorts");

    if (Validator.isNotNull(sortsString)) {
        Map<String, Boolean> sortsMap = JSONFactoryUtil.looseDeserialize(sortsString, LinkedHashMap.class);

        sorts = new Sort[sortsMap.size()];

        int i = 0;

        for (Map.Entry<String, Boolean> entry : sortsMap.entrySet()) {
            sorts[i++] = new Sort(entry.getKey(), entry.getValue());
        }
    }

    AlloySearchResult alloySearchResult = baseAlloyControllerImpl.search(
            PortalUtil.getHttpServletRequest(actionRequest), actionRequest, attributes, keywords, sorts);

    List<BaseModel<?>> baseModels = alloySearchResult.getBaseModels();

    return JSONFactoryUtil.looseSerialize(baseModels);
}

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

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