<?xml version="1.0"?>
<!--
  Copyright 2002-2004 The Apache Software Foundation or its licensors,
  as applicable.
                                                                                                    
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
                                                                                                    
      http://www.apache.org/licenses/LICENSE-2.0
                                                                                                    
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- ===============================================
Pipelines relevant to Lucene index creation and searching.

Creates lucene:documents from Forrest documents, to be used for indexing
by the LuceneIndexTransformer.

Aggregates all lucene:documents from a site into a single lucene:index
document.

Uses the LuceneIndexTransformer to create a Lucene index from this
lucene:index document.

Allows searching the Lucene index using the Cocoon SearchGenerator.

Generates   :  Lucene lucene:index documents, search results 
Example URLs:  http://localhost/lucene-update.html (Index creation)
               http://localhost/**.html (use the search box after setting
               <search provider="lucene"/> in skinconf.xml)
Uses        :  content/xdocs/**.xml, context/xdocs/**.ehtml,
               resources/stylesheets/*2lucene*.xsl

$Revision$
==================================================== -->

<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
  <map:components>

    <!-- Lucene search generator: Creates a hit list from a query and
    an existing index. -->
    <map:generators default="file">
      <map:generator name="search" 
        logger="sitemap.generator.searchgenerator"
        src="org.apache.cocoon.generation.SearchGenerator" />
    </map:generators>

    <!-- Lucene index transformer: Creates a new Lucene index. -->
    <map:transformers default="xslt">
      <map:transformer name="index" 
        logger="sitemap.transformer.luceneindextransformer" 
        src="org.apache.cocoon.transformation.LuceneIndexTransformer"/>      
    </map:transformers>

    <map:readers default="resource"/>
    <map:serializers default="html"/>
    <map:matchers default="wildcard"/>

  </map:components>
  <!-- =========================== Pipelines ================================= -->
  <map:pipelines>

    <map:pipeline internal-only="false">
      
      <!-- ===== INDEX CREATION ===== -->

      <!-- Creates or updates the Lucene index -->
      <map:match pattern="lucene-update.xml">
        <map:generate src="cocoon:/site.lucene"/>
        <map:transform type="index"/>
        <map:transform src="{forrest:stylesheets}/search/lucene-update2document.xsl"/>
        <map:serialize type="xml"/>
      </map:match>


      <!-- ===== INDEX QUERYING ===== -->

      <!-- Searches the Lucene index using the search expression given
      in the request param named "queryString" -->
      <map:match pattern="lucene-search.xml">
        <map:generate type="search">
          <!-- Important: This value must match that of the
          "directory" parameter passed to book2include-lucene.xsl (see
          below) -->
          <map:parameter name="index" value="lucene-index"/>
          <map:parameter name="query-string" value="queryString"/>
        </map:generate>

        <map:transform
        src="{forrest:stylesheets}/search/search2document.xsl"/>

        <map:serialize type="xml"/>
      </map:match>


      <!-- ===== DOCUMENTS FOR LUCENE INDEX TRANSFORMER ===== -->

      <!-- Generates a document suitable for processing by the
      LuceneIndexTransformer, using sources across the whole site -->
      <map:match pattern="site.lucene">
        <map:generate src="cocoon://abs-linkmap"/>
        <map:transform src="{forrest:stylesheets}/site2book.xsl" />
        <map:transform src="{forrest:stylesheets}/search/book2cinclude-lucene.xsl">
          <map:parameter name="analyzer" value="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
          <map:parameter name="merge-factor" value="20"/>
          <map:parameter name="update-index" value="true"/>
          <!-- Important: This value must match that of the
          "index" parameter passed to the search generator (see
          above) -->
          <map:parameter name="directory" value="lucene-index"/>
        </map:transform>
        <map:transform type="cinclude"/>
        <map:serialize type="xml"/>
      </map:match>

      <!-- Creates a lucene:document from a Forrest document body -->
      <map:match pattern="**body-*.lucene">
        <map:select type="exists">
          <map:when test="{project:content.xdocs}{1}{2}.ehtml">
            <map:generate src="{project:content.xdocs}{1}{2}.ehtml" />
            <map:transform src="{forrest:stylesheets}/html2htmlbody.xsl" />
          </map:when>
          <map:when test="cocoon://{1}{2}.xml">
            <map:generate src="cocoon://{1}{2}.xml"/>
          </map:when>
        </map:select>
        <map:transform src="{forrest:stylesheets}/search/document2lucene.xsl">
          <map:parameter name="document-url" value="{1}{2}.xml"/>
        </map:transform>
        <map:serialize type="xml"/>
      </map:match>

      <!-- Creates a lucene:document from a Forrest document (same as
      above, as search-relevant information is only contained in the
      body) -->
      <map:match pattern="*.lucene">
        <map:generate src="cocoon:/body-{0}"/>
        <map:serialize type="xml"/>
      </map:match>         
      <map:match pattern="**/*.lucene">
        <map:generate src="cocoon:/{1}/body-{2}.lucene"/>
        <map:serialize type="xml"/>
      </map:match>

      <!-- ===== TODO: ERROR HANDLING ===== -->

      <!-- Must do something about malformed (unparseable) queries or
      a non-existant index. -->

    </map:pipeline>

  </map:pipelines>
</map:sitemap>
