The indexing process is split up into crawling, fetching URL resource,
and generating the index.
</p>
<p>
The searching process is split up into searching,
and feeding search result into the
Apache Cocoon pipeline.
</p>
<s2 title="Crawling">
<p>
The crawling process is specified by
</p>
<ol>
<li>Base URL to start crawling from</li>
<li>Included, and excluded URLs</li>
<li>Cocoon view to use for requesting links from an XML resource</li>
</ol>
<p>
Specifying the base URL determines the protocol for fetching XML resources.
The implementation offers to specify <code>http:</code> URLs,
crawling an Apache Cocoon instance deployed in a servlet-engine.
Alternatively you may specify an URI, e.g.: <code>/documents/index.html</code>,
offering to crawl the local Apache Cocoon instance only, either
servlet-deployed, or in commandline-mode.
</p>
</s2>
<s2 title="Fetching URL resource">
<p>
This processing step fetches the URL resource from Apache Cocoon.
</p>
<p>
Apache Cocoon offers the feature of views.
This feature is used to fetch the 'bare' content of an URL.
</p>
<p>
The crawling component described above is used by the this processing step
to retrieve a link of an XML document.
The link name is augmented by a cocoon view name for fetching the XML resource.
</p>
<p>
The Avalon component <code>CocoonCrawler</code> defines the interface
of a crawler.
</p>
<p>
The Avalon component <code>SimpleCocoonCrawlerImpl</code> is the implementation.
It can be configured to use a specific view, or default to the 'content' view.
</p>
</s2>
<s2 title="Generating index">
<p>
A xml resource is fed into a indexing engine.
Generating an index specifies which elements of an XML resources
should get indexed, how the elements are stored in the index.
Moreover the physical file location of the index is specified by
this processing step.
</p>
<p>
The current implementation splits up an XML resource the following way:
</p>
<ul>
<li>Use an Lucene Analyzer for splitting up text</li>
<li>Each XML element is indexed using its name as Lucene field name.</li>
<li>Each XML attribute is indexed using its element name and the attribute name
as field name. An attribute has following field name
<code>{element-name}@{attribute-name}</code>.
</li>
<li>XML elements that match the names you configured in cocoon.xconf are added as stored fields.</li>
</ul>
<p>
The Avalon component <code>LuceneCocoonIndexer</code> defines the interface
of an indexer.
</p>
<p>
The Avalon component <code>LuceneXMLIndexer</code> defines an interface
for building an lucene index from an XML document. It uses an SAX content handler
for parsing an XML document, and generating Lucene fields, the current
index layout is implemented by <code>SimpleLuceneXMLIndexerImpl</code>,
and <code>LuceneIndexContentHandler</code>.
</p>
</s2>
<s2 title="Searching">
<p>
This process uses a search engine for querying the index.
The input of this process is a search query string, the result is the
search result of the search engine.
</p>
<p>
The Avalon component <code>LuceneCocoonSearcher</code> defines an interface
for searching a Lucene index.
</p>
</s2>
<s2 title="Feeding Search Results">
<p>
This is the final step for presenting information stored in the index.
The result of search engine is feed into the Cocoon processing pipeline.
</p>
<p>
A GUI for the searching process may be developed using any
java enabled script language, like JSP, or XSP.
Moreover a sitemap generator component <code>SearchGenerator</code>
is provided which transforms the search result to XML, and feeds it
into the Cocoon processing pipeline.
</p>
</s2>
</s1>
<s1 title="Interdependencies">
<p>
As both Avalon components <code>LuceneXMLIndexer</code>, and
<code>LuceneCocoonSearcher</code> may use the same Lucene index, you must
take care of the Lucene index structure in both components.
</p>
<p>
The current implementation uses following Lucene index layout
</p>
<ul>
<li>Lucene field <code>body</code> indexed field of the pure text of an XML document.
The <code>body</code> field is the default field name for searching. Thus the
query-string <code>foo</code>, and <code>body:foo</code> is equivalent.
</li>
<li>Each XML element generates a Lucene field having the same name as the XML element name.
For example searching for occurences of <code>Cocoon</code> inside of an XML abstract
element, use query-string <code>abstact:Cocoon</code>.
</li>
<li>Each XML attribute generates a Lucene field having the name
<code>{element-name}@{attribute-name}</code>.
For example searching for occurrences of <code>Cocoon</code> inside of an XML title attribute
of s1 element, use query-string <code>s1@title:Cocoon</code>.
</li>
<li>
The Lucene field <code>url</code> stores the URI of the indexed document. As
all fields described above are only indexed information, and no XML document
is stored inside the Lucene index, this field is the only reference to the
XML document resource.
</li>
<li>
The Lucene field <code>uid</code> stores an unique id for implementing updating
the index. This field is used for checking if the XML resource is newer than
the information stored in the Lucene index.
</li>
<li>
Further Stored fields can be added, depending on your configuration.
Stored fields are returned in the hits found by the engine.
</li>
</ul>
</s1>
<s1 title="Configuration">
<p>
Configuring the indexing, and searching Avalon components is specified
in the <code>cocoon.xconf</code> file.
</p>
<s2 title="example">
<p>This would set up the crawler to crawl all of your site, except pages in the 'search' section, also we are telling the crawler to use a non-standard cocoon-view for getting the links in documents, called <code>my-search-links</code>. </p>
<p>This tells the indexer to use the non-standard 'my-search-content' view to retrieve the content for indexing. Also it tells the indexer that we would like to have any <code>title</code> or <code>subtitle</code> XML elements in the document added to the index as stored fields, so they can be retrieved and displayed to the user with any hits they get.</p>
SearchGenerator is sitemap generator and is available in
the package <code>org.apache.cocoon.generation</code>.
</p>
<p>
The package <code>org.apache.cocoon.components.crawler</code> holds
all crawling relevant sources.
</p>
</s1>
<s1 title="WebApp Sample usage">
<p>
The Cocoon sample webapplication has a link for generating,
an index of the Cocoon documentation, and searching the
Cocoon documentation.
</p>
<p>
The following list describes step by step how to make use of
webapp sample page:
</p>
<ol>
<li>Go to the page "Search the docs".
</li>
<li>Create an index, follow the link "create".
Creating an index may take some time, as the implementation
accesses the XML resources via http: protocol.
</li>
<li>Next you may query the index, by following the
link "XSP", or "Cocoon Generators". Typing in a query will
result in the table of hits orderer by relevance.
</li>
</ol>
<p>
As a result of the creation step, there should exist an
Lucene index in the directory <code>index</code>
below the temporary working directory of the servlet engine.
</p>
<p>
The "XSP" link for searching shows an XSP implementation of
invoking the Avalon component <code>CocoonSearch</code>.
Using this approach gives fine grained control
over the searching process.
</p>
<p>
The "Cocoon Generator" links defines in the sitemap using
the SearchGenerator, and transforming the XML search result to HTML.
This approach tries to minimize your effort of using searching,
as you need to adapt the XSLT transformation step only to your
needs.
</p>
</s1>
<s1 title="Extending the Sample">
<p>
It is easy to extend the search sample to display more information about the search hit than just the url of the resource.</p>
<p>In order to show, for example, the title and summary of a document, these first need to be added to the search index as 'Stored Fields'. Then when the documents are found during a search, that information is available to display, from the search engine itself.</p>
<p>First, decide which fields you want to store.</p>
<p>Decide where is the best place in your pipeline for content to be extracted for indexing, it might not always be the default view 'content'.</p>
<p>Next, decide if you need an XSLT transformation on your documents, to make them more suitable for indexing. This may include deciding on one of several titles in your document, what part of your document gets added to the summary etc. You might want to strip certain tags out because you don't want their content searched. You might be able to raise hit scores on documents by re-arranging content, or keeping larger amounts of content in fewer tags.</p>
<p>Now you tell the search engine (in cocoon.xconf) which tags you'd like storing.</p>
<p>This example tells the indexer to store any tags called 'title' or 'summary' it finds in your documents. It also tells the indexer to get it's content from the view called 'search-content'.</p>
<source><![CDATA[
<map:view from-label="search" name="search">
<map:transform src="search-filter.xsl"/>
<map:serialize type="xml"/>
</map:view>
]]></source>
<p>This is how you might setup that custom view in your sitemap. You would then add a label attribute <code>label="search"</code> to the appropriate place in your pipelines. See the section on views for more information.</p>
<p>After you have re-indexed the site, when you do searches, the new fields will be available in the XML output by Lucene, in the form of a <code>search:field</code> tag, you will need to modify your XSLT that displays the hits to show this.</p>
<p>This is how the search sample's xslt might be changed. All the fields you made for each document are available to you as <code>search:field</code> elements in the <code>search:hit</code> elements. The code above assumes you only had one 'title' and one 'summary' per document.</p>
</s1>
<s1 title="Summary">
<p>
This document gives an overview of the components for
using an indexing, and searching engine in Cocoon.
It described the component decomposition of the Cocoon