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

The following examples show how to use org.alfresco.service.cmr.search.SearchParameters.SortDefinition. 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: VirtualQueryImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void assertPerform1Results(Pair<QName, Boolean> withSortDefinitions)
{
    ArgumentCaptor<SearchParameters> queryCaptor = ArgumentCaptor.forClass(SearchParameters.class);
    Mockito.verify(mockitoActualEnvironment).query(queryCaptor.capture());

    assertEquals("(QUERY_TEST_STRING_QUERY) and !ASPECT:'tst:testQName1' and !TYPE:'tst:testQName2'",
                 queryCaptor.getValue().getQuery());

    ArrayList<SortDefinition> sortDefinitions = queryCaptor.getValue().getSortDefinitions();

    assertNotNull(sortDefinitions);
    assertEquals(1,
                 sortDefinitions.size());
    assertEquals(withSortDefinitions.getFirst().getPrefixString(),
                 sortDefinitions.get(0).getField());

    assertEquals(withSortDefinitions.getSecond(),
                 Boolean.valueOf(sortDefinitions.get(0).isAscending()));
}
 
Example #3
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 #4
Source File: SolrQueryHTTPClientTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private StatsParameters getParameters()
{

    StringBuilder luceneQuery = new StringBuilder();
    luceneQuery.append(" +TYPE:\"" + ContentModel.TYPE_CONTENT + "\"");
    String filterQuery = "ANCESTOR:\"workspace://SpacesStore/a1c1a0a1-9d68-4912-b853-b3b277f31288\"";
    StatsParameters params = new StatsParameters(SearchService.LANGUAGE_SOLR_FTS_ALFRESCO, luceneQuery.toString(), filterQuery, false);
    params.addSort(new SortDefinition(SortDefinition.SortType.FIELD, "contentsize", false));
    params.addStatsParameter(StatsParameters.PARAM_FIELD, "contentsize");
    params.addStatsParameter(StatsParameters.PARAM_FACET, StatsParameters.FACET_PREFIX + ContentModel.PROP_CREATED.toString());
    params.addStatsParameter("Test1", StatsParameters.FACET_PREFIX + "author. .u");
    params.addStatsParameter("Test2", StatsParameters.FACET_PREFIX + "creator. .u");
    return params;
}
 
Example #5
Source File: VirtualQueryImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void assertPerform2Results()
{
    ArgumentCaptor<SearchParameters> queryCaptor = ArgumentCaptor.forClass(SearchParameters.class);
    Mockito.verify(mockitoActualEnvironment).query(queryCaptor.capture());

    assertEquals("((QUERY_TEST_STRING_QUERY) and TYPE:\"cm:folder\") and !ASPECT:'tst:testQName1' and !TYPE:'tst:testQName2'",
                 queryCaptor.getValue().getQuery());

    ArrayList<SortDefinition> sortDefinitions = queryCaptor.getValue().getSortDefinitions();

    assertNotNull(sortDefinitions);
    assertEquals(0,
                 sortDefinitions.size());
}
 
Example #6
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;
}
 
Example #7
Source File: SolrQueryHTTPClient.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private StringBuffer buildSortParameters(BasicSearchParameters searchParameters, URLCodec encoder)
            throws UnsupportedEncodingException
{
    StringBuffer sortBuffer = new StringBuffer();
    for (SortDefinition sortDefinition : searchParameters.getSortDefinitions())
    {
        if (sortBuffer.length() == 0)
        {
            sortBuffer.append("&sort=");
        }
        else
        {
            sortBuffer.append(encoder.encode(", ", "UTF-8"));
        }
        // MNT-8557 fix, manually replace ' ' with '%20'
        // The sort can be different, see MNT-13742
        switch (sortDefinition.getSortType())
        {
            case DOCUMENT:
                sortBuffer.append(encoder.encode("_docid_", "UTF-8")).append(encoder.encode(" ", "UTF-8"));
                break;
            case SCORE:
                sortBuffer.append(encoder.encode("score", "UTF-8")).append(encoder.encode(" ", "UTF-8"));
                break;
            case FIELD:
            default:
                sortBuffer.append(encoder.encode(sortDefinition.getField().replaceAll(" ", "%20"), "UTF-8")).append(encoder.encode(" ", "UTF-8"));
                break;
        }
     if (sortDefinition.isAscending())
        {
            sortBuffer.append(encoder.encode("asc", "UTF-8"));
        }
        else
        {
            sortBuffer.append(encoder.encode("desc", "UTF-8"));
        }

    }
    return sortBuffer;
}
 
Example #8
Source File: SearchSQLParameters.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public List<SortDefinition> getSortDefinitions()
{
    return null;
}
 
Example #9
Source File: StatsParameters.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
public List<SortDefinition> getSortDefinitions()
{
    return this.sortDefinitions;
}
 
Example #10
Source File: LuceneQueryBuilder.java    From alfresco-data-model with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Build a sort definition for a sorted result set wrapper
 * @param functionContext FunctionEvaluationContext
 */
public List<SortDefinition> buildSortDefinitions(Set<String> selectors, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext);
 
Example #11
Source File: StatsParameters.java    From alfresco-data-model with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Add a sort definition.
 * 
 * @param sortDefinition - the sort definition to add. 
 */
public void addSort(SortDefinition sortDefinition)
{
    sortDefinitions.add(sortDefinition);
}
 
Example #12
Source File: BasicSearchParameters.java    From alfresco-data-model with GNU Lesser General Public License v3.0 votes vote down vote up
public List<SortDefinition> getSortDefinitions();