Class SolrSearchServiceImpl
- All Implemented Interfaces:
SearchService,org.springframework.beans.factory.DisposableBean
Note that prior to 2.2.0, this class used to contain all of the logic for interaction with Solr. Since 2.2.0, this class has been refactored and parts of it have been split into the other classes you can find in this package.
- Author:
- Andre Azzolini (apazzolini)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected SolrSearchServiceExtensionManagerprotected FieldDaoprotected booleanprotected IndexFieldDaoprotected ProductDaoprotected SearchFacetDaoprotected booleanprotected SolrHelperServiceprotected SkuDaoprotected SolrConfigurationprotected org.apache.solr.client.solrj.SolrRequest.METHOD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidattachActiveFacetFilters(org.apache.solr.client.solrj.SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap, SearchCriteria searchCriteria) Restricts the query by adding active facet filters.protected voidattachFacets(org.apache.solr.client.solrj.SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap, SearchCriteria searchCriteria) Notifies solr about which facets you want it to determine results and counts forprotected voidattachSortClause(org.apache.solr.client.solrj.SolrQuery query, SearchCriteria searchCriteria, String defaultSort) Sets up the sorting criteria.protected StringbuildQueryFieldsString(org.apache.solr.client.solrj.SolrQuery query, SearchCriteria searchCriteria) protected List<SearchFacetDTO>buildSearchFacetDTOs(List<SearchFacet> searchFacets) Create the wrapper DTO around the SearchFacetprotected SearchContextDTOvoiddestroy()protected booleanfacetIsAvailable(SearchFacet facet, Map<String, String[]> params) Checks to see if the requiredFacets condition for a given facet is met.protected voidfilterEmptyFacets(List<SearchFacetDTO> facets) protected voidfilterProductsBasedOnInactiveCategory(List<Product> products, Category category) findExplicitSearchResultsByCategory(Category category, SearchCriteria searchCriteria) Performs a search for search results in the given category, taking into consideration the SearchCriteriaprotected SearchResultfindSearchResults(String qualifiedSolrQuery, List<SearchFacetDTO> facets, SearchCriteria searchCriteria, String defaultSort) Deprecated, for removal: This API element is subject to removal in a future version.in favor of the other findSearchResults() methodprotected SearchResultfindSearchResults(String qualifiedSolrQuery, List<SearchFacetDTO> facets, SearchCriteria searchCriteria, String defaultSort, String... filterQueries) Given a qualified solr query string (such as "category:2002"), actually performs a solr search.findSearchResults(SearchCriteria searchCriteria) Performs a search for search results based on the given SearchCriteria, if SearchCriteria has a category, the category is considering for the search.findSearchResultsByCategory(Category category, SearchCriteria searchCriteria) Deprecated.findSearchResultsByCategoryAndQuery(Category category, String query, SearchCriteria searchCriteria) Deprecated.findSearchResultsByQuery(String query, SearchCriteria searchCriteria) Deprecated.getCategoryFacets(Category category) Gets all available facets for a given categoryprotected StringgetCategoryFilter(SearchCriteria searchCriteria) protected StringgetDefaultSort(SearchCriteria criteria) protected Map<String,SearchFacetDTO> getNamedFacetMap(List<SearchFacetDTO> facets, SearchCriteria searchCriteria) getProducts(List<org.apache.solr.common.SolrDocument> responseDocuments) Given a list of product IDs from solr, this method will look up the IDs via the productDao and build out actual Product instances.protected voidgetQueryFields(org.apache.solr.client.solrj.SolrQuery query, List<String> queryFields, IndexField indexField, SearchCriteria searchCriteria) This helper method gathers the query fields for the given field and stores them in the List parameter.protected List<org.apache.solr.common.SolrDocument>getResponseDocuments(org.apache.solr.client.solrj.response.QueryResponse response) Gets all available facets for search results pagegetSearchFacets(Category category) Gets all available facets for the given category and global searchprotected StringgetSolrFieldTag(String tagField, String tag, SearchFacetRange range) Returns a solr field tag.protected org.apache.solr.client.solrj.SolrRequest.METHODAllows the user to choose the query method to use.protected StringgetSolrRangeFunctionString(BigDecimal minValue, BigDecimal maxValue) protected StringgetSolrRangeString(String fieldName, BigDecimal minValue, BigDecimal maxValue) protected StringgetSolrTaggedFieldString(String indexField, String tag, SearchFacetRange range) Returns a fully composed solr field string.booleanisActive()Determines whether or not the necessary configuration is in placeprotected voidmodifySolrQuery(org.apache.solr.client.solrj.SolrQuery query, String qualifiedSolrQuery, List<SearchFacetDTO> facets, SearchCriteria searchCriteria, String defaultSort) Provides a hook point for implementations to modify all SolrQueries before they're executed.protected StringsanitizeQuery(String query) Perform any necessary query sanitation here.protected StringscrubFacetValue(String facetValue) Scrubs a facet value string for all Solr special characters, automatically adding escape charactersprotected voidsetFacetResults(Map<String, SearchFacetDTO> namedFacetMap, org.apache.solr.client.solrj.response.QueryResponse response) Builds out the DTOs for facet results from the search.voidsetPagingAttributes(SearchResult result, int numResults, SearchCriteria searchCriteria) Sets the total results, the current page, and the page size on the ProductSearchResult.protected booleanprotected voidsortFacetResults(Map<String, SearchFacetDTO> namedFacetMap) Invoked to sort the facet results.
-
Field Details
-
solrConfiguration
@Qualifier("blCatalogSolrConfiguration") @Autowired(required=false) protected SolrConfiguration solrConfiguration -
productDao
-
skuDao
-
fieldDao
-
searchFacetDao
-
shs
-
indexFieldDao
-
extensionManager
-
globalFacetsForCategorySearch
@Value("${solr.global.facets.category.search:false}") protected boolean globalFacetsForCategorySearch -
boostSearchResultsCategory
@Value("${solr.boost.category.results:false}") protected boolean boostSearchResultsCategory -
shouldShowDebugQuery
@Value("${solr.showDebugQuery:false}") protected boolean shouldShowDebugQuery -
solrSearchMethod
@Value("${solr.search.method:POST}") protected org.apache.solr.client.solrj.SolrRequest.METHOD solrSearchMethod
-
-
Constructor Details
-
SolrSearchServiceImpl
public SolrSearchServiceImpl()
-
-
Method Details
-
shouldShowDebugQuery
protected boolean shouldShowDebugQuery()- Returns:
- whether or not to enable debug query info for the SolrQuery
-
findExplicitSearchResultsByCategory
public SearchResult findExplicitSearchResultsByCategory(Category category, SearchCriteria searchCriteria) throws ServiceException Description copied from interface:SearchServicePerforms a search for search results in the given category, taking into consideration the SearchCriteriaThis method will NOT return search results that are in a sub-level of a given category. For example, if you had a "Routers" category and a "Enterprise Routers" sub-category, asking for search results in "Routers", would NOT return search results that are in the "Enterprise Routers" category.
- Specified by:
findExplicitSearchResultsByCategoryin interfaceSearchService- Returns:
- Throws:
ServiceException- See Also:
-
findSearchResultsByCategory
@Deprecated public SearchResult findSearchResultsByCategory(Category category, SearchCriteria searchCriteria) throws ServiceException Deprecated.Description copied from interface:SearchServicePerforms a search for search results in the given category, taking into consideration the SearchCriteriaThis method will return search results that are in any sub-level of a given category. For example, if you had a "Routers" category and a "Enterprise Routers" sub-category, asking for search results in "Routers", would return search results that are in the "Enterprise Routers" category.
- Specified by:
findSearchResultsByCategoryin interfaceSearchService- Returns:
- the result of the search
- Throws:
ServiceException- See Also:
-
findSearchResultsByQuery
@Deprecated public SearchResult findSearchResultsByQuery(String query, SearchCriteria searchCriteria) throws ServiceException Deprecated.Description copied from interface:SearchServicePerforms a search for search results across all categories for the given query, taking into consideration the SearchCriteria- Specified by:
findSearchResultsByQueryin interfaceSearchService- Returns:
- the result of the search
- Throws:
ServiceException
-
findSearchResultsByCategoryAndQuery
@Deprecated public SearchResult findSearchResultsByCategoryAndQuery(Category category, String query, SearchCriteria searchCriteria) throws ServiceException Deprecated.Description copied from interface:SearchServicePerforms a search for search results in the given category for the given query, taking into consideration the SearchCriteria- Specified by:
findSearchResultsByCategoryAndQueryin interfaceSearchService- Throws:
ServiceException
-
findSearchResults
Description copied from interface:SearchServicePerforms a search for search results based on the given SearchCriteria, if SearchCriteria has a category, the category is considering for the search.- Specified by:
findSearchResultsin interfaceSearchService- Parameters:
searchCriteria- contains the information about this given search- Returns:
- the SearchResult
- Throws:
ServiceException
-
findSearchResults
@Deprecated(forRemoval=true) protected SearchResult findSearchResults(String qualifiedSolrQuery, List<SearchFacetDTO> facets, SearchCriteria searchCriteria, String defaultSort) throws ServiceException Deprecated, for removal: This API element is subject to removal in a future version.in favor of the other findSearchResults() method- Throws:
ServiceException
-
findSearchResults
protected SearchResult findSearchResults(String qualifiedSolrQuery, List<SearchFacetDTO> facets, SearchCriteria searchCriteria, String defaultSort, String... filterQueries) throws ServiceException Given a qualified solr query string (such as "category:2002"), actually performs a solr search. It will take into considering the search criteria to build out facets / pagination / sorting.- Parameters:
searchCriteria-facets-- Returns:
- the ProductSearchResult of the search
- Throws:
ServiceException
-
filterProductsBasedOnInactiveCategory
-
filterEmptyFacets
-
getDefaultSort
-
getCategoryFilter
-
getLocalePrefix
-
buildQueryFieldsString
protected String buildQueryFieldsString(org.apache.solr.client.solrj.SolrQuery query, SearchCriteria searchCriteria) -
getQueryFields
protected void getQueryFields(org.apache.solr.client.solrj.SolrQuery query, List<String> queryFields, IndexField indexField, SearchCriteria searchCriteria) This helper method gathers the query fields for the given field and stores them in the List parameter.- Parameters:
query-queryFields- the query fields for this queryindexField-searchCriteria-
-
modifySolrQuery
protected void modifySolrQuery(org.apache.solr.client.solrj.SolrQuery query, String qualifiedSolrQuery, List<SearchFacetDTO> facets, SearchCriteria searchCriteria, String defaultSort) Provides a hook point for implementations to modify all SolrQueries before they're executed. Modules should leverage the extension manager method of the same name,SolrSearchServiceExtensionHandler.modifySolrQuery(SolrQuery, String, List, SearchCriteria, String)- Parameters:
query-qualifiedSolrQuery-facets-searchCriteria-defaultSort-
-
createSearchContextDTO
-
getResponseDocuments
protected List<org.apache.solr.common.SolrDocument> getResponseDocuments(org.apache.solr.client.solrj.response.QueryResponse response) -
getSearchFacets
Description copied from interface:SearchServiceGets all available facets for search results page- Specified by:
getSearchFacetsin interfaceSearchService- Returns:
- the available facets
-
getSearchFacets
Description copied from interface:SearchServiceGets all available facets for the given category and global search- Specified by:
getSearchFacetsin interfaceSearchService- Returns:
-
getCategoryFacets
Description copied from interface:SearchServiceGets all available facets for a given category- Specified by:
getCategoryFacetsin interfaceSearchService- Returns:
- the available facets
-
attachSortClause
protected void attachSortClause(org.apache.solr.client.solrj.SolrQuery query, SearchCriteria searchCriteria, String defaultSort) Sets up the sorting criteria. This will support sorting by multiple fields at a time- Parameters:
query-searchCriteria-
-
attachActiveFacetFilters
protected void attachActiveFacetFilters(org.apache.solr.client.solrj.SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap, SearchCriteria searchCriteria) Restricts the query by adding active facet filters.- Parameters:
query-namedFacetMap-searchCriteria-
-
scrubFacetValue
Scrubs a facet value string for all Solr special characters, automatically adding escape characters- Parameters:
facetValue- The raw facet value- Returns:
- The facet value with all special characters properly escaped, safe to be used in construction of a Solr query
-
attachFacets
protected void attachFacets(org.apache.solr.client.solrj.SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap, SearchCriteria searchCriteria) Notifies solr about which facets you want it to determine results and counts for- Parameters:
query-namedFacetMap-searchCriteria-
-
setFacetResults
protected void setFacetResults(Map<String, SearchFacetDTO> namedFacetMap, org.apache.solr.client.solrj.response.QueryResponse response) Builds out the DTOs for facet results from the search. This will then be used by the view layer to display which values are available given the current constraints as well as the count of the values.- Parameters:
namedFacetMap-response-
-
sortFacetResults
Invoked to sort the facet results. This method will use the natural sorting of the value attribute of the facet (or, if value is null, the minValue of the facet result). Override this method to customize facet sorting for your given needs.- Parameters:
namedFacetMap-
-
setPagingAttributes
Sets the total results, the current page, and the page size on the ProductSearchResult. Total results comes from solr, while page and page size are duplicates of the searchCriteria conditions for ease of use.- Parameters:
result-numResults-searchCriteria-
-
getProducts
Given a list of product IDs from solr, this method will look up the IDs via the productDao and build out actual Product instances. It will return a Products that is sorted by the order of the IDs in the passed in list.- Parameters:
responseDocuments-- Returns:
- the actual Product instances as a result of the search
-
buildSearchFacetDTOs
Create the wrapper DTO around the SearchFacet- Parameters:
searchFacets-- Returns:
- the wrapper DTO
-
facetIsAvailable
Checks to see if the requiredFacets condition for a given facet is met.- Parameters:
facet-params-- Returns:
- whether or not the facet parameter is available
-
sanitizeQuery
Perform any necessary query sanitation here. For example, we disallow open and close parentheses, colons, and we also ensure that quotes are actual quotes (") and not the URL encoding (") so that Solr is able to properly handle the user's intent.- Parameters:
query-- Returns:
- the sanitized query
-
getSolrTaggedFieldString
Returns a fully composed solr field string. Given indexField = a, tag = ex, and a non-null range, would produce the following String: {!tag=a frange incl=false l=minVal u=maxVal}a -
getSolrFieldTag
Returns a solr field tag. Given indexField = a, tag = tag, would produce the following String: {!tag=a}. if range is not null it will produce {!tag=a frange incl=false l=minVal u=maxVal} -
getSolrRangeString
-
getSolrRangeFunctionString
- Parameters:
minValue-maxValue-- Returns:
- a string representing a call to the frange solr function. it is not inclusive of lower limit, inclusive of upper limit
-
getNamedFacetMap
protected Map<String,SearchFacetDTO> getNamedFacetMap(List<SearchFacetDTO> facets, SearchCriteria searchCriteria) - Parameters:
facets-searchCriteria-- Returns:
- a map of fully qualified solr index field key to the searchFacetDTO object
-
getSolrQueryMethod
protected org.apache.solr.client.solrj.SolrRequest.METHOD getSolrQueryMethod()Allows the user to choose the query method to use. POST allows for longer, more complex queries with a higher number of facets.Default value is POST. Implementors can change the value by setting the solr.search.method property
- Returns:
-
destroy
- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Throws:
Exception
-
isActive
public boolean isActive()Description copied from interface:SearchServiceDetermines whether or not the necessary configuration is in place- Specified by:
isActivein interfaceSearchService- Returns:
- whether or not the necessary configuration is in place
-