org.alfresco.service.cmr.search.SearchParameters.SortDefinition.SortType Java Examples

The following examples show how to use org.alfresco.service.cmr.search.SearchParameters.SortDefinition.SortType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SortConstraint.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected SearchParameters applyDecorations(ActualEnvironment environment, SearchParameters searchParameters,
            VirtualQuery query)
{
    SearchParameters searchParametersCopy = searchParameters.copy();
    for (Pair<QName, Boolean> sort : sortProps)
    {
        if (!IGNORED_SORT_PROPERTIES.contains(sort.getFirst()))
        {
            SortDefinition sortDefinition = new SortDefinition(SortType.FIELD,
                                                               sort.getFirst().getPrefixString(),
                                                               sort.getSecond());
            searchParametersCopy.addSort(sortDefinition);
        }
    }
    return searchParametersCopy;
}
 
Example #2
Source File: SearchMapper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * SearchParameters from List<SortDef>
 * @param sp SearchParameters
 * @param sort List<SortDef>
 */
public void fromSort(SearchParameters sp, List<SortDef> sort)
{
    if (sort != null && !sort.isEmpty())
    {
        if (LANGUAGE_CMIS_ALFRESCO.equals(sp.getLanguage()))
        {
            throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
                        new Object[] { ": sort {} not allowed with cmis language" });
        }
        for (SortDef sortDef:sort)
        {

            try
            {
                SortType sortType = SortType.valueOf(sortDef.getType());
                String field = sortDef.getField();
                sp.addSort(new SortDefinition(sortType, field, sortDef.isAscending()));
            }
            catch (IllegalArgumentException e)
            {
                throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID, new Object[] { sortDef.getType() });
            }
        }
    }
}
 
Example #3
Source File: LuceneQuery.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<SortDefinition> buildSortDefinitions(Set<String> selectors, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
{
    if ((getOrderings() == null) || (getOrderings().size() == 0))
    {
        return Collections.<SortDefinition>emptyList();
    }

    ArrayList<SortDefinition> definitions = new ArrayList<SortDefinition>(getOrderings().size());

    for (Ordering ordering : getOrderings())
    {
        if (ordering.getColumn().getFunction().getName().equals(PropertyAccessor.NAME))
        {
            PropertyArgument property = (PropertyArgument) ordering.getColumn().getFunctionArguments().get(PropertyAccessor.ARG_PROPERTY);

            if (property == null)
            {
                throw new IllegalStateException();
            }

            String propertyName = property.getPropertyName();

            String fieldName = functionContext.getLuceneFieldName(propertyName);
            
            definitions.add(new SortDefinition(SortType.FIELD, fieldName, ordering.getOrder() == Order.ASCENDING));
        }
        else if (ordering.getColumn().getFunction().getName().equals(Score.NAME))
        {
            definitions.add(new SortDefinition(SortType.SCORE, null, ordering.getOrder() == Order.ASCENDING));
        }
    }

    return definitions;
}