fr.gouv.culture.sdx.search.lucene.query
Class AbstractQuery

java.lang.Object
  extended byfr.gouv.culture.sdx.utils.SdxObjectImpl
      extended byfr.gouv.culture.sdx.search.lucene.query.AbstractQuery
All Implemented Interfaces:
org.apache.avalon.framework.logger.LogEnabled, Query, Query, SdxObject, org.apache.cocoon.xml.XMLizable
Direct Known Subclasses:
ComplexQuery, DateIntervalQuery, ExactFieldQuery, FieldQuery, LinearQuery, SimpleQuery

public abstract class AbstractQuery
extends SdxObjectImpl
implements Query, org.apache.avalon.framework.logger.LogEnabled

Abstract class for basic SDX query functionalities.

To implement a new SDX query type, it is better to extend this class which takes care of:

In building a query, one should following the steps to avoid problems:
  1. Create the query, using the constructor
  2. set the logger by calling the enableLogging
  3. build the query by calling the setUp method
  4. prepare the query with the prepare method
  5. use execute method to obtain results

use the toSAX method for info; this method will deliver the best information after the prepare() method has been called

See Also:
enableLogging(org.apache.avalon.framework.logger.Logger), setUp(fr.gouv.culture.sdx.search.lucene.query.SearchLocations, org.apache.lucene.search.Query), prepare(), execute(), toSAX(org.xml.sax.ContentHandler)

Field Summary
protected  int baseOperator
          The operator linking this query to the base query.
protected  Query baseQuery
          The internal Lucene query for the base query.
protected  Results baseResults
          Results of a base query.
protected  AbstractFilter filter
          The filter for this query.
protected  org.apache.lucene.search.Query luceneQuery
          The internal Lucene query for this query.
protected  java.lang.String queryText
          The requested Text, especially for simple or field queries
protected  SearchLocations searchLocations
          A Lucene index to search.
protected  SortSpecification sortSpecification
          The sort specification for this query.
 
Fields inherited from class fr.gouv.culture.sdx.utils.SdxObjectImpl
encoding, logger
 
Fields inherited from interface fr.gouv.culture.sdx.search.lucene.query.Query
defaultOperator, OPERATOR_AND, OPERATOR_NOT, OPERATOR_OR, SEARCH_ENGINE
 
Constructor Summary
AbstractQuery()
           
 
Method Summary
protected  org.xml.sax.helpers.AttributesImpl addAttributesLucene(org.xml.sax.helpers.AttributesImpl atts)
          Factorization of *Query.toSax() components
protected  org.xml.sax.helpers.AttributesImpl addAttributesText(org.xml.sax.helpers.AttributesImpl atts)
          Factorization of *Query.toSax() components
 void addBaseQuery(Query query, int operator)
          Adds a base query to the current query
 void addBaseQuery(Results results, int operator)
          Adds a base query for this query.
 void addFilter(AbstractFilter filter)
          Adds a filter for this query.
 void addSortSpecification(SortSpecification ss)
          Adds a sort specification for this query.
 void enableLogging(org.apache.avalon.framework.logger.Logger logger)
          Sets the logger.
 Results execute()
          Executes the query and return results.
 org.apache.lucene.search.Query getLuceneQuery()
          Returns the internal Lucene query for this query.
static int getOperator(java.lang.String str)
          Returns a query operator from a given string representation.
 SearchLocations getSearchLocations()
           
 AbstractFilter prepare()
          Prepares a query before execution.
 void setLuceneQuery(org.apache.lucene.search.Query lquery)
           
protected  void setSearchLocations(SearchLocations sLocs)
          Sets the SearchLocations object
 void setUp()
          Does nothing here, please see subclasses
 void setUp(SearchLocations sLocs, org.apache.lucene.search.Query lquery)
           
abstract  void toSAX(org.xml.sax.ContentHandler hdl)
          Formats a query in XML.
 
Methods inherited from class fr.gouv.culture.sdx.utils.SdxObjectImpl
getChildLogger, setEncoding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface fr.gouv.culture.sdx.utils.SdxObject
setEncoding
 

Field Detail

luceneQuery

protected org.apache.lucene.search.Query luceneQuery
The internal Lucene query for this query.


queryText

protected java.lang.String queryText
The requested Text, especially for simple or field queries


searchLocations

protected SearchLocations searchLocations
A Lucene index to search.


baseResults

protected Results baseResults
Results of a base query.


baseQuery

protected Query baseQuery
The internal Lucene query for the base query.


baseOperator

protected int baseOperator
The operator linking this query to the base query.


sortSpecification

protected SortSpecification sortSpecification
The sort specification for this query.


filter

protected AbstractFilter filter
The filter for this query.

Constructor Detail

AbstractQuery

public AbstractQuery()
Method Detail

setUp

public void setUp(SearchLocations sLocs,
                  org.apache.lucene.search.Query lquery)
           throws SDXException
Specified by:
setUp in interface Query
Throws:
SDXException

setLuceneQuery

public void setLuceneQuery(org.apache.lucene.search.Query lquery)
Specified by:
setLuceneQuery in interface Query

getLuceneQuery

public org.apache.lucene.search.Query getLuceneQuery()
Returns the internal Lucene query for this query.

Specified by:
getLuceneQuery in interface Query

execute

public Results execute()
                throws SDXException
Executes the query and return results.

Specified by:
execute in interface Query
Throws:
SDXException

getOperator

public static int getOperator(java.lang.String str)
Returns a query operator from a given string representation.

The values accepted are :

  1. and ; et for the logical AND operator
  2. or ; ou for the logical OR operator
  3. not ; sauf for the logical NOT operator
  4. Parameters:
    str - The string representation of the operator.
    Returns:
    The operator ; if the string representation does'nt match any operator, OPERATOR_AND is returned.

addBaseQuery

public void addBaseQuery(Results results,
                         int operator)
Adds a base query for this query.

A base query is another query, given by its search results, that will be combined with the current query with a logical operator (AND, OR or NOT).

Using the AND operator is equivalent to "searching within results". Using the OR operator lets one extend a query. Using the NOT operator lets one eclude some previous results.

Specified by:
addBaseQuery in interface Query
Parameters:
results - Results from the base query.
operator - The operator to use.

addBaseQuery

public void addBaseQuery(Query query,
                         int operator)
Description copied from interface: Query
Adds a base query to the current query

Specified by:
addBaseQuery in interface Query
Parameters:
query - The query object
operator - The operator linking the query with the base query

addSortSpecification

public void addSortSpecification(SortSpecification ss)
Adds a sort specification for this query.

Specified by:
addSortSpecification in interface Query
Parameters:
ss - The sort specification.

addFilter

public void addFilter(AbstractFilter filter)
Adds a filter for this query.

Specified by:
addFilter in interface Query
Parameters:
filter - The filter to add.

prepare

public AbstractFilter prepare()
Prepares a query before execution.

Queries needing a specifc action can override this method that only returns the current filter.

Specified by:
prepare in interface Query
Returns:
A filter defined for this query.

enableLogging

public void enableLogging(org.apache.avalon.framework.logger.Logger logger)
Sets the logger.

Specified by:
enableLogging in interface org.apache.avalon.framework.logger.LogEnabled
Overrides:
enableLogging in class SdxObjectImpl
Parameters:
logger - The logger.

addAttributesLucene

protected org.xml.sax.helpers.AttributesImpl addAttributesLucene(org.xml.sax.helpers.AttributesImpl atts)
                                                          throws org.xml.sax.SAXException,
                                                                 org.apache.cocoon.ProcessingException
Factorization of *Query.toSax() components

Parameters:
atts - current atts to had attributes
Throws:
org.xml.sax.SAXException
org.apache.cocoon.ProcessingException

addAttributesText

protected org.xml.sax.helpers.AttributesImpl addAttributesText(org.xml.sax.helpers.AttributesImpl atts)
                                                        throws org.xml.sax.SAXException,
                                                               org.apache.cocoon.ProcessingException
Factorization of *Query.toSax() components

Parameters:
atts - current atts to had attributes
Throws:
org.xml.sax.SAXException
org.apache.cocoon.ProcessingException

toSAX

public abstract void toSAX(org.xml.sax.ContentHandler hdl)
                    throws org.xml.sax.SAXException,
                           org.apache.cocoon.ProcessingException
Formats a query in XML.

Specified by:
toSAX in interface Query
Parameters:
hdl - A content handler to receive XML data.
Throws:
org.xml.sax.SAXException
org.apache.cocoon.ProcessingException

setSearchLocations

protected void setSearchLocations(SearchLocations sLocs)
                           throws SDXException
Sets the SearchLocations object

Parameters:
sLocs - The SearchLocations object
Throws:
SDXException

setUp

public void setUp()
Does nothing here, please see subclasses


getSearchLocations

public SearchLocations getSearchLocations()
Specified by:
getSearchLocations in interface Query


Copyright © 2000-2004 Ministere de la culture et de la communication / AJLSM. All Rights Reserved.