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 Classes Modifier and Type Class Description protected class
AbstractSearchGenerator.AttributeFacetField
Facet field for an attributeprotected class
AbstractSearchGenerator.ContentTypeFacetField
Facet field for content typesprotected static interface
AbstractSearchGenerator.FacetField
Interface representing a facet field
-
Field Summary
Fields Modifier and Type Field Description protected ContentTypesHelper
_contentTypesHelper
The helper to handler content typesprotected Context
_context
The cocoon contextprotected ContentTypeExtensionPoint
_cTypeExtPt
TheContentType
managerprotected AmetysObjectResolver
_resolver
The Ametys resolverprotected FrontOfficeSearcherFactory
_searcherFactory
The searcher factoryprotected ContentSearchHelper
_searchHelper
The content searcherprotected SiteManager
_siteManager
The sites managerprotected TagProviderExtensionPoint
_tagExtPt
The tag extension pointprotected static Pattern
_TEXTFIELD_PATTERN
Textfield patternprotected URIResolverExtensionPoint
_uriResolverEP
The uri resolver extension pointstatic String
DOCUMENT_TYPE_IS_PAGE_RESOURCE_FACET_NAME
The name of the facet.query testing the pageResources-
Fields inherited from class org.apache.cocoon.generation.ServiceableGenerator
manager
-
Fields inherited from class org.apache.cocoon.generation.AbstractGenerator
objectModel, parameters, resolver, source
-
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer
-
Fields 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, CONTENT_COMMENTS_NONVALIDATED, CONTENT_COMMENTS_VALIDATED, CONTENT_CREATOR, CONTENT_LANGUAGE, CONTENT_LANGUAGES, CONTENT_LAST_CONTRIBUTOR, 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, EXCERPT, FILENAME, FIRST_VALIDATION, FULL_EXACT_WS, FULL_GENERAL, FULL_PREFIX, FULL_STEMMED_PREFIX, ID, IS_AMETYS_OBJECT, LAST_MAJOR_VALIDATION, LAST_MODIFIED, LAST_VALIDATION, 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, SUB_CONTENT, 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, WORKFLOW_STEP_ACTIONID, WORKFLOW_STEP_CALLER, WORKFLOW_STEP_DUEDATE, WORKFLOW_STEP_FINISHDATE, WORKFLOW_STEP_ID, WORKFLOW_STEP_OWNER, WORKFLOW_STEP_STARTDATE, WORKFLOW_STEP_STATUS
-
Fields 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, ORPHAN, 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, PRIVACY, SECTION_PAGE_TITLE, SERVICE_IDS, SHARED, SITE_NAME, SITE_TYPE, SITEMAP_NAME, TEMPLATE, TYPE_PAGE, TYPE_PAGE_RESOURCE
-
-
Constructor Summary
Constructors Constructor Description AbstractSearchGenerator()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
_additionalSearchProcessing(SearcherFactory.Searcher searcher)
Allow to perform other searcher configurationprivate String
_getResourceExcerpt(Resource resource)
private Page
_getResourcePage(Resource resource)
private void
_saxIcon(String filename)
private void
_saxLastModifiedDate(Page page)
private void
_saxLastValidationDate(Page page)
private void
_saxPageContents(Page page)
private void
_saxSize(long size)
void
contextualize(Context context)
void
generate()
protected abstract Collection<String>
getDocumentTypes(Request request)
Get the document types.protected Query
getDocumentTypesQuery(Collection<String> documentTypes)
Build the search query to have results matching at least one of the given document typesprotected abstract Map<String,AbstractSearchGenerator.FacetField>
getFacets(Request request)
Get the facets from request parametersprotected abstract Map<String,List<String>>
getFacetValues(Request request, Collection<String> siteNames, String language)
Get the facet valuesprotected abstract Collection<String>
getFields()
Get the searchable fieldsprotected abstract Collection<Query>
getFilterQueries(Request request, Collection<String> siteNames, String language)
Get the filter queries from the request parameters.protected int
getPageIndex(Request request)
Get the page indexprotected abstract List<Sort>
getPrimarySortFields(Request request)
Get the primary sort fieldsprotected abstract Query
getQuery(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 String
getSearchMode()
Get the search mode.protected abstract Sort
getSortField(Request request)
Get the sort fieldprotected ZoneItem
getZoneItem(Request request)
Get the zone itemprotected boolean
isInputValid()
Check if the input is valid.protected void
saxAdditionalInfos()
Generate any additional information.protected void
saxAdditionalInfosOnPageHit(Page page)
SAX additional information on page hitprotected void
saxContent(String contentId, String viewName, Locale defaultLocale)
SAX the view of a content if existsprotected void
saxFacets(Request request, SearchResults<AmetysObject> searchResults, String siteName, String lang)
SAX the facets resultsprotected abstract void
saxFormFields(Request request, String siteName, String lang)
SAX the form search criteriaprotected void
saxFormParameters(Request request, SearchResults<AmetysObject> searchResults, int start, int offset, String siteName, String lang)
SAX the search parameters from the request parametersprotected abstract void
saxFormValues(Request request, int start, int offset)
SAX the form search criteria valuesprotected abstract void
saxHits(SearchResults<AmetysObject> results, int start, int maxResults)
SAX the result hitsprotected void
saxPageHit(float score, float maxScore, Page page)
SAX a hit of type page.protected void
saxPagination(long totalHits, int start, int offset)
SAX elements for paginationprotected void
saxResourceHit(float score, float maxScore, Resource resource)
SAX a hit of type "resource".protected void
saxRichTextExcerpt(String attributePath, String contentId, RichText richText)
SAX excerpt for rich textprotected void
saxServiceIdentifiers()
Generate the service identifiers: service group ID, ZoneItem ID, ...protected void
saxSort(Sort sort)
SAX 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)
Searchvoid
service(ServiceManager smanager)
protected boolean
useFacets()
Template methods to disable/enable the processing of the facets during the search.-
Methods inherited from class org.apache.cocoon.generation.ServiceableGenerator
dispose
-
Methods inherited from class org.apache.cocoon.generation.AbstractGenerator
recycle, setup
-
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cocoon.xml.XMLProducer
setConsumer
-
-
-
-
Field Detail
-
DOCUMENT_TYPE_IS_PAGE_RESOURCE_FACET_NAME
public static final String DOCUMENT_TYPE_IS_PAGE_RESOURCE_FACET_NAME
The name of the facet.query testing the pageResources- See Also:
- Constant Field Values
-
_TEXTFIELD_PATTERN
protected static final Pattern _TEXTFIELD_PATTERN
Textfield pattern
-
_cTypeExtPt
protected ContentTypeExtensionPoint _cTypeExtPt
TheContentType
manager
-
_siteManager
protected SiteManager _siteManager
The sites manager
-
_tagExtPt
protected TagProviderExtensionPoint _tagExtPt
The tag extension point
-
_resolver
protected AmetysObjectResolver _resolver
The Ametys resolver
-
_contentTypesHelper
protected ContentTypesHelper _contentTypesHelper
The helper to handler content types
-
_uriResolverEP
protected URIResolverExtensionPoint _uriResolverEP
The uri resolver extension point
-
_searcherFactory
protected FrontOfficeSearcherFactory _searcherFactory
The searcher factory
-
_searchHelper
protected ContentSearchHelper _searchHelper
The content searcher
-
-
Constructor Detail
-
AbstractSearchGenerator
public AbstractSearchGenerator()
-
-
Method Detail
-
service
public void service(ServiceManager smanager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classServiceableGenerator
- Throws:
ServiceException
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
generate
public void generate() throws IOException, SAXException, ProcessingException
- Specified by:
generate
in interfaceGenerator
- Throws:
IOException
SAXException
ProcessingException
-
getZoneItem
protected ZoneItem getZoneItem(Request request)
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
protected void saxSort(Sort sort) throws SAXException
SAX sort- Parameters:
sort
- the current sort- Throws:
SAXException
- SAXException If an error occurs while SAXing
-
_additionalSearchProcessing
protected void _additionalSearchProcessing(SearcherFactory.Searcher searcher)
Allow to perform other searcher configuration- Parameters:
searcher
- The searcher that will be used for the search operation
-
getDocumentTypesQuery
protected Query getDocumentTypesQuery(Collection<String> documentTypes)
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
protected abstract Collection<String> getDocumentTypes(Request request)
Get the document types.- Parameters:
request
- The request.- Returns:
- the document types to search.
-
getSortField
protected abstract Sort getSortField(Request request)
Get the sort field- Parameters:
request
- The request- Returns:
- The sort field or null to sort by score
-
getPrimarySortFields
protected abstract List<Sort> getPrimarySortFields(Request request)
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
protected abstract void saxFormValues(Request request, int start, int offset) throws SAXException
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
protected boolean useFacets()
Template methods to disable/enable the processing of the facets during the search.- Returns:
true
to 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
protected abstract Set<FrontOfficeSearcherFactory.QueryFacet> getQueryFacets(Request request)
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
protected abstract Collection<String> getQueryFacetValues(Request request)
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
-
getFields
protected abstract Collection<String> getFields()
Get the searchable fields- Returns:
- The fields
-
saxPageHit
protected void saxPageHit(float score, float maxScore, Page page) throws SAXException
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
-
_saxPageContents
private void _saxPageContents(Page page) throws SAXException
- Throws:
SAXException
-
_saxLastModifiedDate
private void _saxLastModifiedDate(Page page) throws SAXException
- Throws:
SAXException
-
_saxLastValidationDate
private void _saxLastValidationDate(Page page) throws SAXException
- Throws:
SAXException
-
saxAdditionalInfosOnPageHit
protected void saxAdditionalInfosOnPageHit(Page page) throws SAXException
SAX additional information on page hit- Parameters:
page
- the page- Throws:
SAXException
- if something goes wrong when saxing the information
-
saxResourceHit
protected void saxResourceHit(float score, float maxScore, Resource resource) throws SAXException
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
-
_getResourceExcerpt
private String _getResourceExcerpt(Resource resource)
-
_getResourcePage
private Page _getResourcePage(Resource resource)
-
saxPagination
protected void saxPagination(long totalHits, int start, int offset) throws SAXException
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
protected int getPageIndex(Request request)
Get the page index- Parameters:
request
- The request- Returns:
- The page index
-
_saxIcon
private void _saxIcon(String filename) throws SAXException
- Throws:
SAXException
-
_saxSize
private void _saxSize(long size) throws SAXException
- Throws:
SAXException
-
saxServiceIdentifiers
protected void saxServiceIdentifiers() throws SAXException, IOException, ProcessingException
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
protected void saxAdditionalInfos() throws SAXException, IOException, ProcessingException
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
protected String getSearchMode()
Get the search mode.- Returns:
- the search mode as a string.
-
isInputValid
protected boolean 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
protected void saxRichTextExcerpt(String attributePath, String contentId, RichText richText)
SAX excerpt for rich text- Parameters:
attributePath
- The path of attributecontentId
- The content idrichText
- The rich text
-
-