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 aQueryobject from a user search.
-
-
Field Summary
Fields Modifier and Type Field Description protected AdvancedQueryBuilder_advancedQueryBuilderThe advanced query builderprotected TreeMaker_advancedTreeMakerThe Advanced tree makerprotected ContentTypeExtensionPoint_cTypeEPThe content type extension point.protected LanguagesManager_languagesManagerThe languages managerstatic StringDEFAULT_LANGUAGEThe query default language.static StringMULTILINGUAL_SEARCHKey of flag present in contextual parameters to indicate the current search is multilingualstatic StringROLEThe component role.static StringSEARCH_CRITERIA_METADATA_PREFIXPrefix for id of metadata search criteriastatic StringSEARCH_CRITERIA_SYSTEM_PREFIXPrefix for id of system property search criteriastatic StringVALUE_IS_ESCAPEDKey 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 Querybuild(SearchUIModel model, String searchMode, boolean createContentTypeQuery, Map<String,Object> values, Map<String,Object> contextualParameters)Build theQueryobject.QuerycreateContentTypeOrMixinQuery(Set<String> modelContentTypes, Object cTypeOrMixinParam, boolean criterionIsMultiple)Create a content type or mixin query.protected QuerycreateContentTypeOrMixinQuery(Set<String> modelContentTypes, Map<String,Object> values, Map<String,SearchCriterion> criteria, String searchMode)Create a content type or mixin query.protected QuerycreateContentTypeQuery(Set<String> modelContentTypes, Map<String,Object> values, Map<String,SearchCriterion> criteria, String searchMode)Create a content type query.protected QuerycreateMixinTypeQuery(Set<String> mixinTypes, Map<String,Object> values, Map<String,SearchCriterion> criteria, String searchMode)Create a mixin type query.protected QuerygetAdvancedCriteriaQuery(Map<String,SearchCriterion> criteria, Map<String,Object> values, String language, Map<String,Object> contextualParameters)Get a complex Query from the advanced search values.StringgetCriteriaLanguage(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 StringgetDefaultLanguage()Get the default language for searchvoidservice(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:
servicein interfaceServiceable- Throws:
ServiceException
-
build
public Query build(SearchUIModel model, String searchMode, boolean createContentTypeQuery, Map<String,Object> values, Map<String,Object> contextualParameters)
Build theQueryobject.- 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
Queryobject 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-trueif 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.
-
-