no.sesat.search.mode.command
Class AbstractSearchCommand

java.lang.Object
  extended by no.sesat.search.mode.command.AbstractSearchCommand
All Implemented Interfaces:
Serializable, Callable<ResultList<ResultItem>>, SearchCommand
Direct Known Subclasses:
AbstractWebServiceSearchCommand, AbstractXmlSearchCommand, MathExpressionSearchCommand, PropertiesCommand, SolrSearchCommand, StaticSearchCommand, StockSearchCommand

public abstract class AbstractSearchCommand
extends Object
implements SearchCommand, Serializable

The base abstraction for Search Commands providing a large framework for commands to run against.

While the SearchCommand interface defines basic execution behavour this abstraction defines:



This command undertook a large refactoring in 2.18 to clean up internal concerns. See the specification http://sesat.no/new-design-proposal-for-searchcommand-and-abstractsearchcommand.html

Version:
$Id: AbstractSearchCommand.java 7225 2009-04-09 00:32:20Z ssmiweve $
See Also:
Serialized Form

Nested Class Summary
protected static class AbstractSearchCommand.QueryBuilderFactory
           
protected static class AbstractSearchCommand.ReconstructedQuery
          see createQuery(string)
 
Nested classes/interfaces inherited from interface no.sesat.search.mode.command.SearchCommand
SearchCommand.Context
 
Field Summary
protected  boolean completed
           
protected  SearchCommand.Context context
          The context to work against.
protected  DataModel datamodel
           
protected  Map<String,StringDataObject> datamodelParameters
           
protected static Logger DUMP
           
protected  String untransformedQuery
           
 
Constructor Summary
AbstractSearchCommand(SearchCommand.Context cxt)
          Default constructor.
 
Method Summary
protected  void addFilterString(String filter)
          Makes presumption that filter is in format "field:value".
 ResultList<ResultItem> call()
          Called by thread executor
protected  QueryBuilder constructQueryBuilder(SearchCommand.Context cxt, QueryBuilder.Context queryBuilderContext)
          Construct from scratch, and return the query builder to use.
protected  AbstractSearchCommand.ReconstructedQuery createQuery(String queryString)
          Uses QueryParser to create a new Query with all evaluation enabled.
protected  AbstractSearchCommand.ReconstructedQuery createQuery(String queryString, boolean evaluationEnabled)
          Uses QueryParser to create a new Query with the option to disable evaluation.
protected  String escape(String word)
          Escape the word (whether it requires escaping or not).
abstract  ResultList<ResultItem> execute()
           
protected  int getCurrentOffset(int i)
          Deprecated. instead use getOffset() + i
protected  TokenEvaluationEngine getEngine()
          Use this always instead of context.getTokenEvaluationEngine() because the command could be running off a different query string.
protected  String getFieldFilter(LeafClause clause)
          Returns null when no field exists.
protected  String getFilter()
           
protected  FilterBuilder getFilterBuilder()
           
protected  int getOffset()
          Returns the offset applicable to this command.
protected  String getParameter(String paramName)
          Returns parameter value.
 Query getQuery()
          Use this always instead of datamodel.getQuery().getQuery() because the command could be running off a different query string.
protected  QueryBuilder getQueryBuilder()
           
protected  String getQueryRepresentation()
           
protected  Collection<String> getReservedWords()
           
protected  int getResultsToReturn()
           
 BaseSearchConfiguration getSearchConfiguration()
          Returns the configuration associated with this search command.
protected  ResultList<ResultItem> getSearchResult(String id, DataModel datamodel)
          Get the results from another search command waiting if neccessary.
protected  String getSingleParameter(String paramName)
          Deprecated. use getParameter(string) instead
 String getTransformedQuery()
          Returns the query as it is after the query transformers and command specific query builder have been applied to it.
protected  String getTransformedQuerySesamSyntax()
          Returns the query as it is after the query transformers have been applied to it.
protected  Map<Clause,String> getTransformedTerms()
           
protected  String getUserSortBy()
          Returns the userSortBy applicable to this command and request.
 boolean handleCancellation()
          Handles cancelling the command.
protected  void initialiseTransformedTerms(Query query)
          Set (or reset) the transformed terms back to the state before any queryTransformers were run.
 boolean isCancelled()
          Has the command been cancelled.
 boolean isPaginated()
          Can this command provide paginated results.
 boolean isUserSortable()
          Can this command be sorted differently at user's requst.
protected  ResultList<ResultItem> performExecution()
          Handles the execution process.
protected  void performQueryTransformation()
           
protected  void performResultHandling(ResultList<ResultItem> result)
          Perform (delegating out to) all registered result handlers for this command.
protected  void setTransformedQuerySesamSyntax(String sesamSyntax)
           
protected  void statisticsInfo(String msg)
           
 String toString()
           
protected  void updateTransformedQuerySesamSyntax()
           
protected  void visitXorClause(no.sesat.commons.visitor.Visitor visitor, XorClause clause)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DUMP

protected static final Logger DUMP

context

protected final transient SearchCommand.Context context
The context to work against.


untransformedQuery

protected final String untransformedQuery

datamodel

protected final transient DataModel datamodel

datamodelParameters

protected final transient Map<String,StringDataObject> datamodelParameters

completed

protected volatile boolean completed
Constructor Detail

AbstractSearchCommand

public AbstractSearchCommand(SearchCommand.Context cxt)
Default constructor. Only constructor.

Parameters:
cxt - The context to execute in.
Method Detail

initialiseTransformedTerms

protected final void initialiseTransformedTerms(Query query)
Set (or reset) the transformed terms back to the state before any queryTransformers were run.

Parameters:
query - the query that the transformedTerms map will be constructed from. This should match getQuery()

execute

public abstract ResultList<ResultItem> execute()

getQuery

public Query getQuery()
Use this always instead of datamodel.getQuery().getQuery() because the command could be running off a different query string.

Returns:

getTransformedQuery

public String getTransformedQuery()
Returns the query as it is after the query transformers and command specific query builder have been applied to it.

Returns:
The transformed query.

toString

public String toString()
Overrides:
toString in class Object

getSearchConfiguration

public BaseSearchConfiguration getSearchConfiguration()
Description copied from interface: SearchCommand
Returns the configuration associated with this search command. Typically delegates to the context provided.

Specified by:
getSearchConfiguration in interface SearchCommand
Returns:
The search configuration.

call

public ResultList<ResultItem> call()
Called by thread executor

Specified by:
call in interface Callable<ResultList<ResultItem>>
Specified by:
call in interface SearchCommand
Returns:

handleCancellation

public boolean handleCancellation()
Handles cancelling the command. Inserts an "-1" result list. And does the result handling on it. Returns true if cancellation action was taken.

Specified by:
handleCancellation in interface SearchCommand
Returns:
if cleaning was actually performed

isCancelled

public boolean isCancelled()
Has the command been cancelled. Calling this method only makes sense once the call() method has been.

Specified by:
isCancelled in interface SearchCommand
Returns:
true if cancelled.

constructQueryBuilder

protected QueryBuilder constructQueryBuilder(SearchCommand.Context cxt,
                                             QueryBuilder.Context queryBuilderContext)
Construct from scratch, and return the query builder to use. Default implementation returns the query builder that is configured from the BaseSearchConfiguration.
This method is intended to be overridden, but it called from the constructor. So it is important the overrides do not reference "this", or any other fields as they will likely not be initialised yet.

Parameters:
cxt - search command's context
queryBuilderContext - the query builder context
Returns:

getReservedWords

protected Collection<String> getReservedWords()

visitXorClause

protected void visitXorClause(no.sesat.commons.visitor.Visitor visitor,
                              XorClause clause)
Parameters:
visitor -
clause -

getSearchResult

protected final ResultList<ResultItem> getSearchResult(String id,
                                                       DataModel datamodel)
                                                throws InterruptedException
Get the results from another search command waiting if neccessary.

Parameters:
id -
datamodel -
Returns:
Throws:
InterruptedException

performQueryTransformation

protected void performQueryTransformation()

performExecution

protected final ResultList<ResultItem> performExecution()
Handles the execution process. Will determine whether to call execute() and wrap it with timing info.

Returns:

performResultHandling

protected final void performResultHandling(ResultList<ResultItem> result)
Perform (delegating out to) all registered result handlers for this command. Also performs some hardcoded result handling, eg DataModelResultHandler.

Parameters:
result -

getCurrentOffset

protected int getCurrentOffset(int i)
Deprecated. instead use getOffset() + i

Returns the offset in the result set. If paging is enabled for the current search configuration the offset to the current page will be added to the parameter.

Parameters:
i - the current offset.
Returns:
i plus the offset of the current page.

getOffset

protected int getOffset()
Returns the offset applicable to this command. Zero if the command has no "offset" navigator configured, the value of the offset parameter otherwise.

Returns:
the offset.

isPaginated

public boolean isPaginated()
Description copied from interface: SearchCommand
Can this command provide paginated results.

Specified by:
isPaginated in interface SearchCommand
Returns:
true if results can be paginated.

getUserSortBy

protected String getUserSortBy()
Returns the userSortBy applicable to this command and request. Null if the command has no "sort" navigator configured, the value of the user's userSortBy parameter. This method does not return any command configuration's sort-by attribute (as some subclasses have).

Returns:
the userSortBy. returns null when false == isUserSortable().

isUserSortable

public boolean isUserSortable()
Description copied from interface: SearchCommand
Can this command be sorted differently at user's requst.

Specified by:
isUserSortable in interface SearchCommand
Returns:
true if user sorting is applicable.

getParameter

protected String getParameter(String paramName)
Returns parameter value. Changed since 2.16.1 so that only request parameters are searched.

Parameters:
paramName - the name of the parameter to look for.
Returns:
the parameter value, unescaped, or null if parameter does not exist.

getQueryBuilder

protected QueryBuilder getQueryBuilder()

getQueryRepresentation

protected String getQueryRepresentation()

getFilterBuilder

protected FilterBuilder getFilterBuilder()

getFilter

protected String getFilter()
Returns:

getTransformedTerms

protected final Map<Clause,String> getTransformedTerms()

getSingleParameter

protected final String getSingleParameter(String paramName)
Deprecated. use getParameter(string) instead

Get a string parameter (first if array exists).

Parameters:
paramName - parameter name
Returns:
null when array is null

getEngine

protected TokenEvaluationEngine getEngine()
Use this always instead of context.getTokenEvaluationEngine() because the command could be running off a different query string.

Returns:

createQuery

protected final AbstractSearchCommand.ReconstructedQuery createQuery(String queryString)
Uses QueryParser to create a new Query with all evaluation enabled. XXX Very expensive method to call! Consider disabling evaluation.

Parameters:
queryString - the new query string to parse.
Returns:
newly constructed Query.

createQuery

protected final AbstractSearchCommand.ReconstructedQuery createQuery(String queryString,
                                                                     boolean evaluationEnabled)
Uses QueryParser to create a new Query with the option to disable evaluation. XXX Very expensive method to call! It helps to disable evaluation.

Parameters:
queryString - the new query string to parse.
evaluationEnabled - whether to enable evaluation. if false the DeadTokenEvaluationEngineImpl is used.
Returns:
newly constructed Query.

escape

protected String escape(String word)
Escape the word (whether it requires escaping or not). Default escaping for strings is to enclose in quotes, ie to phrase the word. Default escaping for the ':' character is "\\:". Override this to match back-end (index) specific escaping.

Parameters:
word - The term to escape
Returns:
The escaped version of term.

getFieldFilter

protected final String getFieldFilter(LeafClause clause)
Returns null when no field exists.

Parameters:
clause -
Returns:

statisticsInfo

protected final void statisticsInfo(String msg)

getTransformedQuerySesamSyntax

protected String getTransformedQuerySesamSyntax()
Returns the query as it is after the query transformers have been applied to it. It is normalised.

Returns:

updateTransformedQuerySesamSyntax

protected void updateTransformedQuerySesamSyntax()

setTransformedQuerySesamSyntax

protected void setTransformedQuerySesamSyntax(String sesamSyntax)

addFilterString

protected void addFilterString(String filter)
Makes presumption that filter is in format "field:value". Must be overridden if QueryTransformers return filters in an alternative format.

Parameters:
filter -

getResultsToReturn

protected int getResultsToReturn()
Returns:


Copyright © 2005-2009 Schibsted ASA. All Rights Reserved.