Interface CQLSearchService


  • public interface CQLSearchService
    Entry point into CQL Search. Provides methods for executing the Confluence Query Language queries to fetch indexed Content.

    See Advanced Searching using CQL

    Since:
    5.7
    • Method Detail

      • searchContent

        PageResponse<Content> searchContent​(String cqlInput,
                                            SearchContext searchContext,
                                            PageRequest pageRequest,
                                            Expansion... expansions)
        Execute a CQL search query and fetch a page results.

        For example, to fetch the first 10 pieces of content in the DEV space with a title containing 'Specs' :

         cqlSearchService.searchContent("space = DEV AND title ~ 'Specs' ORDER BY title", SearchContext.builder().build(), new SimplePageRequest(0, 10));
         

        The service will verify the execution context, confirming that the passed entity ids exist, throwing NotFoundException if they don't exist.

        Parameters:
        cqlInput - - the CQL query to execute
        searchContext - - the context to execute the search in
        pageRequest - - the pagination request, indicating the start position and limit for the result
        expansions - - the optional properties to expand on the result
      • searchContent

        PageResponse<Content> searchContent​(String cqlInput,
                                            PageRequest pageRequest,
                                            Expansion... expansions)
        Execute a CQL search query and fetch a page results.

        For example, to fetch the first 10 pieces of content in the DEV space with a title containing 'Specs' :

         cqlSearchService.searchContent("space = DEV AND title ~ 'Specs' ORDER BY title", new SimplePageRequest(0, 10));
         

        This variant of the method executes with the default search context of just the logged in user.

        Parameters:
        cqlInput - - the CQL query to execute
        pageRequest - - the pagination request, indicating the start position and limit for the result
        expansions - - the optional properties to expand on the result
      • searchContent

        PageResponse<Content> searchContent​(String cqlInput,
                                            Expansion... expansions)
        Execute a CQL search query and fetch a page results.

        For example, to fetch the first page of content in the DEV space with a title containing 'Specs' :

         cqlSearchService.searchContent("space = DEV AND title ~ 'Specs' ORDER BY title", ExpansionParser.parse("space, history"));
         

        This variant executes with the default execution context and a default page size.

        Parameters:
        cqlInput - - the CQL query to execute
        expansions - - optional properties to expand on the result, if an expandable property is not specified here that property will not be accessible
      • countContent

        int countContent​(String cqlInput)
        Execute a CQL search query and fetch the number of results found.

        For example to count the number of pages and blogs in the DEV space created by admin :

         cqlSearchService.countContent("type in (page, blogpost) and space = DEV and creator = admin");
         

        Parameters:
        cqlInput - - the cql query to count the results of
        Returns:
        a count of the results that match the cql query
      • countContent

        int countContent​(String cqlInput,
                         SearchContext searchContext)
        Execute a CQL search query and fetch the number of results found.

        For example to count the number of pages and blogs in the DEV space created by admin :

         cqlSearchService.countContent("type in (page, blogpost) and space = DEV and creator = admin", SearchContext.builder().build());
         

        Parameters:
        cqlInput - - the cql query to count the results of
        searchContext - - the context to execute the search in
        Returns:
        a count of the results that match the cql query
      • search

        @Internal
        SearchPageResponse<SearchResult> search​(String cqlInput,
                                                SearchOptions searchOptions,
                                                PageRequest pageRequest,
                                                Expansion... expansions)
        Execute a CQL search query and fetch a page of results.

        The result set includes all searchable entities in confluence, including users, spaces, content and plugin content, such as Confluence Questions.

        Expansions are applied to the entity in the search result that matches the entity type. For instance to expand the version property on a piece of content, pass the expansion property: "content.version", likewise to expand the homepage of a space, use the expansion string : "space.homepage"

        Parameters:
        cqlInput - - the query to search
        searchOptions - - search options to apply when executing the query
        pageRequest - - the pagination request, indicating the start position and limit for the result
        expansions - - the expansions to apply to the result.
        Returns:
        a page of SearchResults
        Since:
        5.9