Example usage for com.liferay.portal.kernel.search SortFactoryUtil getDefaultSorts

List of usage examples for com.liferay.portal.kernel.search SortFactoryUtil getDefaultSorts

Introduction

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

Prototype

public static Sort[] getDefaultSorts() 

Source Link

Usage

From source file:com.liferay.knowledgebase.util.KnowledgeBaseUtil.java

License:Open Source License

public static Sort[] getKBArticleSorts(String orderByCol, String orderByType) {

    if (Validator.isNull(orderByCol) || Validator.isNull(orderByType)) {
        return SortFactoryUtil.getDefaultSorts();
    }//from  w  w w .j  av  a2 s .  c o m

    boolean reverse = true;

    if (orderByType.equals("asc")) {
        reverse = false;
    }

    if (orderByCol.equals("create-date")) {
        String fieldName = Field.CREATE_DATE;

        return new Sort[] { SortFactoryUtil.create(fieldName, Sort.LONG_TYPE, reverse),
                SortFactoryUtil.create(null, Sort.SCORE_TYPE, false) };
    } else if (orderByCol.equals("modified-date")) {
        String fieldName = Field.MODIFIED_DATE;

        return new Sort[] { SortFactoryUtil.create(fieldName, Sort.LONG_TYPE, reverse),
                SortFactoryUtil.create(null, Sort.SCORE_TYPE, false) };
    } else if (orderByCol.equals("score")) {
        String fieldName = null;

        return new Sort[] { SortFactoryUtil.create(fieldName, Sort.SCORE_TYPE, !reverse),
                SortFactoryUtil.create(Field.MODIFIED_DATE, Sort.LONG_TYPE, true) };
    } else if (orderByCol.equals("title")) {
        String fieldName = "titleKeyword";

        return new Sort[] { SortFactoryUtil.create(fieldName, Sort.STRING_TYPE, reverse),
                SortFactoryUtil.create(null, Sort.SCORE_TYPE, false) };
    } else if (orderByCol.equals("user-name")) {
        String fieldName = Field.USER_NAME;

        return new Sort[] { SortFactoryUtil.create(fieldName, Sort.STRING_TYPE, reverse),
                SortFactoryUtil.create(null, Sort.SCORE_TYPE, false) };
    }

    return SortFactoryUtil.getDefaultSorts();
}

From source file:com.liferay.mail.util.AccountIndexer.java

License:Open Source License

@Override
protected void doDelete(Account account) throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(account.getCompanyId());
    searchContext.setEnd(QueryUtil.ALL_POS);
    searchContext.setSearchEngineId(getSearchEngineId());
    searchContext.setSorts(SortFactoryUtil.getDefaultSorts());
    searchContext.setStart(QueryUtil.ALL_POS);

    BooleanQuery booleanQuery = new BooleanQueryImpl();

    booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, CLASS_NAME);

    booleanQuery.addRequiredTerm("accountId", account.getAccountId());

    Hits hits = IndexSearcherHelperUtil.search(searchContext, booleanQuery);

    List<String> uids = new ArrayList<>(hits.getLength());

    for (int i = 0; i < hits.getLength(); i++) {
        Document document = hits.doc(i);

        uids.add(document.get(Field.UID));
    }// w  w  w  .jav  a  2s . com

    IndexWriterHelperUtil.deleteDocuments(getSearchEngineId(), account.getCompanyId(), uids,
            isCommitImmediately());
}

From source file:com.liferay.mail.util.FolderIndexer.java

License:Open Source License

@Override
protected void doDelete(Folder folder) throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setCompanyId(folder.getCompanyId());
    searchContext.setEnd(QueryUtil.ALL_POS);
    searchContext.setSearchEngineId(getSearchEngineId());
    searchContext.setSorts(SortFactoryUtil.getDefaultSorts());
    searchContext.setStart(QueryUtil.ALL_POS);

    BooleanQuery booleanQuery = new BooleanQueryImpl();

    booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, CLASS_NAME);

    booleanQuery.addRequiredTerm("folderId", folder.getFolderId());

    Hits hits = IndexSearcherHelperUtil.search(searchContext, booleanQuery);

    List<String> uids = new ArrayList<>(hits.getLength());

    for (int i = 0; i < hits.getLength(); i++) {
        Document document = hits.doc(i);

        uids.add(document.get(Field.UID));
    }/*  ww w . java2s  . c o m*/

    IndexWriterHelperUtil.deleteDocuments(getSearchEngineId(), folder.getCompanyId(), uids,
            isCommitImmediately());
}

From source file:com.liferay.mail.util.MessageIndexer.java

License:Open Source License

@Override
protected void doDelete(Object obj) throws Exception {
    SearchContext searchContext = new SearchContext();

    searchContext.setSearchEngineId(getSearchEngineId());

    if (obj instanceof Account) {
        Account account = (Account) obj;

        searchContext.setCompanyId(account.getCompanyId());
        searchContext.setEnd(QueryUtil.ALL_POS);
        searchContext.setSorts(SortFactoryUtil.getDefaultSorts());
        searchContext.setStart(QueryUtil.ALL_POS);

        BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);

        booleanQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);

        booleanQuery.addRequiredTerm("accountId", account.getAccountId());

        Hits hits = SearchEngineUtil.search(searchContext, booleanQuery);

        List<String> uids = new ArrayList<String>(hits.getLength());

        for (int i = 0; i < hits.getLength(); i++) {
            Document document = hits.doc(i);

            uids.add(document.get(Field.UID));
        }/*from   www .  j a  va2 s .  com*/

        SearchEngineUtil.deleteDocuments(getSearchEngineId(), account.getCompanyId(), uids,
                isCommitImmediately());
    } else if (obj instanceof Folder) {
        Folder folder = (Folder) obj;

        searchContext.setCompanyId(folder.getCompanyId());
        searchContext.setEnd(QueryUtil.ALL_POS);
        searchContext.setSorts(SortFactoryUtil.getDefaultSorts());
        searchContext.setStart(QueryUtil.ALL_POS);

        BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext);

        booleanQuery.addRequiredTerm(Field.PORTLET_ID, PORTLET_ID);

        booleanQuery.addRequiredTerm("folderId", folder.getFolderId());

        Hits hits = SearchEngineUtil.search(searchContext, booleanQuery);

        List<String> uids = new ArrayList<String>(hits.getLength());

        for (int i = 0; i < hits.getLength(); i++) {
            Document document = hits.doc(i);

            uids.add(document.get(Field.UID));
        }

        SearchEngineUtil.deleteDocuments(getSearchEngineId(), folder.getCompanyId(), uids,
                isCommitImmediately());
    } else if (obj instanceof Message) {
        Message message = (Message) obj;

        Document document = new DocumentImpl();

        document.addUID(PORTLET_ID, message.getMessageId());

        SearchEngineUtil.deleteDocument(getSearchEngineId(), message.getCompanyId(), document.get(Field.UID),
                isCommitImmediately());
    }
}