org.compass.core.support.search
Class CompassSearchHelper

java.lang.Object
  extended by org.compass.core.support.search.CompassSearchHelper

public class CompassSearchHelper
extends Object

A general Search Controller that perform the search operations. The seardch controller is therad safe.

Will perform the search operation on the Compass instance using the query supplied by the CompassSearchCommand.

Pagination will be enabled if pageSize property is set on the controller, as well as providing the page number property on the CompassSearchCommand.

The search controller provides several extension points, including buildQuery(CompassSearchCommand,org.compass.core.CompassSession), doProcessBeforeDetach(CompassSearchCommand,org.compass.core.CompassSession,org.compass.core.CompassHits,int,int) and doProcessAfterDetach(CompassSearchCommand,org.compass.core.CompassSession,org.compass.core.CompassDetachedHits).

Author:
kimchy

Constructor Summary
CompassSearchHelper(Compass compass)
          Creates a new compass search helper based on Compass without pagination.
CompassSearchHelper(Compass compass, Integer pageSize)
          Creates a new compass search helper based on Compass with pagination.
 
Method Summary
protected  CompassQuery buildQuery(CompassSearchCommand searchCommand, CompassSession session)
          Acts as an extension point for search controller that wish to build different CompassQueries.
protected  void doProcessAfterDetach(CompassSearchCommand searchCommand, CompassSession session, CompassDetachedHits hits)
          An option to perform any type of processing after the hits are detached.
protected  void doProcessBeforeDetach(CompassSearchCommand searchCommand, CompassSession session, CompassHits hits, int from, int size)
          An option to perform any type of processing before the hits are detached.
 Integer getPageSize()
          Returns the page size for the pagination of the results.
protected  CompassSearchResults performSearch(CompassSearchCommand searchCommand, CompassSession session)
          Performs the actual search operation.
 CompassSearchResults search(CompassSearchCommand command)
           
 CompassSearchResults searchLocal(CompassSearchCommand command)
           
 void setPageSize(Integer pageSize)
          Sets the page size for the pagination of the results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompassSearchHelper

public CompassSearchHelper(Compass compass)
Creates a new compass search helper based on Compass without pagination.

Parameters:
compass - The compass instance to use

CompassSearchHelper

public CompassSearchHelper(Compass compass,
                           Integer pageSize)
Creates a new compass search helper based on Compass with pagination.

Parameters:
compass - The Compass instance
pageSize - The page size
Method Detail

search

public CompassSearchResults search(CompassSearchCommand command)
                            throws CompassException
Throws:
CompassException

searchLocal

public CompassSearchResults searchLocal(CompassSearchCommand command)
                                 throws CompassException
Throws:
CompassException

performSearch

protected CompassSearchResults performSearch(CompassSearchCommand searchCommand,
                                             CompassSession session)
Performs the actual search operation. If pageSize is set, will perform pagination using the provided size, if not, will return all the hits. Also allows for several extensions points: buildQuery(CompassSearchCommand,org.compass.core.CompassSession), doProcessBeforeDetach(CompassSearchCommand,org.compass.core.CompassSession,org.compass.core.CompassHits,int,int) and doProcessAfterDetach(CompassSearchCommand,org.compass.core.CompassSession,org.compass.core.CompassDetachedHits).

Parameters:
searchCommand - The search command to perform the search
session - CompassSession to execute the search with
Returns:
search results

buildQuery

protected CompassQuery buildQuery(CompassSearchCommand searchCommand,
                                  CompassSession session)

Acts as an extension point for search controller that wish to build different CompassQueries. Since the search command can hold either a CompassQuery or a query string, will first check if the CompassQuery is set, and if not, will use the query search string.

The default implementation when query string is provided uses the session to create a query builder and use the queryString option, i.e.: session.queryBuilder().queryString(searchCommand.getQuery().trim()).toQuery();.

Some other interesting options might be to add sorting to the query, adding other queries using a boolean query, or executing a different query.


doProcessBeforeDetach

protected void doProcessBeforeDetach(CompassSearchCommand searchCommand,
                                     CompassSession session,
                                     CompassHits hits,
                                     int from,
                                     int size)
An option to perform any type of processing before the hits are detached.


doProcessAfterDetach

protected void doProcessAfterDetach(CompassSearchCommand searchCommand,
                                    CompassSession session,
                                    CompassDetachedHits hits)
An option to perform any type of processing after the hits are detached.


getPageSize

public Integer getPageSize()
Returns the page size for the pagination of the results. If not set, not pagination will be used.


setPageSize

public void setPageSize(Integer pageSize)
Sets the page size for the pagination of the results. If not set, not pagination will be used.

Parameters:
pageSize - The page size for pagination of the results


Copyright (c) 2004-2008 The Compass Project.