Search in sources :

Example 1 with ReSortingQueryResults

use of com.zimbra.cs.index.ReSortingQueryResults in project zm-mailbox by Zimbra.

the class MailboxIndex method search.

private ZimbraQueryResults search(ZimbraQuery zq) throws ServiceException {
    SearchParams params = zq.getParams();
    ZimbraLog.search.debug("query: %s", params.getQueryString());
    ZimbraLog.searchstat.debug("query: %s", zq.toSanitizedtring());
    // handle special-case Task-only sorts: convert them to a "normal sort" and then re-sort them at the end
    // TODO: this hack (converting the sort) should be able to go away w/ the new SortBy implementation, if the
    // lower-level code was modified to use the SortBy.Criterion and SortBy.Direction data (instead of switching on
    // the SortBy itself). We still will need this switch so that we can wrap the results in ReSortingQueryResults.
    boolean isTaskSort = false;
    boolean isLocalizedSort = false;
    SortBy originalSort = params.getSortBy();
    switch(originalSort) {
        case TASK_DUE_ASC:
            isTaskSort = true;
            params.setSortBy(SortBy.DATE_DESC);
            break;
        case TASK_DUE_DESC:
            isTaskSort = true;
            params.setSortBy(SortBy.DATE_DESC);
            break;
        case TASK_STATUS_ASC:
            isTaskSort = true;
            params.setSortBy(SortBy.DATE_DESC);
            break;
        case TASK_STATUS_DESC:
            isTaskSort = true;
            params.setSortBy(SortBy.DATE_DESC);
            break;
        case TASK_PERCENT_COMPLETE_ASC:
            isTaskSort = true;
            params.setSortBy(SortBy.DATE_DESC);
            break;
        case TASK_PERCENT_COMPLETE_DESC:
            isTaskSort = true;
            params.setSortBy(SortBy.DATE_DESC);
            break;
        case NAME_LOCALIZED_ASC:
        case NAME_LOCALIZED_DESC:
            isLocalizedSort = true;
            break;
    }
    ZimbraQueryResults results = zq.execute();
    if (isTaskSort) {
        results = new ReSortingQueryResults(results, originalSort, null);
    }
    if (isLocalizedSort) {
        results = new ReSortingQueryResults(results, originalSort, params);
    }
    return results;
}
Also used : SearchParams(com.zimbra.cs.index.SearchParams) SortBy(com.zimbra.cs.index.SortBy) ZimbraQueryResults(com.zimbra.cs.index.ZimbraQueryResults) ReSortingQueryResults(com.zimbra.cs.index.ReSortingQueryResults)

Aggregations

ReSortingQueryResults (com.zimbra.cs.index.ReSortingQueryResults)1 SearchParams (com.zimbra.cs.index.SearchParams)1 SortBy (com.zimbra.cs.index.SortBy)1 ZimbraQueryResults (com.zimbra.cs.index.ZimbraQueryResults)1