Java Code Examples for org.alfresco.service.cmr.search.LimitBy#FINAL_SIZE

The following examples show how to use org.alfresco.service.cmr.search.LimitBy#FINAL_SIZE . 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: ACLEntryAfterInvocationProvider.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Compute a (Weak)FilteringResultSet by selecting the first maxSize elements from returnedObject.
 *
 * @param maxSize
 * @param returnedObject
 * @return
 */
private ResultSet filterMaxCount(Integer maxSize, ResultSet returnedObject)
{
    // If maxsize is not defined, than return the entire resultset.
    if (maxSize == null)
    {
        return returnedObject;
    }

    WeakFilteringResultSet filteringResultSet = new WeakFilteringResultSet(returnedObject);

    for (int i = 0; i < maxSize && i < returnedObject.length(); i++)
    {
        filteringResultSet.setIncluded(i, true);
    }

    LimitBy limitBy = returnedObject.length() > maxSize? LimitBy.FINAL_SIZE : LimitBy.UNLIMITED;

    filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(limitBy,
            PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));


    return filteringResultSet;
}
 
Example 2
Source File: ResultMapperTests.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
private ResultSet mockResultset(List<Long> archivedNodes, List<Long> versionNodes) throws JSONException
{

    NodeService nodeService = mock(NodeService.class);
    when(nodeService.getNodeRef(any())).thenAnswer(new Answer<NodeRef>() {
        @Override
        public NodeRef answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            //If the DBID is in the list archivedNodes, instead of returning a noderef return achivestore noderef
            if (archivedNodes.contains(args[0])) return new NodeRef(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, GUID.generate());
            if (versionNodes.contains(args[0])) return new NodeRef(StoreMapper.STORE_REF_VERSION2_SPACESSTORE, GUID.generate()+args[0]);
            return new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate());
        }
    });

    SearchParameters sp = new SearchParameters();
    sp.setBulkFetchEnabled(false);
    JSONObject json = new JSONObject(new JSONTokener(JSON_REPONSE));
    ResultSet results = new SolrJSONResultSet(json,sp,nodeService, null, LimitBy.FINAL_SIZE, 10);
    return results;
}
 
Example 3
Source File: ACLEntryAfterInvocationProvider.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get the max size from the search parameters.
 * The max size is the maximum number of elements to be returned, It is computed considering various
 * parameters in the searchParameters : maxSize, limitBy and skipCount.
 *
 * @param searchParameters
 * @return
 */
private Integer getMaxSize(SearchParameters searchParameters)
{
    Integer maxSize = null;
    if (searchParameters.getMaxItems() >= 0)
    {
        maxSize = searchParameters.getMaxItems() + searchParameters.getSkipCount();
    }
    else if (searchParameters.getLimitBy() == LimitBy.FINAL_SIZE)
    {
        maxSize = searchParameters.getLimit() + searchParameters.getSkipCount();
    }

    return maxSize;
}
 
Example 4
Source File: SolrSQLJSONResultSet.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public SolrSQLJSONResultSet(JSONObject json, SearchParameters searchParameters)
{
    try
    {
        solrResponse = ((JSONObject) json).toString();
        JSONObject res = (JSONObject) json.get("result-set");
        docs = (JSONArray) res.get("docs");
        /*
         * Check that there is no error, which is returned in the first object.
         */
        
        JSONObject obj1 = docs.getJSONObject(0);
        if(obj1.has(SOLR_STREAM_EXCEPTION)) 
        {
            String error =  obj1.get(SOLR_STREAM_EXCEPTION).toString();
            if(error.equalsIgnoreCase("/sql handler only works in Solr Cloud mode"))
            {
                throw new RuntimeException("Unable to execute the query, this API requires InsightEngine.");
            }
            else
            {
                throw new RuntimeException("Unable to execute the query, error caused by: " + error);
            }
        }
        //Check if it has an error
        this.length = docs.length();
        //Last element will contain the object that hold the solr response time.
        JSONObject time = (JSONObject) docs.get(length -1);
        this.numberFound = length - 1;
        queryTime = new Long((Integer) time.get("RESPONSE_TIME"));
        // Were hard coding this as we have a hard limit of 1000 results, any more will not be readable.
        this.resultSetMetaData = new SimpleResultSetMetaData(LimitBy.FINAL_SIZE, 
                PermissionEvaluationMode.EAGER, (SearchParameters)searchParameters);
    } 
    catch (JSONException e)
    {
        logger.info(e.getMessage());
    }
}
 
Example 5
Source File: DBResultSet.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public DBResultSet(SearchParameters searchParameters, List<Long> dbids, NodeDAO nodeDao,  NodeService nodeService, TenantService tenantService, int maximumResultsFromUnlimitedQuery)
{
    this.nodeDao = nodeDao;
    this.dbids = dbids;
    this.nodeService = nodeService;
    this.tenantService = tenantService;
    this.prefetch = new BitSet(dbids.size());
    nodeRefs= new NodeRef[(dbids.size())];
    
    final LimitBy limitBy;
    int maxResults = -1;
    if (searchParameters.getMaxItems() >= 0)
    {
        maxResults = searchParameters.getMaxItems();
        limitBy = LimitBy.FINAL_SIZE;
    }
    else if(searchParameters.getLimitBy() == LimitBy.FINAL_SIZE && searchParameters.getLimit() >= 0)
    {
        maxResults = searchParameters.getLimit();
        limitBy = LimitBy.FINAL_SIZE;
    }
    else
    {
        maxResults = searchParameters.getMaxPermissionChecks();
        if (maxResults < 0)
        {
            maxResults = maximumResultsFromUnlimitedQuery;
        }
        limitBy = LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS;
    }
    
    this.resultSetMetaData = new SimpleResultSetMetaData(
            maxResults > 0 && dbids.size() < maxResults ? LimitBy.UNLIMITED : limitBy,
            PermissionEvaluationMode.EAGER, searchParameters);
}
 
Example 6
Source File: QueryOptions.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static QueryOptions create(SearchParameters searchParameters)
{
    QueryOptions options = new QueryOptions(searchParameters.getQuery(), null);
    options.setIncludeInTransactionData(!searchParameters.excludeDataInTheCurrentTransaction());
    options.setDefaultFTSConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR : Connective.AND);
    options.setDefaultFTSFieldConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR : Connective.AND);
    options.setSkipCount(searchParameters.getSkipCount());
    options.setMaxPermissionChecks(searchParameters.getMaxPermissionChecks());
    options.setMaxPermissionCheckTimeMillis(searchParameters.getMaxPermissionCheckTimeMillis());
    options.setDefaultFieldName(searchParameters.getDefaultFieldName());
    if (searchParameters.getLimitBy() == LimitBy.FINAL_SIZE)
    {
        options.setMaxItems(searchParameters.getLimit());
    }
    else
    {
        options.setMaxItems(searchParameters.getMaxItems());
    }
    options.setMlAnalaysisMode(searchParameters.getMlAnalaysisMode());
    options.setLocales(searchParameters.getLocales());
    options.setStores(searchParameters.getStores());
    options.setQueryParameterDefinitions(searchParameters.getQueryParameterDefinitions());
    ///options.setQuery(query); Done on construction.
    options.setUseInMemorySort(searchParameters.getUseInMemorySort());
    options.setMaxRawResultSetSizeForInMemorySort(searchParameters.getMaxRawResultSetSizeForInMemorySort());
    options.setBulkFetchEnabled(searchParameters.isBulkFetchEnabled());
    options.setExcludeTenantFilter(searchParameters.getExcludeTenantFilter());
    options.setQueryConsistency(searchParameters.getQueryConsistency());
    options.setSinceTxId(searchParameters.getSinceTxId());
    for(String name : searchParameters.getQueryTemplates().keySet())
    {
    	String template = searchParameters.getQueryTemplates().get(name);
    	options.addQueryTemplate(name, template);
    }
    return options;
}
 
Example 7
Source File: CMISQueryOptions.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static CMISQueryOptions create(SearchParameters searchParameters)
{
    String sql = searchParameters.getQuery();

    CMISQueryOptions options = new CMISQueryOptions(sql, searchParameters.getStores().get(0));
    options.setIncludeInTransactionData(!searchParameters.excludeDataInTheCurrentTransaction());
    options.setDefaultFTSConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR : Connective.AND);
    options.setDefaultFTSFieldConnective(searchParameters.getDefaultOperator() == SearchParameters.Operator.OR ? Connective.OR : Connective.AND);
    options.setSkipCount(searchParameters.getSkipCount());
    options.setMaxPermissionChecks(searchParameters.getMaxPermissionChecks());
    options.setMaxPermissionCheckTimeMillis(searchParameters.getMaxPermissionCheckTimeMillis());
    if (searchParameters.getLimitBy() == LimitBy.FINAL_SIZE)
    {
        options.setMaxItems(searchParameters.getLimit());
    }
    else
    {
        options.setMaxItems(searchParameters.getMaxItems());
    }
    options.setMlAnalaysisMode(searchParameters.getMlAnalaysisMode());
    options.setLocales(searchParameters.getLocales());
    options.setStores(searchParameters.getStores());
    options.setUseInMemorySort(searchParameters.getUseInMemorySort());
    options.setMaxRawResultSetSizeForInMemorySort(searchParameters.getMaxRawResultSetSizeForInMemorySort());
    //options.setQuery(); Done on conbstruction
    //options.setQueryMode(); Should set afterwards
    options.setQueryParameterDefinitions(searchParameters.getQueryParameterDefinitions());
    options.setDefaultFieldName(searchParameters.getDefaultFieldName());
    options.setBulkFetchEnabled(searchParameters.isBulkFetchEnabled());
    options.setExcludeTenantFilter(searchParameters.getExcludeTenantFilter());
    options.setSinceTxId(searchParameters.getSinceTxId());
    for(String name : searchParameters.getQueryTemplates().keySet())
    {
    	String template = searchParameters.getQueryTemplates().get(name);
    	options.addQueryTemplate(name, template);
    }
    return options;
}
 
Example 8
Source File: ResultMapperTests.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ResultSet mockResultset(String json) throws Exception
{
    NodeService nodeService = mock(NodeService.class);
    JSONObject jsonObj = new JSONObject(new JSONTokener(json));
    SearchParameters sp = new SearchParameters();
    sp.setBulkFetchEnabled(false);
    ResultSet results = new SolrJSONResultSet(jsonObj,
                                              sp,
                                              nodeService,
                                              null,
                                              LimitBy.FINAL_SIZE,
                                              10);
    return results;
}