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-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringbuildSortsAppliedQuery(String query, SearchPageData searchPageData, Map<String, String> sortCodeToQueryAlias) Builds a requested sorts applied query based on given query by appending list ofSortDatapassed from given searchPageData.protected <T> SearchPageData<T>createPagedSearchResult(SearchResult<T> searchResult, SearchPageData searchPageData, DefaultPaginatedFlexibleSearchService.SearchResultInfo searchResultInfo) Returns an instance of {link SearchPageData} with givenSearchResult.protected <T> PaginationDatacreatePagination(SearchPageData searchPageDataInput, DefaultPaginatedFlexibleSearchService.SearchResultInfo searchResultInfo) CreatesPaginationDatabased on searchPageDataInput.pagination and calculates the numberOfPages based on the totalNumberOfResults.protected <T> SearchPageData<T>Returns a new instance ofSearchPageDatafilterSearchPageDataSorts(SearchPageData searchPageData, Map<String, String> sortCodeToQueryAlias) Returns a list ofSortDatawhere each of it exists from given sortCodeToQueryAlias map.protected AbstractQueryHelperprotected FlexibleSearchServiceprotected SortDataParsingStrategyprotected FlexibleSearchQuerypopulateSearchQuery(SearchPageData searchPageData, FlexibleSearchQuery searchQuery, Map<String, String> sortCodeToQueryAlias, boolean nextElementAdded) Populates aFlexibleSearchQuerybased on given searchQuery by appending "ORDER BY" clause if given searchPageData has list ofSortData.<T> SearchPageData<T>search(PaginatedFlexibleSearchParameter parameter) Searches according toPaginatedFlexibleSearchParameter.voidsetAbstractQueryHelper(AbstractQueryHelper abstractQueryHelper) voidsetFlexibleSearchService(FlexibleSearchService flexibleSearchService) voidsetSortDataParsingStrategy(SortDataParsingStrategy sortDataParsingStrategy) protected voidValidates if the givenPaginatedFlexibleSearchParametercontains valid parameters.
-
Constructor Details
-
DefaultPaginatedFlexibleSearchService
public DefaultPaginatedFlexibleSearchService()
-
-
Method Details
-
search
Description copied from interface:PaginatedFlexibleSearchServiceSearches according toPaginatedFlexibleSearchParameter.- Specified by:
searchin interfacePaginatedFlexibleSearchService- 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 inPaginatedFlexibleSearchParameter.searchPageDataPaginatedFlexibleSearchParameter.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 dataPaginatedFlexibleSearchParameter.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
SearchPageDatacontaining the search results with applied sorts and pagination data
-
validatePaginatedFlexibleSearchParameter
Validates if the givenPaginatedFlexibleSearchParametercontains 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 aFlexibleSearchQuerybased on given searchQuery by appending "ORDER BY" clause if given searchPageData has list ofSortData.- Parameters:
searchPageData- the searchPageData contains requested pagination and sorting informationsearchQuery- the searchQuerysortCodeToQueryAlias- the sortCodeToQueryAlias contains mapping between sort code and query alias which will be used to dynamically generate "ORDER BY" clause.nextElementAdded-- Returns:
- the
FlexibleSearchQuerywith requested sorts applied
-
filterSearchPageDataSorts
protected List<SortData> filterSearchPageDataSorts(SearchPageData searchPageData, Map<String, String> sortCodeToQueryAlias) Returns a list ofSortDatawhere each of it exists from given sortCodeToQueryAlias map. The intention of method is to filter out the undefined sort code from givenSearchPageData.getSorts()based on given sortCodeToQueryAlias map, so that oncebuildSortsAppliedQuery(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 ofSortDatawhich will be used as requested sort listsortCodeToQueryAlias- 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
SortDatawhere 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 ofSortDatapassed from given searchPageData. It usesSortDataParsingStrategyto properly generate "ORDER BY {queryAlias:sortCode} asc|desc" search query dynamically based on the requested sorts. If the list ofSortDatafrom given searchPageData is empty, the given query will be returned without any modification.- Parameters:
query- the querysearchPageData- the searchPageData contains requested pagination and sorting informationsortCodeToQueryAlias- 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 givenSearchResult. It also contains updated pagination and applied sorts information- Type Parameters:
T- the type of item returned from the search- Parameters:
searchResult- the searchResultsearchPageData- the searchPageData containing pagination and sorting informationsearchResultInfo- the search result info needed to properly calculate slicing (hasNext, hasPrevious values)- Returns:
- an instance of
SearchPageDatawith searchResult, pagination and sorting information
-
createPagination
protected <T> PaginationData createPagination(SearchPageData searchPageDataInput, DefaultPaginatedFlexibleSearchService.SearchResultInfo searchResultInfo) CreatesPaginationDatabased 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 informationsearchResultInfo- 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
Returns a new instance ofSearchPageData- Type Parameters:
T- The type of item returned from the search- Returns:
SearchPageData
-
getFlexibleSearchService
-
setFlexibleSearchService
-
getSortDataParsingStrategy
-
setSortDataParsingStrategy
-
getAbstractQueryHelper
-
setAbstractQueryHelper
-