Package org.ametys.cms.search
Class QueryBuilder
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.cms.search.QueryBuilder
-
- All Implemented Interfaces:
Component
,LogEnabled
,Serviceable
public class QueryBuilder extends AbstractLogEnabled implements Component, Serviceable
Builds aQuery
object from a user search.
-
-
Field Summary
Fields Modifier and Type Field Description protected AdvancedQueryBuilder
_advancedQueryBuilder
The advanced query builderprotected TreeMaker
_advancedTreeMaker
The Advanced tree makerprotected ContentTypeExtensionPoint
_cTypeEP
The content type extension point.protected LanguagesManager
_languagesManager
The languages managerstatic String
DEFAULT_LANGUAGE
The query default language.static String
MULTILINGUAL_SEARCH
Key of flag present in contextual parameters to indicate the current search is multilingualstatic String
ROLE
The component role.static String
SEARCH_CRITERIA_METADATA_PREFIX
Prefix for id of metadata search criteriastatic String
SEARCH_CRITERIA_SYSTEM_PREFIX
Prefix for id of system property search criteriastatic String
VALUE_IS_ESCAPED
Key of flag present in contextual parameters to indicate the provided value was already escaped
-
Constructor Summary
Constructors Constructor Description QueryBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Query
build(SearchUIModel model, String searchMode, boolean createContentTypeQuery, Map<String,Object> values, Map<String,Object> contextualParameters)
Build theQuery
object.Query
createContentTypeOrMixinQuery(Set<String> modelContentTypes, Object cTypeOrMixinParam, boolean criterionIsMultiple)
Create a content type or mixin query.protected Query
createContentTypeOrMixinQuery(Set<String> modelContentTypes, Map<String,Object> values, Map<String,SearchCriterion> criteria, String searchMode)
Create a content type or mixin query.protected Query
createContentTypeQuery(Set<String> modelContentTypes, Map<String,Object> values, Map<String,SearchCriterion> criteria, String searchMode)
Create a content type query.protected Query
createMixinTypeQuery(Set<String> mixinTypes, Map<String,Object> values, Map<String,SearchCriterion> criteria, String searchMode)
Create a mixin type query.protected Query
getAdvancedCriteriaQuery(Map<String,SearchCriterion> criteria, Map<String,Object> values, String language, Map<String,Object> contextualParameters)
Get a complex Query from the advanced search values.String
getCriteriaLanguage(Map<String,SearchUICriterion> criteria, String searchMode, Map<String,Object> values, Map<String,Object> contextualParameters)
Get the language.protected List<Query>
getCriteriaQueries(Map<String,SearchUICriterion> criteria, Map<String,Object> values, String language, Map<String,Object> contextualParameters)
Get the list of query on criteria.protected String
getDefaultLanguage()
Get the default language for searchvoid
service(ServiceManager serviceManager)
-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
SEARCH_CRITERIA_METADATA_PREFIX
public static final String SEARCH_CRITERIA_METADATA_PREFIX
Prefix for id of metadata search criteria- See Also:
- Constant Field Values
-
SEARCH_CRITERIA_SYSTEM_PREFIX
public static final String SEARCH_CRITERIA_SYSTEM_PREFIX
Prefix for id of system property search criteria- See Also:
- Constant Field Values
-
MULTILINGUAL_SEARCH
public static final String MULTILINGUAL_SEARCH
Key of flag present in contextual parameters to indicate the current search is multilingual- See Also:
- Constant Field Values
-
VALUE_IS_ESCAPED
public static final String VALUE_IS_ESCAPED
Key of flag present in contextual parameters to indicate the provided value was already escaped- See Also:
- Constant Field Values
-
DEFAULT_LANGUAGE
public static final String DEFAULT_LANGUAGE
The query default language.- See Also:
- Constant Field Values
-
_cTypeEP
protected ContentTypeExtensionPoint _cTypeEP
The content type extension point.
-
_languagesManager
protected LanguagesManager _languagesManager
The languages manager
-
_advancedTreeMaker
protected TreeMaker _advancedTreeMaker
The Advanced tree maker
-
_advancedQueryBuilder
protected AdvancedQueryBuilder _advancedQueryBuilder
The advanced query builder
-
-
Constructor Detail
-
QueryBuilder
public QueryBuilder()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
build
public Query build(SearchUIModel model, String searchMode, boolean createContentTypeQuery, Map<String,Object> values, Map<String,Object> contextualParameters)
Build theQuery
object.- Parameters:
model
- the search model.searchMode
- the search mode.createContentTypeQuery
- True to generate a query based on the content types of the model, and the 'property-contentTypes-eq' if present in valuesvalues
- the user search values.contextualParameters
- the search contextual parameters.- Returns:
- a
Query
object representing the search.
-
getCriteriaLanguage
public String getCriteriaLanguage(Map<String,SearchUICriterion> criteria, String searchMode, Map<String,Object> values, Map<String,Object> contextualParameters)
Get the language.- Parameters:
criteria
- the list of search criteriasearchMode
- The search mode (advanced or simple)values
- The user values.contextualParameters
- The search contextual parameters.- Returns:
- the query language.
-
getDefaultLanguage
protected String getDefaultLanguage()
Get the default language for search- Returns:
- The default language
-
createContentTypeQuery
protected Query createContentTypeQuery(Set<String> modelContentTypes, Map<String,Object> values, Map<String,SearchCriterion> criteria, String searchMode)
Create a content type query.- Parameters:
modelContentTypes
- the content types to search on.values
- the user search values.criteria
- the list of search criteriasearchMode
- The search mode (advanced or simple)- Returns:
- the content type
Query
.
-
createMixinTypeQuery
protected Query createMixinTypeQuery(Set<String> mixinTypes, Map<String,Object> values, Map<String,SearchCriterion> criteria, String searchMode)
Create a mixin type query.- Parameters:
mixinTypes
- the mixin types to search on.values
- the user search values.criteria
- the list of search criteriasearchMode
- The search mode (advanced or simple)- Returns:
- the mixin type
Query
.
-
createContentTypeOrMixinQuery
protected Query createContentTypeOrMixinQuery(Set<String> modelContentTypes, Map<String,Object> values, Map<String,SearchCriterion> criteria, String searchMode)
Create a content type or mixin query.- Parameters:
modelContentTypes
- the content types or mixins to search on.values
- the user search values.criteria
- the list of search criteriasearchMode
- The search mode (advanced or simple)- Returns:
- the content type
Query
.
-
createContentTypeOrMixinQuery
public Query createContentTypeOrMixinQuery(Set<String> modelContentTypes, Object cTypeOrMixinParam, boolean criterionIsMultiple)
Create a content type or mixin query.- Parameters:
modelContentTypes
- the content types or mixins to search on.cTypeOrMixinParam
- The contentTypes or mixin parameter on which you want to build the QuerycriterionIsMultiple
-true
if the given parameter is a value for a multiple criterion- Returns:
- the content type
Query
.
-
getCriteriaQueries
protected List<Query> getCriteriaQueries(Map<String,SearchUICriterion> criteria, Map<String,Object> values, String language, Map<String,Object> contextualParameters)
Get the list of query on criteria.- Parameters:
criteria
- the list of search criteriavalues
- The submitted valueslanguage
- The query language.contextualParameters
- The contextual parameters- Returns:
- The criteria
Query
.
-
getAdvancedCriteriaQuery
protected Query getAdvancedCriteriaQuery(Map<String,SearchCriterion> criteria, Map<String,Object> values, String language, Map<String,Object> contextualParameters)
Get a complex Query from the advanced search values.- Parameters:
criteria
- the list of search criteriavalues
- The submitted valueslanguage
- The query language.contextualParameters
- The contextual parameters- Returns:
- The criteria
Query
.
-
-