org.apache.cocoon.generation
Class SearchGenerator

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.xml.AbstractXMLProducer
          extended by org.apache.cocoon.generation.AbstractGenerator
              extended by org.apache.cocoon.generation.ServiceableGenerator
                  extended by org.apache.cocoon.generation.SearchGenerator
All Implemented Interfaces:
Poolable, Recyclable, Disposable, Component, Contextualizable, LogEnabled, Serviceable, Generator, SitemapModelComponent, XMLProducer

public class SearchGenerator
extends ServiceableGenerator
implements Contextualizable

Generates an XML representation of a search result.

This generator generates xml content representening an XML search. The generated xml content contains the search result, the search query information, and navigation information about the search results. The query is sent to the generator, either via the 'queryString' request parameter or the 'query' SiteMap parameter. The sitemap overides the request.

Search xml sample generated by this generator:


 <?xml version="1.0" encoding="UTF-8"?>

 <search:results date="1008437081064" query-string="cocoon"
     start-index="0" page-length="10"
     xmlns:search="http://apache.org/cocoon/search/1.0"
     xmlns:xlink="http://www.w3.org/1999/xlink">
   <search:hits total-count="125" count-of-pages="13">
     <search:hit rank="0" score="1.0"
         uri="http://localhost:8080/cocoon/documents/hosting.html">
       <search:field name="title">Document Title<search:field/>
     <search:hit/>
     ...
   </search:hits>

   <search:navigation total-count="125" count-of-pages="13"
       has-next="true" has-previous="false" next-index="10" previous-index="0">
     <search:navigation-page start-index="0"/>
     <search:navigation-page start-index="10"/>
     ...
     <search:navigation-page start-index="120"/>
   </search:navigation>
 </search:results>
 

Version:
CVS $Id: SearchGenerator.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Bernhard Huber, Vadim Gritsenko, Jeremy Quinn, Conal Tuohy

Field Summary
protected static String ANALYZER_PARAM
          Setup parameter name of analyzer name, ie analyzer.
protected static String ANALYZER_PARAM_DEFAULT
          Default value of analyzer parameter analyzer, ie org.apache.lucene.analysis.standard.StandardAnalyzer.
protected static String CDATA
          Description of the Field
protected static String COUNT_OF_PAGES_ATTRIBUTE
          Attribute count-of-pages of hits element.
protected static String DATE_ATTRIBUTE
          Attribute date of results element.
protected static String FIELD_ELEMENT
          Child element field of the hit element.
protected static String HAS_NEXT_ATTRIBUTE
          Attribute has-next of navigation-page element.
protected static String HAS_PREVIOUS_ATTRIBUTE
          Attribute has-next of navigation-page element.
protected static String HIT_ELEMENT
          Child element of generated xml content, ie hit.
protected static String HITS_ELEMENT
          Child element of generated xml content, ie hits.
protected static String INDEX_PARAM
          Setup parameter name of index directory, ie index.
protected static String INDEX_PARAM_DEFAULT
          Default value of setup parameter index, ie index.
protected static String NAME_ATTRIBUTE
          Attribute name of hit element.
protected static String NAMESPACE
          The XML namespace for the output document.
protected static String NAVIGATION_ELEMENT
          Child element of generated xml content, ie navigation.
protected static String NAVIGATION_PAGE_ELEMENT
          Child element of generated xml content, ie navigation-page.
protected static String NEXT_INDEX_ATTRIBUTE
          Attribute next-index of navigation-page element.
protected static String PAGE_LENGTH_ATTRIBUTE
          Attribute page-length of results element.
protected static int PAGE_LENGTH_DEFAULT
           
protected static String PAGE_LENGTH_PARAM
          Setup parameter name specifying the name of page-length query parameter, ie page-length.
protected static String PAGE_LENGTH_PARAM_DEFAULT
           
protected static String PREFIX
          The XML namespace prefix for the output document.
protected static String PREVIOUS_INDEX_ATTRIBUTE
          Attribute previous-index of navigation-page element.
protected static String Q_FIELD_ELEMENT
          QName of child element search:field of the hit element.
protected static String Q_HIT_ELEMENT
          QName of child element of generated xml content, ie search:hit.
protected static String Q_HITS_ELEMENT
          QName of child element of generated xml content, ie search:hits.
protected static String Q_NAVIGATION_ELEMENT
          QName of child element of generated xml content, ie search:navigation.
protected static String Q_NAVIGATION_PAGE_ELEMENT
          QName of child element of generated xml content, ie search:navigation-page.
protected static String Q_RESULTS_ELEMENT
          Qualified name of root element of generated xml content, ie search:results.
protected static String QUERY_PARAM
          Setup the actual query from generator parameter, ie query.
protected static String QUERY_STRING_ATTRIBUTE
          Attribute query-string of results element.
protected static String QUERY_STRING_PARAM
          Setup parameter name specifying the name of query-string query parameter, ie query-string.
protected static String QUERY_STRING_PARAM_DEFAULT
          Default value of setup parameter query-string, ie queryString.
protected static String RANK_ATTRIBUTE
          Attribute rank of hit element.
protected static String RESULTS_ELEMENT
          Name of root element of generated xml content, ie results.
protected static String SCORE_ATTRIBUTE
          Attribute score of hit element.
protected static String START_INDEX_ATTRIBUTE
          Attribute start-index of results element.
protected static int START_INDEX_DEFAULT
           
protected static String START_INDEX_NEXT_PARAM
          Setup parameter name specifying the name of start-next-index query parameter, ie start-next-index.
protected static String START_INDEX_NEXT_PARAM_DEFAULT
          Default value of setup parameter start-next-index, ie startNextIndex.
protected static String START_INDEX_PARAM
          Setup parameter name specifying the name of start-index query parameter, ie start-index.
protected static String START_INDEX_PARAM_DEFAULT
          Default value of setup parameter start-index, ie startIndex.
protected static String START_INDEX_PREVIOUS_PARAM
          Setup parameter name specifying the name of start-previous-index query parameter, ie start-previous-index.
protected static String START_INDEX_PREVIOUS_PARAM_DEFAULT
          Default value of setup parameter start-previous-index, ie startPreviousIndex.
protected static String TOTAL_COUNT_ATTRIBUTE
          Attribute total-count of hits element.
protected static String URI_ATTRIBUTE
          Attribute uri of hit element.
protected static String XLINK_NAMESPACE
          The XML namespace for xlink
 
Fields inherited from class org.apache.cocoon.generation.ServiceableGenerator
manager
 
Fields inherited from class org.apache.cocoon.generation.AbstractGenerator
objectModel, parameters, resolver, source
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.cocoon.generation.Generator
ROLE
 
Constructor Summary
SearchGenerator()
           
 
Method Summary
 void contextualize(Context context)
          Contextualize this class.
 void generate()
          Generate xml content describing search results.
 void recycle()
          Recycle the generator
 void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
          setup all members of this generator.
 
Methods inherited from class org.apache.cocoon.generation.ServiceableGenerator
dispose, service
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.xml.XMLProducer
setConsumer
 

Field Detail

NAMESPACE

protected static final String NAMESPACE
The XML namespace for the output document.

See Also:
Constant Field Values

PREFIX

protected static final String PREFIX
The XML namespace prefix for the output document.

See Also:
Constant Field Values

XLINK_NAMESPACE

protected static final String XLINK_NAMESPACE
The XML namespace for xlink

See Also:
Constant Field Values

CDATA

protected static final String CDATA
Description of the Field

See Also:
Constant Field Values

RESULTS_ELEMENT

protected static final String RESULTS_ELEMENT
Name of root element of generated xml content, ie results.

See Also:
Constant Field Values

Q_RESULTS_ELEMENT

protected static final String Q_RESULTS_ELEMENT
Qualified name of root element of generated xml content, ie search:results.

See Also:
Constant Field Values

DATE_ATTRIBUTE

protected static final String DATE_ATTRIBUTE
Attribute date of results element. It contains the date a long value, indicating when a search generated this xml content.

See Also:
Constant Field Values

QUERY_STRING_ATTRIBUTE

protected static final String QUERY_STRING_ATTRIBUTE
Attribute query-string of results element. Echos the queryString query parameter.

See Also:
Constant Field Values

START_INDEX_ATTRIBUTE

protected static final String START_INDEX_ATTRIBUTE
Attribute start-index of results element. Echoes the startIndex query parameter.

See Also:
Constant Field Values

PAGE_LENGTH_ATTRIBUTE

protected static final String PAGE_LENGTH_ATTRIBUTE
Attribute page-length of results element. Echoes the pageLenth query parameter.

See Also:
Constant Field Values

NAME_ATTRIBUTE

protected static final String NAME_ATTRIBUTE
Attribute name of hit element.

See Also:
Constant Field Values

HITS_ELEMENT

protected static final String HITS_ELEMENT
Child element of generated xml content, ie hits. This element describes all hits.

See Also:
Constant Field Values

Q_HITS_ELEMENT

protected static final String Q_HITS_ELEMENT
QName of child element of generated xml content, ie search:hits. This element describes all hits.

See Also:
Constant Field Values

TOTAL_COUNT_ATTRIBUTE

protected static final String TOTAL_COUNT_ATTRIBUTE
Attribute total-count of hits element. The value describes total number of hits found by the search engine.

See Also:
Constant Field Values

COUNT_OF_PAGES_ATTRIBUTE

protected static final String COUNT_OF_PAGES_ATTRIBUTE
Attribute count-of-pages of hits element. The value describes number of pages needed for all hits.

See Also:
Constant Field Values

HIT_ELEMENT

protected static final String HIT_ELEMENT
Child element of generated xml content, ie hit. This element describes a single hit.

See Also:
Constant Field Values

Q_HIT_ELEMENT

protected static final String Q_HIT_ELEMENT
QName of child element of generated xml content, ie search:hit. This element describes a single hit.

See Also:
Constant Field Values

RANK_ATTRIBUTE

protected static final String RANK_ATTRIBUTE
Attribute rank of hit element. The value describes the count index of this hits, ranging between 0, and total-count minus 1.

See Also:
Constant Field Values

SCORE_ATTRIBUTE

protected static final String SCORE_ATTRIBUTE
Attribute score of hit element. The value describes the score of this hits, ranging between 0, and 1.0.

See Also:
Constant Field Values

URI_ATTRIBUTE

protected static final String URI_ATTRIBUTE
Attribute uri of hit element. The value describes the uri of a document matching the search query.

See Also:
Constant Field Values

FIELD_ELEMENT

protected static final String FIELD_ELEMENT
Child element field of the hit element. This element contains value of the stored field of a hit.

See Also:
Constant Field Values

Q_FIELD_ELEMENT

protected static final String Q_FIELD_ELEMENT
QName of child element search:field of the hit element.

See Also:
Constant Field Values

NAVIGATION_ELEMENT

protected static final String NAVIGATION_ELEMENT
Child element of generated xml content, ie navigation. This element describes some hints for easier navigation.

See Also:
Constant Field Values

Q_NAVIGATION_ELEMENT

protected static final String Q_NAVIGATION_ELEMENT
QName of child element of generated xml content, ie search:navigation.

See Also:
Constant Field Values

NAVIGATION_PAGE_ELEMENT

protected static final String NAVIGATION_PAGE_ELEMENT
Child element of generated xml content, ie navigation-page. This element describes the start-index of page containing hits.

See Also:
Constant Field Values

Q_NAVIGATION_PAGE_ELEMENT

protected static final String Q_NAVIGATION_PAGE_ELEMENT
QName of child element of generated xml content, ie search:navigation-page. This element describes the start-index of page containing hits.

See Also:
Constant Field Values

HAS_NEXT_ATTRIBUTE

protected static final String HAS_NEXT_ATTRIBUTE
Attribute has-next of navigation-page element. The value is true if a next navigation control should be presented.

See Also:
Constant Field Values

HAS_PREVIOUS_ATTRIBUTE

protected static final String HAS_PREVIOUS_ATTRIBUTE
Attribute has-next of navigation-page element. The value is true if a previous navigation control should be presented.

See Also:
Constant Field Values

NEXT_INDEX_ATTRIBUTE

protected static final String NEXT_INDEX_ATTRIBUTE
Attribute next-index of navigation-page element. The value describes the start-index of the next-to-be-presented page.

See Also:
Constant Field Values

PREVIOUS_INDEX_ATTRIBUTE

protected static final String PREVIOUS_INDEX_ATTRIBUTE
Attribute previous-index of navigation-page element. The value describes the start-index of the previous-to-be-presented page.

See Also:
Constant Field Values

INDEX_PARAM

protected static final String INDEX_PARAM
Setup parameter name of index directory, ie index.

See Also:
Constant Field Values

INDEX_PARAM_DEFAULT

protected static final String INDEX_PARAM_DEFAULT
Default value of setup parameter index, ie index.

See Also:
Constant Field Values

ANALYZER_PARAM

protected static final String ANALYZER_PARAM
Setup parameter name of analyzer name, ie analyzer.

See Also:
Constant Field Values

ANALYZER_PARAM_DEFAULT

protected static final String ANALYZER_PARAM_DEFAULT
Default value of analyzer parameter analyzer, ie org.apache.lucene.analysis.standard.StandardAnalyzer.

See Also:
Constant Field Values

QUERY_PARAM

protected static final String QUERY_PARAM
Setup the actual query from generator parameter, ie query.

See Also:
Constant Field Values

QUERY_STRING_PARAM

protected static final String QUERY_STRING_PARAM
Setup parameter name specifying the name of query-string query parameter, ie query-string.

See Also:
Constant Field Values

QUERY_STRING_PARAM_DEFAULT

protected static final String QUERY_STRING_PARAM_DEFAULT
Default value of setup parameter query-string, ie queryString.

See Also:
Constant Field Values

START_INDEX_PARAM

protected static final String START_INDEX_PARAM
Setup parameter name specifying the name of start-index query parameter, ie start-index.

See Also:
Constant Field Values

START_INDEX_PARAM_DEFAULT

protected static final String START_INDEX_PARAM_DEFAULT
Default value of setup parameter start-index, ie startIndex.

See Also:
Constant Field Values

START_INDEX_NEXT_PARAM

protected static final String START_INDEX_NEXT_PARAM
Setup parameter name specifying the name of start-next-index query parameter, ie start-next-index.

See Also:
Constant Field Values

START_INDEX_NEXT_PARAM_DEFAULT

protected static final String START_INDEX_NEXT_PARAM_DEFAULT
Default value of setup parameter start-next-index, ie startNextIndex.

See Also:
Constant Field Values

START_INDEX_PREVIOUS_PARAM

protected static final String START_INDEX_PREVIOUS_PARAM
Setup parameter name specifying the name of start-previous-index query parameter, ie start-previous-index.

See Also:
Constant Field Values

START_INDEX_PREVIOUS_PARAM_DEFAULT

protected static final String START_INDEX_PREVIOUS_PARAM_DEFAULT
Default value of setup parameter start-previous-index, ie startPreviousIndex.

See Also:
Constant Field Values

START_INDEX_DEFAULT

protected static final int START_INDEX_DEFAULT
See Also:
Constant Field Values

PAGE_LENGTH_PARAM

protected static final String PAGE_LENGTH_PARAM
Setup parameter name specifying the name of page-length query parameter, ie page-length.

See Also:
Constant Field Values

PAGE_LENGTH_PARAM_DEFAULT

protected static final String PAGE_LENGTH_PARAM_DEFAULT
See Also:
Constant Field Values

PAGE_LENGTH_DEFAULT

protected static final int PAGE_LENGTH_DEFAULT
See Also:
Constant Field Values
Constructor Detail

SearchGenerator

public SearchGenerator()
Method Detail

contextualize

public void contextualize(Context context)
                   throws ContextException
Contextualize this class.

Especially retrieve the work directory. If the index directory is specified relativly, the working directory is used as home directory of the index directory.

Specified by:
contextualize in interface Contextualizable
Parameters:
context - Context to use
Throws:
ContextException - If contextualizing fails.

setup

public void setup(SourceResolver resolver,
                  Map objectModel,
                  String src,
                  Parameters par)
           throws ProcessingException,
                  SAXException,
                  IOException
setup all members of this generator.

Specified by:
setup in interface SitemapModelComponent
Overrides:
setup in class AbstractGenerator
Throws:
ProcessingException
SAXException
IOException

generate

public void generate()
              throws IOException,
                     SAXException,
                     ProcessingException
Generate xml content describing search results. Entry point of the ComposerGenerator. The xml content is generated from the hits object.

Specified by:
generate in interface Generator
Throws:
IOException - when there is a problem reading the from file system.
SAXException - when there is a problem creating the output SAX events.
ProcessingException - when there is a problem obtaining the hits

recycle

public void recycle()
Recycle the generator

Specified by:
recycle in interface Recyclable
Overrides:
recycle in class AbstractGenerator


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.