Package lumis.doui.search
Class SearchDataProvider
- java.lang.Object
-
- lumis.doui.search.SearchDataProvider
-
- All Implemented Interfaces:
IDataProvider<SearchSource>
@StableMinor(version="14.1", sinceVersion="8.1") public class SearchDataProvider extends Object implements IDataProvider<SearchSource>
Executes a search against a Search Engine and return the results.- Since:
- 4.0.0
- Version:
- $Revision: 24684 $ $Date: 2021-08-23 18:58:35 -0300 (Mon, 23 Aug 2021) $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SearchDataProvider.ParsedUserQuery
Class that holds optional parsed user query and query filter.
-
Field Summary
Fields Modifier and Type Field Description static String
SOURCE_PARAMETER_NAME_AGGREGATED_VALUES
Name of the parameter that holds the aggregated values (user's filters).static String
SOURCE_PARAMETER_NAME_AGGREGATIONS
Name of the parameter that holds the aggregations that should be performed during search.static String
SOURCE_PARAMETER_NAME_CONTROL_QUERY
static String
SOURCE_PARAMETER_NAME_QUERY
static String
SOURCE_PARAMETER_NAME_SCOPE_SERVICE_INSTANCE
static String
SOURCE_PARAMETER_NAME_STATUS
static String
SOURCE_PARAMETER_TARGET_OBJECTS_SOURCE_ID
-
Fields inherited from interface lumis.doui.source.IDataProvider
INTERFACE_INSTANCE_PROPERTY_FIELDS, INTERFACE_INSTANCE_PROPERTY_FILTERS, INTERFACE_INSTANCE_PROPERTY_MAX_ROWS, INTERFACE_INSTANCE_PROPERTY_ORDER_BY, MAX_NUM_ORDER_BY_FIELDS
-
-
Constructor Summary
Constructors Constructor Description SearchDataProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map<DocumentTypeField,Float>
getFieldsBoost(SessionConfig sessionConfig, SearchSource searchSource, ServiceInstanceConfig searchServiceInstanceConfig, ITransaction transaction)
Returns the fields boosts configuration.protected Object
getHighlight(ISearchHit hit, ISourceData row)
Returns the highlight value for the given row.protected HighlightConfig
getHighlightConfiguration()
Returns the highlight configuration.protected String
getMainPublishedContextUrlValue(ISearchHit hit)
Returns the main context URL value that user has access permission.protected Object
getPublications(ISearchHit hit, ISourceData row, SearchSource searchSource)
Returns the publications of the given search hit.protected Collection<String>
getPublishedContextIdsIncludedInSearch(SearchSource searchSource, ServiceInstanceConfig searchServiceInstanceConfig)
Returns the identifiers of the published contexts that should be included in search.protected Set<String>
getSearchFieldIds(SessionConfig sessionConfig, SearchSource searchSource, ITransaction transaction)
Returns the search fields identifiers.protected IMonitor
getSearchMonitor(String userQuery, String unparsedUserQuery, SearchSource searchSource, ITransaction transaction)
Returns themonitor
object to be used in monitoring ornull
if the search will not be monitored.protected ServiceInstanceConfig
getSearchServiceInstance(SessionConfig sessionConfig, SearchSource searchSource, ITransaction transaction)
Returns the search service instance.protected List<SearchQuerySort>
getSearchSorts(SessionConfig sessionConfig, SearchSource searchSource, ServiceInstanceConfig searchServiceInstanceConfig, ITransaction transaction)
Returns the search'ssorts
.protected ISearchQueryFilter
getTargetObjectsSourceFilter(SearchSource source, ITransaction transaction)
Returns the target objects source id filter.protected String
getUserQuery(SessionConfig sessionConfig, SearchSource searchSource, ITransaction transaction)
Returns the user query to be used in search.protected boolean
hasUserQueryChanged(SearchSource searchSource)
Returns whether the user query parameter has changed for the current request.void
loadData(SessionConfig sessionConfig, SearchSource searchSource, ITransaction transaction)
protected SearchDataProvider.ParsedUserQuery
parseUserQuery(String query)
Parse the given user query to generate aparsed version of it
.protected void
populateRow(SessionConfig sessionConfig, ISourceData row, ISearchHit hit, Set<String> fieldIds, SearchSource searchSource, ITransaction transaction)
Populate the given row with the given search hit.protected void
populateRowField(SessionConfig sessionConfig, ISourceData row, ISearchHit hit, String fieldId, SearchSource searchSource, ITransaction transaction)
Populates the given field within the row with the given hit.
-
-
-
Field Detail
-
SOURCE_PARAMETER_NAME_SCOPE_SERVICE_INSTANCE
public static final String SOURCE_PARAMETER_NAME_SCOPE_SERVICE_INSTANCE
- See Also:
- Constant Field Values
-
SOURCE_PARAMETER_NAME_QUERY
public static final String SOURCE_PARAMETER_NAME_QUERY
- See Also:
- Constant Field Values
-
SOURCE_PARAMETER_NAME_AGGREGATIONS
public static final String SOURCE_PARAMETER_NAME_AGGREGATIONS
Name of the parameter that holds the aggregations that should be performed during search.- Since:
- 9.0.0
- See Also:
- Constant Field Values
-
SOURCE_PARAMETER_NAME_AGGREGATED_VALUES
public static final String SOURCE_PARAMETER_NAME_AGGREGATED_VALUES
Name of the parameter that holds the aggregated values (user's filters).- Since:
- 9.0.0
- See Also:
- Constant Field Values
-
SOURCE_PARAMETER_NAME_CONTROL_QUERY
public static final String SOURCE_PARAMETER_NAME_CONTROL_QUERY
- See Also:
- Constant Field Values
-
SOURCE_PARAMETER_NAME_STATUS
public static final String SOURCE_PARAMETER_NAME_STATUS
- See Also:
- Constant Field Values
-
SOURCE_PARAMETER_TARGET_OBJECTS_SOURCE_ID
public static final String SOURCE_PARAMETER_TARGET_OBJECTS_SOURCE_ID
- See Also:
- Constant Field Values
-
-
Method Detail
-
loadData
public void loadData(SessionConfig sessionConfig, SearchSource searchSource, ITransaction transaction) throws PortalException
- Specified by:
loadData
in interfaceIDataProvider<SearchSource>
- Throws:
PortalException
-
getFieldsBoost
protected Map<DocumentTypeField,Float> getFieldsBoost(SessionConfig sessionConfig, SearchSource searchSource, ServiceInstanceConfig searchServiceInstanceConfig, ITransaction transaction) throws PortalException
Returns the fields boosts configuration. May returnnull
if no boosting configuration must be applied.- Parameters:
sessionConfig
- the user's session.searchSource
- the search source.searchServiceInstanceConfig
- the search service instance.transaction
- the transaction.- Returns:
- the fields boosts configuration.
- Throws:
PortalException
- Since:
- 11.1.0
- See Also:
SearchQuery.addFieldBoost(DocumentTypeField, float)
-
hasUserQueryChanged
protected boolean hasUserQueryChanged(SearchSource searchSource)
Returns whether the user query parameter has changed for the current request.- Parameters:
searchSource
- the search source.- Returns:
true
if the user query parameter has changed,false
otherwise.- Since:
- 10.4.0
-
getTargetObjectsSourceFilter
protected ISearchQueryFilter getTargetObjectsSourceFilter(SearchSource source, ITransaction transaction)
Returns the target objects source id filter.
The default implementation will retrieve the source id from source's parameter named with the value of the constantSOURCE_PARAMETER_TARGET_OBJECTS_SOURCE_ID
. This value may be either a full source id (service id + '.' + source id, like 'lumis.service.news.default') or a simple source id (like 'default'). In the case of a simple source id, the source's service id will be retrieved from current request's context.
The default implementation will filter the fields:-
ContentVersionDocumentType.ContentFields.SOURCE_ID
- using the source id. -
StandardDocumentType.StandardFields.CONTEXT_IDS
- using source's service id.
- Parameters:
source
-transaction
-- Returns:
- Since:
- 10.3.0
-
-
getSearchMonitor
protected IMonitor getSearchMonitor(String userQuery, String unparsedUserQuery, SearchSource searchSource, ITransaction transaction) throws PortalException
Returns themonitor
object to be used in monitoring ornull
if the search will not be monitored.- Parameters:
userQuery
- the user query (extracted from unparsed user query).unparsedUserQuery
- the unparsed user query.searchSource
- the search sourcetransaction
- the transaction.- Returns:
- the
monitor
object to be used in monitoring ornull
if the search will not be monitored. - Throws:
PortalException
- Since:
- 10.1.0
-
parseUserQuery
protected SearchDataProvider.ParsedUserQuery parseUserQuery(String query)
Parse the given user query to generate aparsed version of it
. This method must not return null.The default implementation follows the following rules:
-
Creates tag filters (
ContentLocaleFields#TAG_NORMALIZED_NAME
), identifying them by terms starting with#
. The#
char must be followed by aletter
char. All chars after#
char, that are alphanumeric will be identified as a tag filter. The tags filters will be transformed inlower case
. All tags filters will be removed from user query andfilters
to thetag normalized name field
will be created using them. -
The remaining user query will be
trimmed
and multiple spaces will be transformed in a single space char.
For example:
For the user querySeattle Seahawks #nfl #twelves #Love#NFL #"GoHawks"
, the parsed user query would be:- User query
Seattle Seahawks #"GoHawks"
- Tags filters
-
nfl
twelves
love
- Parameters:
query
- the user query.- Returns:
- the parsed user query.
- Since:
- 9.0.0
-
Creates tag filters (
-
getHighlightConfiguration
protected HighlightConfig getHighlightConfiguration()
Returns the highlight configuration.- Returns:
- the highlight configuration.
- Since:
- 8.1.0
-
getPublishedContextIdsIncludedInSearch
protected Collection<String> getPublishedContextIdsIncludedInSearch(SearchSource searchSource, ServiceInstanceConfig searchServiceInstanceConfig) throws PortalException
Returns the identifiers of the published contexts that should be included in search. This method is not supposed to returnnull
. If no published contexts should be included, anempty set
should be returned instead.- Parameters:
searchSource
- the search source.searchServiceInstanceConfig
- the search service instance.- Returns:
- the identifiers of the published contexts that should be included in search.
- Throws:
PortalException
- Since:
- 8.1.0
-
populateRow
protected void populateRow(SessionConfig sessionConfig, ISourceData row, ISearchHit hit, Set<String> fieldIds, SearchSource searchSource, ITransaction transaction) throws PortalException
Populate the given row with the given search hit.- Parameters:
sessionConfig
- the user's session.row
- the row to be populated.hit
- the search hit.fieldIds
- the source fields identifiers.searchSource
- the source.transaction
- the transaction.- Throws:
PortalException
- Since:
- 8.1.0
-
getHighlight
protected Object getHighlight(ISearchHit hit, ISourceData row)
Returns the highlight value for the given row.- Parameters:
hit
- the search hit.row
- the row.- Returns:
- the highlight value for the given row.
- Since:
- 8.1.0
-
getPublications
protected Object getPublications(ISearchHit hit, ISourceData row, SearchSource searchSource) throws PortalException
Returns the publications of the given search hit.- Parameters:
hit
- the search hit.row
- the row being processed.searchSource
- the search source.- Returns:
- the publications of the given search hit.
- Throws:
PortalException
- Since:
- 8.1.0
-
populateRowField
protected void populateRowField(SessionConfig sessionConfig, ISourceData row, ISearchHit hit, String fieldId, SearchSource searchSource, ITransaction transaction) throws PortalException
Populates the given field within the row with the given hit.- Parameters:
sessionConfig
- the user's session.row
- the row to be populated.hit
- the search hit.fieldId
- the identifier of the field currently being populated.searchSource
- the search source.transaction
- the transaction.- Throws:
PortalException
- Since:
- 8.1.0
-
getMainPublishedContextUrlValue
protected String getMainPublishedContextUrlValue(ISearchHit hit) throws PortalException
Returns the main context URL value that user has access permission.- Parameters:
hit
- the search hit.- Returns:
- the main context URL value that user has access permission.
- Throws:
PortalException
- Since:
- 8.1.0
-
getSearchSorts
protected List<SearchQuerySort> getSearchSorts(SessionConfig sessionConfig, SearchSource searchSource, ServiceInstanceConfig searchServiceInstanceConfig, ITransaction transaction)
Returns the search'ssorts
. This method is not supposed to returnnull
. If no sort is to be applied in search, anempty list
should be returned instead.- Parameters:
sessionConfig
- the user's session.searchSource
- the search source.searchServiceInstanceConfig
- the search service instance.transaction
- the transaction.- Returns:
- the search's
sorts
- Since:
- 8.1.0
- See Also:
SearchQuerySort
,SearchQuery#addSort(SearchQuerySort)
-
getUserQuery
protected String getUserQuery(SessionConfig sessionConfig, SearchSource searchSource, ITransaction transaction)
Returns the user query to be used in search. If no user query was provided,null
should be returned.- Parameters:
sessionConfig
- the user's session.searchSource
- the search source.transaction
- the transaction.- Returns:
- the user query to be used in search.
- Since:
- 8.1.0
- See Also:
SearchQuery.setUserQuery(String)
-
getSearchFieldIds
protected Set<String> getSearchFieldIds(SessionConfig sessionConfig, SearchSource searchSource, ITransaction transaction)
Returns the search fields identifiers. The default behavior is to get the source'sfields
identifiers
.- Parameters:
sessionConfig
- the user's session.searchSource
- the search source.transaction
- the transaction.- Returns:
- the search fields identifiers.
- Since:
- 8.1.0
-
getSearchServiceInstance
protected ServiceInstanceConfig getSearchServiceInstance(SessionConfig sessionConfig, SearchSource searchSource, ITransaction transaction) throws PortalException
Returns the search service instance. This method is not supposed to returnnull
.- Parameters:
sessionConfig
- the user's session.searchSource
- the search source.transaction
- the transaction.- Returns:
- the search service instance.
- Throws:
PortalException
- Since:
- 8.1.0
-
-