Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.cocoon.generation
Class SearchGenerator  view SearchGenerator download SearchGenerator.java

java.lang.Object
  extended byAbstractLoggable
      extended byorg.apache.cocoon.xml.AbstractXMLProducer
          extended byorg.apache.cocoon.generation.AbstractGenerator
              extended byorg.apache.cocoon.generation.ComposerGenerator
                  extended byorg.apache.cocoon.generation.SearchGenerator
All Implemented Interfaces:
Generator, org.apache.cocoon.sitemap.SitemapModelComponent, org.apache.cocoon.xml.XMLProducer

public class SearchGenerator
extends ComposerGenerator

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.

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.java,v 1.8.2.1 2002/09/06 03:35:33 vgritsenko Exp $

Field Summary
private  org.xml.sax.helpers.AttributesImpl atts
          Attributes used when generating xml content.
protected static java.lang.String CDATA
          Description of the Field
protected static java.lang.String COUNT_OF_PAGES_ATTRIBUTE
          Attribute count-of-pages of hits element.
protected static java.lang.String DATE_ATTRIBUTE
          Attribute date of results element.
protected static java.lang.String FIELD_ELEMENT
          Child element field of the hit element.
protected static java.lang.String HAS_NEXT_ATTRIBUTE
          Attribute has-next of navigation-page element.
protected static java.lang.String HAS_PREVIOUS_ATTRIBUTE
          Attribute has-next of navigation-page element.
protected static java.lang.String HIT_ELEMENT
          Child element of generated xml content, ie hit.
protected static java.lang.String HITS_ELEMENT
          Child element of generated xml content, ie hits.
private  java.io.File index
          Absolute filesystem directory of lucene index directory
protected static java.lang.String INDEX_PARAM
          Setup parameter name of index directory, ie index.
protected static java.lang.String INDEX_PARAM_DEFAULT
          Default value of setup parameter index, ie index.
private  org.apache.cocoon.components.search.LuceneCocoonSearcher lcs
          The avalon component to use for searching.
protected static java.lang.String namespace
          The XML namespace for the output document.
protected static java.lang.String NAVIGATION_ELEMENT
          Child element of generated xml content, ie navigation.
protected static java.lang.String NAVIGATION_PAGE_ELEMENT
          Child element of generated xml content, ie navigation.
protected static java.lang.String NEXT_INDEX_ATTRIBUTE
          Attribute next-index of navigation-page element.
protected static java.lang.String PAGE_LENGTH_ATTRIBUTE
          Attribute page-length of results element.
protected static int PAGE_LENGTH_DEFAULT
          Description of the Field
protected static java.lang.String PAGE_LENGTH_PARAM
          Setup parameter name specifying the name of page-length query parameter, ie page-length.
protected static java.lang.String PAGE_LENGTH_PARAM_DEFAULT
          Description of the Field
private  java.lang.Integer pageLength
          pageLength of query parameter
protected static java.lang.String PREVIOUS_INDEX_ATTRIBUTE
          Attribute previous-index of navigation-page element.
protected static java.lang.String QUERY_STRING_ATTRIBUTE
          Attribute query-string of results element.
protected static java.lang.String QUERY_STRING_PARAM
          Setup parameter name specifying the name of query-string query parameter, ie query-string.
protected static java.lang.String QUERY_STRING_PARAM_DEFAULT
          Default value of setup parameter query-string, ie queryString.
private  java.lang.String queryString
          Query-string to search for
protected static java.lang.String RANK_ATTRIBUTE
          Attribute rank of hit element.
protected static java.lang.String RESULTS_ELEMENT
          Root element of generated xml content, ie results.
protected static java.lang.String SCORE_ATTRIBUTE
          Attribute score of hit element.
protected static java.lang.String START_INDEX_ATTRIBUTE
          Attribute start-index of results element.
protected static int START_INDEX_DEFAULT
          Description of the Field
protected static java.lang.String START_INDEX_NEXT_PARAM
          Setup parameter name specifying the name of start-next-index query parameter, ie start-next-index.
protected static java.lang.String START_INDEX_NEXT_PARAM_DEFAULT
          Default value of setup parameter start-next-index, ie startNextIndex.
protected static java.lang.String START_INDEX_PARAM
          Setup parameter name specifying the name of start-index query parameter, ie start-index.
protected static java.lang.String START_INDEX_PARAM_DEFAULT
          Default value of setup parameter start-index, ie startIndex.
protected static java.lang.String START_INDEX_PREVIOUS_PARAM
          Setup parameter name specifying the name of start-previous-index query parameter, ie start-previous-index.
protected static java.lang.String START_INDEX_PREVIOUS_PARAM_DEFAULT
          Default value of setup parameter start-previous-index, ie startPreviousIndex.
private  java.lang.Integer startIndex
          startIndex of query parameter
protected static java.lang.String TOTAL_COUNT_ATTRIBUTE
          Attribute total-count of hits element.
protected static java.lang.String URI_ATTRIBUTE
          Attribute uri of hit element.
private  java.io.File workDir
          Default home directory of index directories.
protected static java.lang.String xlinkNamespace
          The XML namespace for xlink
 
Fields inherited from class org.apache.cocoon.generation.ComposerGenerator
manager
 
Fields inherited from class org.apache.cocoon.generation.AbstractGenerator
objectModel, parameters, resolver, source
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.cocoon.generation.Generator
ROLE
 
Constructor Summary
SearchGenerator()
           
 
Method Summary
private  org.apache.cocoon.components.search.LuceneCocoonPager buildHits()
          Build hits from a query input, and setup paging object.
 void compose(ComponentManager manager)
          Set the current ComponentManager instance used by this Composable.
 void contextualize(Context context)
          Contextualize this class.
private  java.lang.Integer createInteger(java.lang.String s)
          Create an Integer.
 void dispose()
          Release all resources.
 void generate()
          Generate xml content describing search results.
private  void generateHit(org.apache.cocoon.components.search.LuceneCocoonPager pager)
          Generate the xml content for each hit.
private  void generateHits(org.apache.cocoon.components.search.LuceneCocoonPager pager)
          Generate the xml content of all hits
private  void generateNavigation(org.apache.cocoon.components.search.LuceneCocoonPager pager)
          Generate the navigation element.
private  void generateResults()
          Build and generate the search results.
 void initialize()
           
 void recycle()
          Recycle the generator
 void setup(org.apache.cocoon.environment.SourceResolver resolver, java.util.Map objectModel, java.lang.String src, Parameters par)
          setup all members of this generator.
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
 
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 java.lang.String namespace
The XML namespace for the output document.

See Also:
Constant Field Values

xlinkNamespace

protected static final java.lang.String xlinkNamespace
The XML namespace for xlink

See Also:
Constant Field Values

CDATA

protected static final java.lang.String CDATA
Description of the Field

See Also:
Constant Field Values

RESULTS_ELEMENT

protected static final java.lang.String RESULTS_ELEMENT
Root element of generated xml content, ie results.

See Also:
Constant Field Values

DATE_ATTRIBUTE

protected static final java.lang.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 java.lang.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 java.lang.String START_INDEX_ATTRIBUTE
Attribute start-index of results element. Echos the startIndex query parameter.

See Also:
Constant Field Values

PAGE_LENGTH_ATTRIBUTE

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

See Also:
Constant Field Values

HITS_ELEMENT

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

See Also:
Constant Field Values

TOTAL_COUNT_ATTRIBUTE

protected static final java.lang.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 java.lang.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 java.lang.String HIT_ELEMENT
Child element of generated xml content, ie hit. This element describes a single hit.

See Also:
Constant Field Values

RANK_ATTRIBUTE

protected static final java.lang.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 java.lang.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 java.lang.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 java.lang.String FIELD_ELEMENT
Child element field of the hit element. This element contains value of the stored field of a hit.

Since:
2.0.4
See Also:
Constant Field Values

NAVIGATION_ELEMENT

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

See Also:
Constant Field Values

NAVIGATION_PAGE_ELEMENT

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

See Also:
Constant Field Values

HAS_NEXT_ATTRIBUTE

protected static final java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.String INDEX_PARAM
Setup parameter name of index directory, ie index.

See Also:
Constant Field Values

INDEX_PARAM_DEFAULT

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

See Also:
Constant Field Values

QUERY_STRING_PARAM

protected static final java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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
Description of the Field

Since:
See Also:
Constant Field Values

PAGE_LENGTH_PARAM

protected static final java.lang.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 java.lang.String PAGE_LENGTH_PARAM_DEFAULT
Description of the Field

Since:
See Also:
Constant Field Values

PAGE_LENGTH_DEFAULT

protected static final int PAGE_LENGTH_DEFAULT
Description of the Field

Since:
See Also:
Constant Field Values

workDir

private java.io.File workDir
Default home directory of index directories.

Releative index directories specified in the setup of this generator are resolved relative to this directory.

By default this directory is set to the WORKING_DIR of Cocoon.


lcs

private org.apache.cocoon.components.search.LuceneCocoonSearcher lcs
The avalon component to use for searching.


index

private java.io.File index
Absolute filesystem directory of lucene index directory


queryString

private java.lang.String queryString
Query-string to search for


atts

private final org.xml.sax.helpers.AttributesImpl atts
Attributes used when generating xml content.


startIndex

private java.lang.Integer startIndex
startIndex of query parameter


pageLength

private java.lang.Integer pageLength
pageLength of query parameter

Constructor Detail

SearchGenerator

public SearchGenerator()
Method Detail

compose

public void compose(ComponentManager manager)
             throws ComponentException
Set the current ComponentManager instance used by this Composable.

Overrides:
compose in class ComposerGenerator

setup

public void setup(org.apache.cocoon.environment.SourceResolver resolver,
                  java.util.Map objectModel,
                  java.lang.String src,
                  Parameters par)
           throws org.apache.cocoon.ProcessingException,
                  org.xml.sax.SAXException,
                  java.io.IOException
setup all members of this generator.

Specified by:
setup in interface org.apache.cocoon.sitemap.SitemapModelComponent
Overrides:
setup in class AbstractGenerator
Since:

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.

Since:

initialize

public void initialize()
                throws java.io.IOException

generate

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

Since:

createInteger

private java.lang.Integer createInteger(java.lang.String s)
Create an Integer.

Create an Integer from String s, iff conversion fails return null.

Since:

generateResults

private void generateResults()
                      throws org.xml.sax.SAXException,
                             org.apache.cocoon.ProcessingException
Build and generate the search results.

First build the hits, next generate xml content from the hits, taking page index, and length into account.

Since:

generateHits

private void generateHits(org.apache.cocoon.components.search.LuceneCocoonPager pager)
                   throws org.xml.sax.SAXException
Generate the xml content of all hits

Since:

generateHit

private void generateHit(org.apache.cocoon.components.search.LuceneCocoonPager pager)
                  throws org.xml.sax.SAXException
Generate the xml content for each hit.

Since:

generateNavigation

private void generateNavigation(org.apache.cocoon.components.search.LuceneCocoonPager pager)
                         throws org.xml.sax.SAXException
Generate the navigation element.

Since:

buildHits

private org.apache.cocoon.components.search.LuceneCocoonPager buildHits()
                                                                 throws org.apache.cocoon.ProcessingException
Build hits from a query input, and setup paging object.

Since:

recycle

public void recycle()
Recycle the generator

Overrides:
recycle in class AbstractGenerator

dispose

public void dispose()
Description copied from class: ComposerGenerator
Release all resources.

Overrides:
dispose in class ComposerGenerator