For most query types, the results
property of the form handler is set to the Results
object returned by ATG Search. Typically, you do not need to modify the Results
object in the ATG platform, because ATG Search includes many configuration options for customizing the search results on the server side.
In some cases, however, you may want to manipulate or filter the data in some way on the client (ATG platform) side. To enable you to do this, each form handler has a resultsFetcher
property that can point to a component that implements the atg.search.query.formhandlers.ResultsFetchingProxy
interface. If the form handler is configured this way, the fetch()
method of this component is used to get the Results
object. Your implementation of this method can include logic that modifies the Results
object before using it to set the results
property of the form handler.
The ATG platform includes a class, atg.search.query.formhandlers.CollectionFilterFetchingProxy
, that implements the ResultFetchingProxy
interface. This class has a filter
property that you can set to a collection filter component that performs the actual filtering of the results.
In addition, the ATG platform includes an abstract class for filtering results returned by ATG Search. This class, atg.search.query.filters.RepositoryItemResultCollectionFilter
, serves as a base class that you can subclass to create your own collection filters.
The following example shows the source code of a sample subclass, atg.search.query.filters.SampleRepositoryItemCollectionFilter
, which evaluates all of the Result
objects stored in the results
property of the Results
object, and rejects any Result
object that does not refer to a valid repository item. The SampleRepositoryItemCollectionFilter
class is intended mainly as a simple example of how to write a collection filter that operates on an ATG Search Results
object, and is not necessarily functionality that you will find useful in itself.
package atg.search.query.filters; import atg.repository.Repository; import atg.repository.RepositoryException; import atg.repository.RepositoryItem; import atg.service.collections.filter.FilterException; import com.primus.searchstudio.Result; import javax.naming.NamingException; /** * A sample RepositoryItemResultCollectionFilter which rejects any * search Result object which does not refer to a valid repository * item. */ public class SampleRepositoryItemCollectionFilter extends RepositoryItemResultCollectionFilter { public SampleRepositoryItemCollectionFilter() {} /** * Filter that rejects any search result that does not refer to a * repository item * * @param pResult a search result object * @param pRepositoryItem the associated repository item or null if * the search result object does not refer to a repository item */ protected boolean accept( Result pResult, RepositoryItem pUserProfile) throws FilterException { RepositoryItem repositoryItem = null; try { // Use the url property of the Result object to retrieve the // repository item repositoryItem = getRepositoryItem( pResult ); } catch ( NamingException ne ) { // Don't care } if ( isLoggingDebug() ) logDebug( "repositoryItem = " + repositoryItem ); return repositoryItem != null; } }
For more information about collection filters, see the ATG Personalization Programming Guide.