Do you really want to increase Alfresco’s search limit beyond 1000?

By default Alfresco Content Services sets a default search limit, based on ACL checks to 1000 items.

In order to search for more than 1000 items, you will need to do one of two things:

[su_list icon=”icon: wrench”]

  • Update the system.acl.maxPermissionChecks property in alfresco-global.properties (system wide update)
  • Override this permission check value using the Java Search API (only affects current query)

[/su_list]

However, before you make these changes, you should consider the use case behind your search requirement as a global change will allow users to run some very long accidental wildcard queries.

If search is to perform operations against content, such as update, etc., then use reducing result set search, with Alfresco Transactional Metadata Query, and search clauses that remove items that are already updated, or worked on.

Example of a CMIS search to update a list of objects that are greater than 1000. The Query will work within the default max page size of 1000, and updates will execute until the query finally returns less than 1000 or 0.

package com.example.cmissearch;

import com.google.common.collect.ImmutableList;
import org.apache.chemistry.opencmis.client.api.*;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

@SpringBootApplication
public class CmisSearchApplication {

    public static void main(String[] args) {
        SpringApplication.run(CmisSearchApplication.class, args);

        SessionFactory f = SessionFactoryImpl.newInstance();
        Map<string, string=""> parameter = new HashMap<string, string="">();

        // user credentials
        parameter.put(SessionParameter.USER, "admin");
        parameter.put(SessionParameter.PASSWORD, "admin");

        // connection settings
        parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom/");
        parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

        // set the alfresco object factory
        parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

        // create session
        SessionFactory factory = SessionFactoryImpl.newInstance();
        Session session = factory.getRepositories(parameter).get(0).createSession();

        final String QUERY = "Select * from cmis:document d where d.cmis:name like 'alex%%' and  d.cmis:lastModificationDate < '%s' ";
        String query = String.format(QUERY, LocalDateTime.now().toString());
        Boolean hasMore = false;
        do {
            ItemIterable results = session.query(query, false);
            /*
             * Max default page size by Alfresco Content Services. To go beyond this value, the
             * system.acl.maxPermissionChecks will be needed to search for results greater than 1000 by external APIS.
             *
             * NB: The Java API allows you to override this setting on the search service when querying the search engine
             */
            if (results != null) {
                List objects = new ArrayList<>();
                results.getPage(1000).forEach(item -> {
                    objects.add(session.getObject(item.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue().toString()));
                });
                Map<string, object=""> properties = new HashMap<string, object="">();
                properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, Arrays.asList("P:cm:titled"));
                properties.put("cm:title", "Added New Title");
                List updatedIds = session.bulkUpdateProperties(objects,
                        properties, null, null);

                System.out.println("Count: " + results.getTotalNumItems());
                System.out.println("Page: " + results.getPageNumItems());
                hasMore = results.getHasMoreItems();
            } else
                hasMore = false;
        } while (hasMore);

    }
}
</string,></string,></string,></string,>

 

Commonly Asked Questions:

Restriction of solr results?

How to get more than 1000 Documents By Using CMIS Query

SOLR doesnt return more than 1000 objects

CMIS query not returning expected amount of results

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: