Class DefaultPaginatedFlexibleSearchService

java.lang.Object
de.hybris.platform.servicelayer.search.paginated.impl.DefaultPaginatedFlexibleSearchService
All Implemented Interfaces:
PaginatedFlexibleSearchService

public class DefaultPaginatedFlexibleSearchService extends Object implements PaginatedFlexibleSearchService
Default implementation of PaginatedFlexibleSearchService
  • Constructor Details

    • DefaultPaginatedFlexibleSearchService

      public DefaultPaginatedFlexibleSearchService()
  • Method Details

    • search

      public <T> SearchPageData<T> search(PaginatedFlexibleSearchParameter parameter)
      Description copied from interface: PaginatedFlexibleSearchService
      Searches according to PaginatedFlexibleSearchParameter.
      Specified by:
      search in interface PaginatedFlexibleSearchService
      Type Parameters:
      T - The type of item returned from the search
      Parameters:
      parameter - A parameter object containing all attributes needed for paginated flexible search. The sort info should be only populated in PaginatedFlexibleSearchParameter.searchPageData
      • PaginatedFlexibleSearchParameter.flexibleSearchQuery - The flexible search query containing String query and flexible search query parameters as Map<String, Object>
      • PaginatedFlexibleSearchParameter.searchPageData - The search page data containing requested pagination and sort data
      • PaginatedFlexibleSearchParameter.sortCodeToQueryAlias - The map between sort code and query alias which will be used to dynamically generate "ORDER BY" clause by appending to the given flexible search query based on requested sorts.
      Returns:
      an instance of SearchPageData containing the search results with applied sorts and pagination data
    • validatePaginatedFlexibleSearchParameter

      protected void validatePaginatedFlexibleSearchParameter(PaginatedFlexibleSearchParameter parameter)
      Validates if the given PaginatedFlexibleSearchParameter contains valid parameters.
      Parameters:
      parameter - the PaginatedFlexibleSearchParameter
      Throws:
      IllegalArgumentException - if parameter contains invalid data
    • populateSearchQuery

      protected FlexibleSearchQuery populateSearchQuery(SearchPageData searchPageData, FlexibleSearchQuery searchQuery, Map<String,String> sortCodeToQueryAlias, boolean nextElementAdded)
      Populates a FlexibleSearchQuery based on given searchQuery by appending "ORDER BY" clause if given searchPageData has list of SortData.
      Parameters:
      searchPageData - the searchPageData contains requested pagination and sorting information
      searchQuery - the searchQuery
      sortCodeToQueryAlias - the sortCodeToQueryAlias contains mapping between sort code and query alias which will be used to dynamically generate "ORDER BY" clause.
      nextElementAdded -
      Returns:
      the FlexibleSearchQuery with requested sorts applied
    • filterSearchPageDataSorts

      protected List<SortData> filterSearchPageDataSorts(SearchPageData searchPageData, Map<String,String> sortCodeToQueryAlias)
      Returns a list of SortData where each of it exists from given sortCodeToQueryAlias map. The intention of method is to filter out the undefined sort code from given SearchPageData.getSorts() based on given sortCodeToQueryAlias map, so that once buildSortsAppliedQuery(String, SearchPageData, Map) is called, sortDataParsingStrategy is guaranteed to return the mapped query alias for each sort code.

      It also converts sortData's code to lower case to meet the expectation of SortDataParsingStrategy

      Parameters:
      searchPageData - the searchPageData contains list of SortData which will be used as requested sort list
      sortCodeToQueryAlias - the sortCodeToQueryAlias contains mapping between sort code and query alias which will be used to generate "ORDER BY" clause dynamically based on requested sort codes
      Returns:
      the list of SortData where each of them found from given sortCodeToQueryAlias
      See Also:
    • buildSortsAppliedQuery

      protected String buildSortsAppliedQuery(String query, SearchPageData searchPageData, Map<String,String> sortCodeToQueryAlias)
      Builds a requested sorts applied query based on given query by appending list of SortData passed from given searchPageData. It uses SortDataParsingStrategy to properly generate "ORDER BY {queryAlias:sortCode} asc|desc" search query dynamically based on the requested sorts. If the list of SortData from given searchPageData is empty, the given query will be returned without any modification.
      Parameters:
      query - the query
      searchPageData - the searchPageData contains requested pagination and sorting information
      sortCodeToQueryAlias - the sortCodeToQueryAlias contains mapping between sort code and query alias which will be used to generate "ORDER BY" clause dynamically based on requested sort codes
      Returns:
      a requested sorts applied query
    • createPagedSearchResult

      protected <T> SearchPageData<T> createPagedSearchResult(SearchResult<T> searchResult, SearchPageData searchPageData, DefaultPaginatedFlexibleSearchService.SearchResultInfo searchResultInfo)
      Returns an instance of {link SearchPageData} with given SearchResult. It also contains updated pagination and applied sorts information
      Type Parameters:
      T - the type of item returned from the search
      Parameters:
      searchResult - the searchResult
      searchPageData - the searchPageData containing pagination and sorting information
      searchResultInfo - the search result info needed to properly calculate slicing (hasNext, hasPrevious values)
      Returns:
      an instance of SearchPageData with searchResult, pagination and sorting information
    • createPagination

      protected <T> PaginationData createPagination(SearchPageData searchPageDataInput, DefaultPaginatedFlexibleSearchService.SearchResultInfo searchResultInfo)
      Creates PaginationData based on searchPageDataInput.pagination and calculates the numberOfPages based on the totalNumberOfResults.
      Type Parameters:
      T - the type of item returned from the search
      Parameters:
      searchPageDataInput - the searchPageDataInput contains pagination and sorting information
      searchResultInfo - the search result info needed to properly calculate slicing (hasNext, hasPrevious values)
      Returns:
      PaginationData based on input paginationData and calculated numberOfPages of the given searchResult
    • createSearchPageData

      protected <T> SearchPageData<T> createSearchPageData()
      Returns a new instance of SearchPageData
      Type Parameters:
      T - The type of item returned from the search
      Returns:
      SearchPageData
    • getFlexibleSearchService

      protected FlexibleSearchService getFlexibleSearchService()
    • setFlexibleSearchService

      public void setFlexibleSearchService(FlexibleSearchService flexibleSearchService)
    • getSortDataParsingStrategy

      protected SortDataParsingStrategy getSortDataParsingStrategy()
    • setSortDataParsingStrategy

      public void setSortDataParsingStrategy(SortDataParsingStrategy sortDataParsingStrategy)
    • getAbstractQueryHelper

      protected AbstractQueryHelper getAbstractQueryHelper()
    • setAbstractQueryHelper

      public void setAbstractQueryHelper(AbstractQueryHelper abstractQueryHelper)