Finding Sites by a Term - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

To find sites by term use the findSites method of the QueriesApi, which is a search API you can use when doing simple search on a term. For more complex search, such as Alfresco Full Text Search (AFTS), use the Search API (see Finding Content by a Search Query).

For more information about this ReST API endpoint, see Finding Sites by a Term.

For a description of the common parameters, such as fields, see Common Parameters.

import org.alfresco.core.handler.QueriesApi;
import org.alfresco.core.model.SiteEntry;
import org.alfresco.core.model.SitePagingList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

@Component
public class FindSitesCmd {
    static final Logger LOGGER = LoggerFactory.getLogger(FindSitesCmd.class);

    @Autowired
    QueriesApi queriesApi;

    public void execute() throws IOException {
        Integer skipCount = 0;
        Integer maxItems = 100;

        List<String> orderBy = null;
        List<String> fields = null;

        String term = "Soft*";
        LOGGER.info("Searching for sites by term: {}", term);
        SitePagingList result = queriesApi.findSites(term, skipCount, maxItems, orderBy, fields).getBody().getList();
        for (SiteEntry node: result.getEntries()) {
            LOGGER.info("Found site [id={}][name={}]", node.getEntry().getId(), node.getEntry().getTitle());
        }
    }
}

Executing this code gives the following type of result:

% java -jar target/rest-api-0.0.1-SNAPSHOT.jar find-sites

2021-05-10 13:52:04.833  INFO 55062 --- [           main] o.a.tutorial.restapi.RestApiApplication  : Started RestApiApplication in 4.107 seconds (JVM running for 4.762)
2021-05-10 13:52:04.835  INFO 55062 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[0]: find-sites
2021-05-10 13:52:04.845  INFO 55062 --- [           main] o.a.tutorial.restapi.FindSitesCmd        : Searching for sites by term: Soft*
2021-05-10 13:52:05.036  INFO 55062 --- [           main] o.a.tutorial.restapi.FindSitesCmd        : Found site [id=downloadable-software][name=Downloadable Software]
2021-05-10 13:52:05.036  INFO 55062 --- [           main] o.a.tutorial.restapi.FindSitesCmd        : Found site [id=software-design][name=Software Design]