Package org.ametys.cms.search.cocoon
Class SearchJsonReader
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.apache.cocoon.reading.AbstractReader
-
- org.apache.cocoon.reading.ServiceableReader
-
- org.ametys.cms.search.cocoon.SearchJsonReader
-
- All Implemented Interfaces:
Poolable
,Recyclable
,Component
,LogEnabled
,Serviceable
,Reader
,SitemapModelComponent
,SitemapOutputComponent
public class SearchJsonReader extends ServiceableReader
JSON reader for search for contents.
-
-
Field Summary
Fields Modifier and Type Field Description protected ContentGridComponent
_contentGridComponent
The ContentGridComponent instanceprotected ContentHelper
_contentHelper
The content helperprotected ContentTypesHelper
_contentTypesHelper
The content types helper.protected JSONUtils
_jsonUtils
JSON utilsprotected AmetysObjectResolver
_resolver
The Ametys object resolverprotected ServerCommHelper
_serverCommHelper
The serverComm helper-
Fields inherited from class org.apache.cocoon.reading.ServiceableReader
manager
-
Fields inherited from class org.apache.cocoon.reading.AbstractReader
objectModel, out, parameters, resolver, source
-
-
Constructor Summary
Constructors Constructor Description SearchJsonReader()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
convertContents2JsonObject(Map<String,Object> results2Json, List<String> contentIds, SearchUIModel model, Locale defaultLocale)
Convert the query results to a JSON objectprotected void
convertResults2JsonObject(Map<String,Object> results2Json, SearchResults<Content> results, SearchUIModel model, Locale defaultLocale)
Convert the query results to a JSON objectvoid
generate()
protected Map<String,Object>
getContentData(Content content, ContentValuesExtractorFactory.ContentValuesExtractor extractor, Locale defaultLocale, Map<String,Object> contextualParameters)
Generate standard content data.String
getMimeType()
void
service(ServiceManager smanager)
protected int
setContents(Map<String,Object> searchResults, List<String> contentIds, SearchUIModel model, Locale defaultLocale, Map<String,Object> contextualParameters)
Extract the desired contents and set them in the search results.protected void
setContents(Map<String,Object> searchResults, SearchResults<Content> results, SearchUIModel model, Locale defaultLocale, Map<String,Object> contextualParameters)
Extract the desired contents from theSearchResults
object and set them in the search results.protected void
setFacets(Map<String,Object> searchResults, Map<String,Map<String,Integer>> facetResults, SearchUIModel model, Locale locale, Map<String,Object> contextualParameters)
Set the facet results in the search results.-
Methods inherited from class org.apache.cocoon.reading.AbstractReader
getLastModified, recycle, setOutputStream, setup, shouldSetContentLength
-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
_jsonUtils
protected JSONUtils _jsonUtils
JSON utils
-
_serverCommHelper
protected ServerCommHelper _serverCommHelper
The serverComm helper
-
_contentTypesHelper
protected ContentTypesHelper _contentTypesHelper
The content types helper.
-
_contentHelper
protected ContentHelper _contentHelper
The content helper
-
_resolver
protected AmetysObjectResolver _resolver
The Ametys object resolver
-
_contentGridComponent
protected ContentGridComponent _contentGridComponent
The ContentGridComponent instance
-
-
Constructor Detail
-
SearchJsonReader
public SearchJsonReader()
-
-
Method Detail
-
service
public void service(ServiceManager smanager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classServiceableReader
- Throws:
ServiceException
-
getMimeType
public String getMimeType()
- Specified by:
getMimeType
in interfaceSitemapOutputComponent
- Overrides:
getMimeType
in classAbstractReader
-
generate
public void generate() throws IOException, SAXException, ProcessingException
-
convertResults2JsonObject
protected void convertResults2JsonObject(Map<String,Object> results2Json, SearchResults<Content> results, SearchUIModel model, Locale defaultLocale) throws ProcessingException
Convert the query results to a JSON object- Parameters:
results2Json
- the JSON object to fill.results
- the query resultsmodel
- the search modeldefaultLocale
- the default locale for localized values if content's language is null.- Throws:
ProcessingException
- If an error occurs.
-
convertContents2JsonObject
protected void convertContents2JsonObject(Map<String,Object> results2Json, List<String> contentIds, SearchUIModel model, Locale defaultLocale) throws ProcessingException
Convert the query results to a JSON object- Parameters:
results2Json
- the JSON object to fill.contentIds
- the ids of contentsmodel
- the search modeldefaultLocale
- the default locale for localized values if content's language is null.- Throws:
ProcessingException
- If an error occurs.
-
setContents
protected void setContents(Map<String,Object> searchResults, SearchResults<Content> results, SearchUIModel model, Locale defaultLocale, Map<String,Object> contextualParameters)
Extract the desired contents from theSearchResults
object and set them in the search results.- Parameters:
searchResults
- the search results to populate.results
- theSearchResults
.model
- the search model.defaultLocale
- the default locale for localized values if content's language is null.contextualParameters
- the search contextual parameters.
-
setContents
protected int setContents(Map<String,Object> searchResults, List<String> contentIds, SearchUIModel model, Locale defaultLocale, Map<String,Object> contextualParameters)
Extract the desired contents and set them in the search results.- Parameters:
searchResults
- the search results to populate.contentIds
- the id of desired contentsmodel
- the search model.defaultLocale
- the default locale for localized values if content's language is null.contextualParameters
- the search contextual parameters.- Returns:
- the number of resolved contents without error
-
getContentData
protected Map<String,Object> getContentData(Content content, ContentValuesExtractorFactory.ContentValuesExtractor extractor, Locale defaultLocale, Map<String,Object> contextualParameters)
Generate standard content data.- Parameters:
content
- The content.extractor
- The content values extractor which generates.defaultLocale
- the default locale for localized values if content's language is null.contextualParameters
- The search contextual parameters.- Returns:
- A Map containing the content data.
-
setFacets
protected void setFacets(Map<String,Object> searchResults, Map<String,Map<String,Integer>> facetResults, SearchUIModel model, Locale locale, Map<String,Object> contextualParameters)
Set the facet results in the search results.- Parameters:
searchResults
- the search results.facetResults
- the facet results as a Map<column name, Map<value, result count>>.model
- the search model.locale
- the locale for localized valuescontextualParameters
- the search contextual parameters.
-
-