Package org.ametys.web.frontoffice
Class AbstractSearchGenerator
java.lang.Object
org.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.cocoon.xml.AbstractXMLProducer
org.apache.cocoon.generation.AbstractGenerator
org.apache.cocoon.generation.ServiceableGenerator
org.ametys.web.frontoffice.AbstractSearchGenerator
- All Implemented Interfaces:
SolrFieldNames,SolrWebFieldNames,Poolable,Recyclable,Disposable,Component,Contextualizable,LogEnabled,Serviceable,Generator,SitemapModelComponent,XMLProducer
- Direct Known Subclasses:
SearchGenerator,SearchResourcesGenerator
public abstract class AbstractSearchGenerator
extends ServiceableGenerator
implements Contextualizable, SolrWebFieldNames
Abstract class for solr search
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classFacet field for an attributeprotected classFacet field for content typesprotected static interfaceInterface representing a facet field -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ContentTypesHelperThe helper to handler content typesprotected ContextThe cocoon contextprotected ContentTypeExtensionPointTheContentTypemanagerprotected AmetysObjectResolverThe Ametys resolverprotected FrontOfficeSearcherFactoryThe searcher factoryprotected ContentSearchHelperThe content searcherprotected SiteManagerThe sites managerprotected TagProviderExtensionPointThe tag extension pointprotected static final PatternTextfield patternprotected URIResolverExtensionPointThe uri resolver extension pointstatic final StringThe name of the facet.query testing the pageResourcesFields inherited from class org.apache.cocoon.generation.ServiceableGenerator
managerFields inherited from class org.apache.cocoon.generation.AbstractGenerator
objectModel, parameters, resolver, sourceFields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumerFields inherited from interface org.ametys.cms.content.indexing.solr.SolrFieldNames
ACL_INIT_VALUE_ALLOWED_GROUPS, ACL_INIT_VALUE_ALLOWED_USERS, ACL_INIT_VALUE_ANONYMOUS, ACL_INIT_VALUE_ANYCONNECTED, ACL_INIT_VALUE_DENIED_GROUPS, ACL_INIT_VALUE_DENIED_USERS, ALL_CONTENT_TYPES, ALL_MIXIN_TYPES, ALL_TAGS, ATTACHMENT_CONTENT_ID, CONTENT_COMMENTS_NONVALIDATED, CONTENT_COMMENTS_VALIDATED, CONTENT_CREATOR, CONTENT_FIRST_VALIDATOR, CONTENT_LANGUAGE, CONTENT_LANGUAGES, CONTENT_LAST_CONTRIBUTOR, CONTENT_LAST_MAJOR_VALIDATOR, CONTENT_LAST_VALIDATOR, CONTENT_NAME, CONTENT_OUTGOING_REFEERENCES_RESOURCE_IDS, CONTENT_TITLES, CONTENT_TYPE_RESOURCE, CONTENT_TYPES, CONTENT_VISIBLE_ATTACHMENT_RESOURCE_IDS, CREATION_DATE, DC_CONTRIBUTOR, DC_COVERAGE, DC_CREATOR, DC_DATE, DC_DESCRIPTION, DC_FORMAT, DC_IDENTIFIER, DC_LANGUAGE, DC_PUBLISHER, DC_RELATION, DC_RIGHTS, DC_SOURCE, DC_SUBJECT, DC_TITLE, DC_TYPE, DOCUMENT_TYPE, EXACT_WS_OPERATOR, EXCERPT, FILENAME, FULL, ID, ID_DV, IS_AMETYS_OBJECT, LANGUAGE_SEPARATOR, LAST_MODIFIED, LENGTH, MIME_TYPES, MIXIN_TYPES, PATH, PSEUDO_CONTENT_TYPE_VALUE_RESOURCE, PSEUDO_CONTENT_TYPES, REPEATER_ENTRY_POSITION, RESOURCE_ANCESTOR_AND_SELF_IDS, RESOURCE_ANCESTOR_IDS, RESOURCE_CREATOR, RESOURCE_DATE, RESOURCE_LAST_MODIFIED, RESOURCE_MIME_TYPE_GROUP, RESOURCE_ROOT_ID, SIMPLE_CONTENT_PARENTS, STEMMED_OPERATOR, SUB_CONTENT, SYSTEM_FULL, TAGS, TITLE, TITLE_SORT, TYPE_CONTENT, TYPE_CONTENT_ATTACHMENT_RESOURCE, TYPE_CONTENT_ATTRIBUTE_RESOURCE, TYPE_REPEATER, TYPE_RESOURCE, TYPE_WF_ENTRY, TYPE_WF_STEP, WORKFLOW_CURRENT_STEPS, WORKFLOW_CURRENT_STEPS_DV, WORKFLOW_ENTRY_STATE, WORKFLOW_HISTORY_STEPS, WORKFLOW_HISTORY_STEPS_DV, WORKFLOW_NAME, WORKFLOW_REF, WORKFLOW_REF_DV, WORKFLOW_STEP_ACTIONID, WORKFLOW_STEP_CALLER, WORKFLOW_STEP_DUEDATE, WORKFLOW_STEP_FINISHDATE, WORKFLOW_STEP_ID, WORKFLOW_STEP_OWNER, WORKFLOW_STEP_STARTDATE, WORKFLOW_STEP_STATUSFields inherited from interface org.ametys.web.indexing.solr.SolrWebFieldNames
ATTACHMENT_PAGE_ID, CONTENT_IDS, CONTENT_INTERESTING_DATES, DATE_FOR_SORTING, DATES_FACET, FACETABLE_CONTENT_FIELD_PREFIX, LASTNAME_FOR_SORTING, PAGE_ANCESTOR_IDS, PAGE_CONTENT_TYPES, PAGE_DEPTH, PAGE_IDS, PAGE_LONG_TITLE, PAGE_OUTGOING_REFEERENCES_RESOURCE_IDS, PAGE_PARENT_ID, PAGE_TITLE, PAGE_TYPE, PAGE_VISIBLE_ATTACHMENT_RESOURCE_IDS, SECTION_PAGE_TITLE, SERVICE_IDS, SHARED, SITE_NAME, SITE_TYPE, SITEMAP_NAME, TEMPLATE, TYPE_PAGE, TYPE_PAGE_RESOURCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAllow to perform other searcher configurationprotected booleantrueto check rights during searchvoidcontextualize(Context context) voidgenerate()protected abstract Collection<String>getDocumentTypes(Request request) Get the document types.protected QuerygetDocumentTypesQuery(Collection<String> documentTypes) Build the search query to have results matching at least one of the given document typesprotected abstract Map<String,AbstractSearchGenerator.FacetField> Get the facets from request parametersgetFacetValues(Request request, Collection<String> siteNames, String language) Get the facet valuesprotected abstract Collection<Query>getFilterQueries(Request request, Collection<String> siteNames, String language) Get the filter queries from the request parameters.protected intgetPageIndex(Request request) Get the page indexgetPrimarySortFields(Request request) Get the primary sort fieldsprotected abstract QuerygetQuery(Request request, Collection<String> siteNames, String language) Get the query from request parametersprotected abstract Set<FrontOfficeSearcherFactory.QueryFacet>getQueryFacets(Request request) Get the facet.queriesprotected abstract Collection<String>getQueryFacetValues(Request request) Get the facet.query valuesprotected StringGet the search mode.protected abstract SortgetSortField(Request request) Get the sort fieldprotected ZoneItemgetZoneItem(Request request) Get the zone itemprotected booleanCheck if the input is valid.protected voidGenerate any additional information.protected voidSAX additional information on page hitprotected voidsaxContent(String contentId, String viewName, Locale defaultLocale) SAX the view of a content if existsprotected voidsaxFacets(Request request, SearchResults<AmetysObject> searchResults, String siteName, String lang) SAX the facets resultsprotected abstract voidsaxFormFields(Request request, String siteName, String lang) SAX the form search criteriaprotected voidsaxFormParameters(Request request, SearchResults<AmetysObject> searchResults, int start, int offset, String siteName, String lang) SAX the search parameters from the request parametersprotected abstract voidsaxFormValues(Request request, int start, int offset) SAX the form search criteria valuesprotected abstract voidsaxHits(SearchResults<AmetysObject> results, int start, int maxResults) SAX the result hitsprotected voidsaxPageHit(float score, float maxScore, Page page) SAX a hit of type page.protected voidsaxPagination(long totalHits, int start, int offset) SAX elements for paginationprotected voidsaxResourceHit(float score, float maxScore, Resource resource) SAX a hit of type "resource".protected voidsaxRichTextExcerpt(String attributePath, String contentId, RichText richText) SAX excerpt for rich textprotected voidGenerate the service identifiers: service group ID, ZoneItem ID, ...protected voidSAX sortprotected SearchResults<AmetysObject>search(Request request, Collection<String> siteNames, String language, int pageIndex, int start, int maxResults) Searchprotected SearchResults<AmetysObject>search(Request request, Collection<String> siteNames, String language, int pageIndex, int start, int maxResults, boolean saxResults) Searchvoidservice(ServiceManager smanager) protected booleanTemplate methods to disable/enable the processing of the facets during the search.Methods inherited from class org.apache.cocoon.generation.ServiceableGenerator
disposeMethods inherited from class org.apache.cocoon.generation.AbstractGenerator
recycle, setupMethods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandlerMethods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLoggerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.cocoon.xml.XMLProducer
setConsumer
-
Field Details
-
DOCUMENT_TYPE_IS_PAGE_RESOURCE_FACET_NAME
The name of the facet.query testing the pageResources- See Also:
-
_TEXTFIELD_PATTERN
Textfield pattern -
_cTypeExtPt
TheContentTypemanager -
_siteManager
The sites manager -
_context
The cocoon context -
_tagExtPt
The tag extension point -
_resolver
The Ametys resolver -
_contentTypesHelper
The helper to handler content types -
_uriResolverEP
The uri resolver extension point -
_searcherFactory
The searcher factory -
_searchHelper
The content searcher
-
-
Constructor Details
-
AbstractSearchGenerator
public AbstractSearchGenerator()
-
-
Method Details
-
service
- Specified by:
servicein interfaceServiceable- Overrides:
servicein classServiceableGenerator- Throws:
ServiceException
-
contextualize
- Specified by:
contextualizein interfaceContextualizable- Throws:
ContextException
-
generate
- Specified by:
generatein interfaceGenerator- Throws:
IOExceptionSAXExceptionProcessingException
-
getZoneItem
Get the zone item- Parameters:
request- The request- Returns:
- the zone item
-
search
protected SearchResults<AmetysObject> search(Request request, Collection<String> siteNames, String language, int pageIndex, int start, int maxResults) throws Exception Search- Parameters:
request- the requestsiteNames- The name of the sites to search inlanguage- The language code to searchpageIndex- the page indexstart- The offset for search resultsmaxResults- The maximum number of results- Returns:
- The search results
- Throws:
Exception- If an error occurred during search
-
search
protected SearchResults<AmetysObject> search(Request request, Collection<String> siteNames, String language, int pageIndex, int start, int maxResults, boolean saxResults) throws Exception Search- Parameters:
request- the requestsiteNames- The name of the sites to search inlanguage- The language code to searchpageIndex- the page indexstart- The offset for search resultsmaxResults- The maximum number of resultssaxResults- false to not sax results- Returns:
- The search results
- Throws:
Exception- If an error occurred during search
-
saxSort
SAX sort- Parameters:
sort- the current sort- Throws:
SAXException- SAXException If an error occurs while SAXing
-
_additionalSearchProcessing
Allow to perform other searcher configuration- Parameters:
searcher- The searcher that will be used for the search operation
-
getDocumentTypesQuery
Build the search query to have results matching at least one of the given document types- Parameters:
documentTypes- The document types- Returns:
- The document type query
-
getDocumentTypes
Get the document types.- Parameters:
request- The request.- Returns:
- the document types to search.
-
getSortField
Get the sort field- Parameters:
request- The request- Returns:
- The sort field or null to sort by score
-
getPrimarySortFields
Get the primary sort fields- Parameters:
request- The request- Returns:
- the list additional sort fields or empty list.
-
saxFormParameters
protected void saxFormParameters(Request request, SearchResults<AmetysObject> searchResults, int start, int offset, String siteName, String lang) throws SAXException SAX the search parameters from the request parameters- Parameters:
request- The requestsearchResults- The search resultsstart- The start indexoffset- The number of resultssiteName- The current site namelang- The current language- Throws:
SAXException- If an error occurs while SAXing
-
saxFormFields
protected abstract void saxFormFields(Request request, String siteName, String lang) throws SAXException SAX the form search criteria- Parameters:
request- The requestsiteName- The current site namelang- The current language- Throws:
SAXException- if an error occurs while SAXing
-
saxFacets
protected void saxFacets(Request request, SearchResults<AmetysObject> searchResults, String siteName, String lang) throws SAXException SAX the facets results- Parameters:
request- The requestsearchResults- The search resultsiteName- The site namelang- The language- Throws:
SAXException- if an error occurred while saxing
-
saxFormValues
SAX the form search criteria values- Parameters:
request- The requeststart- The start indexoffset- The number of results- Throws:
SAXException- if an error occurs while SAXing
-
getQuery
protected abstract Query getQuery(Request request, Collection<String> siteNames, String language) throws IllegalArgumentException Get the query from request parameters- Parameters:
request- The requestsiteNames- The site names.language- The language- Returns:
- The query object.
- Throws:
IllegalArgumentException- If the search field is invalid.
-
getFilterQueries
protected abstract Collection<Query> getFilterQueries(Request request, Collection<String> siteNames, String language) throws IllegalArgumentException Get the filter queries from the request parameters.- Parameters:
request- The request.siteNames- The site names.language- The language.- Returns:
- A collection of filter queries.
- Throws:
IllegalArgumentException- If a search field is invalid.
-
useFacets
Template methods to disable/enable the processing of the facets during the search.- Returns:
trueto enable facets
-
getFacets
protected abstract Map<String,AbstractSearchGenerator.FacetField> getFacets(Request request) throws IllegalArgumentException Get the facets from request parameters- Parameters:
request- The request- Returns:
- The facet fields
- Throws:
IllegalArgumentException- If the search field is invalid.
-
getQueryFacets
Get the facet.queries- Parameters:
request- The request- Returns:
- The facet.queries
- Throws:
IllegalArgumentException- If the search field is invalid.
-
getFacetValues
protected abstract Map<String,List<String>> getFacetValues(Request request, Collection<String> siteNames, String language) Get the facet values- Parameters:
request- The requestsiteNames- The site nameslanguage- The language- Returns:
- The facet values
-
getQueryFacetValues
Get the facet.query values- Parameters:
request- The request- Returns:
- The facet.query values
-
saxHits
protected abstract void saxHits(SearchResults<AmetysObject> results, int start, int maxResults) throws SAXException, IOException SAX the result hits- Parameters:
results- The search results.start- The start indexmaxResults- The number of results to generate.- Throws:
SAXException- If an error occurs while SAXingIOException- If there is a low-level IO error
-
saxPageHit
SAX a hit of type page.- Parameters:
score- The score of the pagemaxScore- The maximum score of the search resultspage- The page- Throws:
SAXException- If an error occurs while SAXing
-
saxAdditionalInfosOnPageHit
SAX additional information on page hit- Parameters:
page- the page- Throws:
SAXException- if something goes wrong when saxing the information
-
saxResourceHit
SAX a hit of type "resource".- Parameters:
score- The score of the pagemaxScore- The maximum score of the search resultsresource- The resource- Throws:
SAXException- If an error occurs while SAXing
-
saxPagination
SAX elements for pagination- Parameters:
totalHits- The total number of resultstart- The start index of searchoffset- The max number of results per page- Throws:
SAXException- SAXException If an error occurs while SAXing
-
getPageIndex
Get the page index- Parameters:
request- The request- Returns:
- The page index
-
saxServiceIdentifiers
Generate the service identifiers: service group ID, ZoneItem ID, ...- Throws:
SAXException- if an error occurs SAXing data.IOException- if an error occurs SAXing data.ProcessingException- if a processing error occurs.
-
saxAdditionalInfos
Generate any additional information.- Throws:
SAXException- if an error occurs SAXing data.IOException- if an error occurs SAXing data.ProcessingException- if a processing error occurs.
-
getSearchMode
Get the search mode.- Returns:
- the search mode as a string.
-
isInputValid
Check if the input is valid.- Returns:
- true if the input is valid, false otherwise.
-
saxContent
protected void saxContent(String contentId, String viewName, Locale defaultLocale) throws SAXException SAX the view of a content if exists- Parameters:
contentId- the id of the contentviewName- The name of view to saxdefaultLocale- The locale to use to sax localized values such as multilingual content or multilingual string. Only use if initial content's language is not null.- Throws:
SAXException- if an exception occurs while saxing
-
saxRichTextExcerpt
SAX excerpt for rich text- Parameters:
attributePath- The path of attributecontentId- The content idrichText- The rich text
-
_checkRights
trueto check rights during search- Returns:
trueto check rights during search
-