huber 2003/12/14 13:03:34
Modified: src/blocks/lucene/samples/stylesheets search2html.xsl
src/blocks/lucene/samples sitemap.xmap statistic-index.xsp
welcome-index.xsp
Added: src/blocks/lucene/samples/stylesheets all-files2content.xsl
content2lucene.xsl lucene-index2html.xsl
search-index2html.xsl
src/blocks/lucene/samples document-files.xsp
Log:
add LuceneTransformerIndex sample
Revision Changes Path
1.3 +2 -1
cocoon-2.1/src/blocks/lucene/samples/stylesheets/search2html.xsl
Index: search2html.xsl
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/lucene/samples/stylesheets/search2html.xsl,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- search2html.xsl 12 Dec 2003 08:15:55 -0000 1.2
+++ search2html.xsl 14 Dec 2003 21:03:34 -0000 1.3
@@ -10,6 +10,7 @@
<html>
<head>
<title>Index Search</title>
+ <link title="Default Style" href="/styles/main.css"
rel="stylesheet"/>
</head>
<body bgcolor="white" alink="red" link="blue" vlink="blue">
<a href="http://jakarta.apache.org/lucene/">
@@ -24,7 +25,7 @@
</small>
</p>
- <form action="findIt">
+ <form action="">
<input type="text" name="queryString" size="60" value="[EMAIL
PROTECTED]"/>
 
<input type="submit" name="Search" value="Search"/>
1.1
cocoon-2.1/src/blocks/lucene/samples/stylesheets/all-files2content.xsl
Index: all-files2content.xsl
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cinclude="http://apache.org/cocoon/include/1.0"
>
<xsl:template match="files">
<includes>
<path><xsl:value-of select="path"/></path>
<xsl:apply-templates/>
</includes>
</xsl:template >
<xsl:template match="file">
<file>
<name><xsl:value-of select="path"/></name>
<include>
<cinclude:includexml ignoreErrors="true">
<cinclude:src><xsl:value-of select="absolutePath"/></cinclude:src>
</cinclude:includexml>
</include>
</file>
</xsl:template >
<xsl:template match="@*|node()" priority="-1"></xsl:template>
<xsl:template match="text()" priority="-1"></xsl:template>
</xsl:stylesheet>
1.1
cocoon-2.1/src/blocks/lucene/samples/stylesheets/content2lucene.xsl
Index: content2lucene.xsl
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cinclude="http://apache.org/cocoon/include/1.0"
xmlns:lucene="http://apache.org/cocoon/lucene/1.0"
>
<xsl:template match="includes">
<lucene:index
analyzer="org.apache.lucene.analysis.standard.StandardAnalyzer"
directory="index2"
create="false"
merge-factor="10">
<xsl:apply-templates/>
</lucene:index>
</xsl:template>
<xsl:template match="file">
<lucene:document>
<xsl:attribute name="url"><xsl:value-of select="name"/></xsl:attribute>
<xsl:copy-of select="include/*"/>
</lucene:document>
</xsl:template>
<xsl:template match="@*|node()" priority="-1"></xsl:template>
<xsl:template match="text()" priority="-1"></xsl:template>
</xsl:stylesheet>
1.1
cocoon-2.1/src/blocks/lucene/samples/stylesheets/lucene-index2html.xsl
Index: lucene-index2html.xsl
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cinclude="http://apache.org/cocoon/include/1.0"
xmlns:lucene="http://apache.org/cocoon/lucene/1.0"
>
<xsl:template match="lucene:index">
<html>
<head>
<title>Lucene Index</title>
<link title="Default Style" href="/styles/main.css" rel="stylesheet"/>
</head>
<body >
<a href="http://jakarta.apache.org/lucene/">
<img border="0" alt="Lucene Logo"
src="images/lucene_green_300.gif"/>
</a>
<h1>Lucene-Index</h1>
<p>
<small>
<a href="welcome">Welcome</a>
</small>
</p>
<ul>
<li>merge-factor - <xsl:value-of select="@merge-factor"/></li>
<li>create - <xsl:value-of select="@create"/></li>
<li>directory - <xsl:value-of select="@directory"/></li>
<li>analyzer - <xsl:value-of select="@analyzer"/></li>
</ul>
<table>
<tr><th>url</th><th>elapsed-time</th></tr>
<xsl:apply-templates/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="lucene:document">
<tr>
<td><xsl:value-of select="@url"/></td>
<td><xsl:value-of select="@elapsed-time"/></td>
</tr>
</xsl:template>
<xsl:template match="@*|node()" priority="-1"></xsl:template>
<xsl:template match="text()" priority="-1"></xsl:template>
</xsl:stylesheet>
1.1
cocoon-2.1/src/blocks/lucene/samples/stylesheets/search-index2html.xsl
Index: search-index2html.xsl
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:search="http://apache.org/cocoon/search/1.0"
>
<xsl:template match="search:results">
<html>
<head>
<title>Index2 Search</title>
<link title="Default Style" href="/styles/main.css" rel="stylesheet"/>
</head>
<body bgcolor="white" alink="red" link="blue" vlink="blue">
<a href="http://jakarta.apache.org/lucene/">
<img border="0" alt="Lucene Logo"
src="images/lucene_green_300.gif"/>
</a>
<h1>Index2Search</h1>
<p>
<small>
<a href="welcome">Welcome</a> |
<a href="statistic?indexName=index2">Index2 Statistic</a>
</small>
</p>
<form action="">
<input type="text" name="queryString" size="60" value="[EMAIL
PROTECTED]"/>
 
<input type="submit" name="Search" value="Search"/>
</form>
Search Help
<table cellspacing="2" cellpadding="2">
<tr bgcolor="#dddedd" valign="top">
<td width="50%"><font size="-2" >
<ul>
<li>free AND "text search"
Search for documents containing "free" and the
phrase "text search"
</li>
<li>+text search
Search for documents containing "text" and
preferentially containing "search".
</li>
<li>giants -football
Search for "giants" but omit documents containing "football"
</li>
</ul>
</font></td>
<td><font size="-2">
<ul>
<li>body:john
Search for documents containing "john" in the body field.
The field "body" is used by default.
Thus query "body:john" is equivalent to query "john".
</li>
<li>[EMAIL PROTECTED]:cocoon
Search for documents containing "cocoon" in the
using field [EMAIL PROTECTED], ie searching in
title attribute of s1 element of xml document.
</li>
</ul>
</font></td>
</tr>
</table>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="search:hits">
<p>
Total Hits <xsl:value-of select="@total-count"/>
Pages <xsl:value-of select="@count-of-pages"/>
</p>
<p>
Page:
<xsl:for-each
select="/search:results/search:navigation/search:navigation-page">
<xsl:call-template name="navigation-link">
<xsl:with-param name="query-string"
select="/search:results/@query-string"/>
<xsl:with-param name="page-length"
select="/search:results/@page-length"/>
<xsl:with-param name="start-index" select="@start-index"/>
<xsl:with-param name="link-text" select="position()"/>
</xsl:call-template>
</xsl:for-each>
</p>
<p>
<xsl:call-template name="navigation-paging-link">
<xsl:with-param name="query-string"
select="/search:results/@query-string"/>
<xsl:with-param name="page-length"
select="/search:results/@page-length"/>
<xsl:with-param name="has-previous"
select="/search:results/search:navigation/@has-previous"/>
<xsl:with-param name="has-next"
select="/search:results/search:navigation/@has-next"/>
<xsl:with-param name="previous-index"
select="/search:results/search:navigation/@previous-index"/>
<xsl:with-param name="next-index"
select="/search:results/search:navigation/@next-index"/>
</xsl:call-template>
</p>
<hr/>
<table border="1" width="90%" cellpadding="4">
<tr>
<td>Score</td><td>Rank</td><td>URI</td>
</tr>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="search:navigation">
<p>
<xsl:call-template name="navigation-paging-form">
<xsl:with-param name="query-string"><xsl:value-of
select="/search:results/@query-string"/></xsl:with-param>
<xsl:with-param name="page-length"><xsl:value-of
select="/search:results/@page-length"/></xsl:with-param>
<xsl:with-param name="has-previous"><xsl:value-of
select="@has-previous"/></xsl:with-param>
<xsl:with-param name="has-next"><xsl:value-of
select="@has-next"/></xsl:with-param>
<xsl:with-param name="previous-index"><xsl:value-of
select="@previous-index"/></xsl:with-param>
<xsl:with-param name="next-index"><xsl:value-of
select="@next-index"/></xsl:with-param>
</xsl:call-template>
</p>
</xsl:template>
<xsl:template match="search:hit">
<tr>
<td>
<xsl:value-of select="format-number( @score, '### %' )"/>
</td>
<td>
<xsl:value-of select="@rank"/>
</td>
<td>
<xsl:variable name="pure-name"
select="substring-before(@uri,'.xml')"/>
<a target="_blank">
<xsl:attribute name="href">/docs/<xsl:value-of
select="$pure-name"/>.html</xsl:attribute>
<xsl:value-of select="@uri"/>
</a>
</td>
</tr>
</xsl:template>
<xsl:template name="navigation-paging-form">
<xsl:param name="query-string"/>
<xsl:param name="page-length"/>
<xsl:param name="has-previous"/>
<xsl:param name="has-next"/>
<xsl:param name="previous-index"/>
<xsl:param name="next-index"/>
<xsl:if test="$has-previous = 'true'">
<form action="findIt2">
<input type="hidden" name="startIndex" value="{$previous-index}"/>
<input type="hidden" name="queryString" value="{$query-string}"/>
<input type="hidden" name="pageLength" value="{$page-length}"/>
<input type="submit" name="previous" value="previous"/>
</form>
</xsl:if>
<xsl:if test="$has-next = 'true'">
<form action="findIt2">
<input type="hidden" name="startIndex" value="{$next-index}"/>
<input type="hidden" name="queryString" value="{$query-string}"/>
<input type="hidden" name="pageLength" value="{$page-length}"/>
<input type="submit" name="next" value="next"/>
</form>
</xsl:if>
</xsl:template>
<xsl:template name="navigation-paging-link">
<xsl:param name="query-string"/>
<xsl:param name="page-length"/>
<xsl:param name="has-previous"/>
<xsl:param name="has-next"/>
<xsl:param name="previous-index"/>
<xsl:param name="next-index"/>
<xsl:if test="$has-previous = 'true'">
<xsl:call-template name="navigation-link">
<xsl:with-param name="query-string"><xsl:value-of
select="$query-string"/></xsl:with-param>
<xsl:with-param name="page-length"><xsl:value-of
select="$page-length"/></xsl:with-param>
<xsl:with-param name="start-index"><xsl:value-of
select="$previous-index"/></xsl:with-param>
<xsl:with-param name="link-text">Previous Page Of
Hits</xsl:with-param>
</xsl:call-template>
</xsl:if>
 
<xsl:if test="$has-next = 'true'">
<a
href="findIt2?startIndex={$next-index}&queryString={$query-string}&pageLength={$page-length}">
Next Page Of Hits
</a>
</xsl:if>
</xsl:template>
<xsl:template name="navigation-link">
<xsl:param name="query-string"/>
<xsl:param name="page-length"/>
<xsl:param name="start-index"/>
<xsl:param name="link-text"/>
<a
href="findIt2?startIndex={$start-index}&queryString={$query-string}&pageLength={$page-length}">
<xsl:value-of select="$link-text"/>
</a>
 
</xsl:template>
<xsl:template match="@*|node()"
priority="-2"><xsl:copy><xsl:apply-templates
select="@*|node()"/></xsl:copy></xsl:template>
<xsl:template match="text()" priority="-1"><xsl:value-of
select="."/></xsl:template>
</xsl:stylesheet>
1.4 +37 -2 cocoon-2.1/src/blocks/lucene/samples/sitemap.xmap
Index: sitemap.xmap
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/lucene/samples/sitemap.xmap,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- sitemap.xmap 12 Dec 2003 08:15:55 -0000 1.3
+++ sitemap.xmap 14 Dec 2003 21:03:34 -0000 1.4
@@ -12,8 +12,12 @@
</map:generators>
<map:transformers default="xslt">
<map:transformer name="log"
- src="org.apache.cocoon.transformation.LogTransformer"/>
+ src="org.apache.cocoon.transformation.LogTransformer"/>
+ <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"/>
@@ -68,8 +72,39 @@
<map:transform src="stylesheets/search2html.xsl"/>
<map:serialize/>
</map:match>
+
+ <map:match pattern="findIt2">
+ <map:generate type="search">
+ <map:parameter name="index" value="index2"/>
+ </map:generate>
+ <map:transform type="log"/>
+ <map:transform src="stylesheets/search-index2html.xsl"/>
+ <map:serialize/>
+ </map:match>
+
+ <map:match pattern="document-files.xsp">
+ <map:generate type="serverpages" src="document-files.xsp">
+ </map:generate>
+
+ <map:transform src="stylesheets/all-files2content.xsl"/>
+ <map:transform type="cinclude"/>
+ <map:transform src="stylesheets/content2lucene.xsl"/>
+ <map:transform type="index"/>
+
+ <map:transform src="stylesheets/lucene-index2html.xsl"/>
+
+ <map:serialize/>
+ </map:match>
+
+ <map:match pattern="*.xsp">
+ <map:generate type="serverpages" src="{1}.xsp">
+ <map:parameter name="p1" value="context://docs/xdocs"/>
+ </map:generate>
+
+ <map:serialize type="xml"/>
+ </map:match>
- <map:match pattern="**">
+ <map:match pattern="*">
<map:generate type="serverpages" src="{1}-index.xsp"/>
<!--
Run-time configuration is done through these
1.3 +5 -3 cocoon-2.1/src/blocks/lucene/samples/statistic-index.xsp
Index: statistic-index.xsp
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/lucene/samples/statistic-index.xsp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- statistic-index.xsp 12 Dec 2003 08:15:55 -0000 1.2
+++ statistic-index.xsp 14 Dec 2003 21:03:34 -0000 1.3
@@ -26,9 +26,9 @@
Directory directory;
- void init() throws ProcessingException {
+ void init(String indexName) throws ProcessingException {
try {
- directory = LuceneCocoonHelper.getDirectory( new File( workDir,
"index" ), false );
+ directory = LuceneCocoonHelper.getDirectory( new File( workDir,
indexName ), false );
} catch (Exception e) {
throw new ProcessingException( "Exception in init()!", e );
}
@@ -131,7 +131,9 @@
<page>
<xsp:logic>
- init();
+ String indexName = request.getParameter("indexName");
+ if (indexName == null) indexName = "index";
+ init(indexName);
</xsp:logic>
<title>Index Statistics</title>
<content>
1.2 +30 -3 cocoon-2.1/src/blocks/lucene/samples/welcome-index.xsp
Index: welcome-index.xsp
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/lucene/samples/welcome-index.xsp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- welcome-index.xsp 21 Mar 2003 07:54:19 -0000 1.1
+++ welcome-index.xsp 14 Dec 2003 21:03:34 -0000 1.2
@@ -27,6 +27,12 @@
<h2>Creating an Index</h2>
<p>
You must create a Lucene index first, before you can do the
searching.
+ You can create a Lucene index either by crawling, or by using
+ LuceneIndexTransformer.
+ </p>
+
+ <h3>Creating Index By Crawling</h3>
+ <p>
Create an index by specifying a base url from which to start
crawling (the indexer will follow the links to build its content).
The base url should be
@@ -38,11 +44,27 @@
</p>
<p>
This following page allows you to <a href="create">create</a> an
- index.
+ index, named index.
+ </p>
+
+ <h3>Creating Index2 By Transforming</h3>
+ <p>
+ Create an index by using LuceneIndexTransformer.
+ An XSP Page gathers all files of directory docs/xdocs, includes all
+ the files and pipes it through LuceneIndexTransformer, creating an
+ index, named index2.
+ </p>
+ <p>
+ This following page allows you to <a
href="document-files.xsp">create</a> an
+ index, named index2.
</p>
-
+
<h2>Searching</h2>
<p>
+ If you have created a Lucene index, you can search the created index.
+ </p>
+ <h3>Searching Index</h3>
+ <p>
Enter a query and search the Lucene index that you have created
- using <a href="search?queryString=lucene">XSP</a>.
</p>
@@ -50,7 +72,12 @@
Enter a query and search the Lucene index that you have created
- using <a href="findIt?queryString=lucene">Cocoon Generators</a>.
</p>
-
+
+ <h3>Searching Index2</h3>
+ <p>
+ Enter a query and search the Lucene index2 that you have created
+ - using <a href="findIt2?queryString=cocoon">Cocoon Generators</a>.
+ </p>
<h2>Internals</h2>
<p>
1.1 cocoon-2.1/src/blocks/lucene/samples/document-files.xsp
Index: document-files.xsp
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page language="java"
xmlns:xsp="http://apache.org/xsp"
xmlns:xsp-request="http://apache.org/xsp/request/2.0">
<xsp:structure>
<xsp:include>org.apache.avalon.framework.context.ContextException</xsp:include>
<xsp:include>org.apache.avalon.framework.component.ComponentException</xsp:include>
<xsp:include>org.apache.cocoon.ProcessingException</xsp:include>
<xsp:include>java.net.URL</xsp:include>
<xsp:include>java.net.MalformedURLException</xsp:include>
<xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:include>
<xsp:include>org.apache.avalon.framework.context.ContextException</xsp:include>
<xsp:include>org.apache.cocoon.components.search.*</xsp:include>
<xsp:include>org.apache.lucene.store.Directory</xsp:include>
<xsp:include>org.apache.lucene.analysis.Analyzer</xsp:include>
<xsp:include>java.util.*</xsp:include>
</xsp:structure>
<xsp:logic>
String base = "docs/xdocs" ;
String baseContext = "context://" + base;
File []allFiles(File base) {
List allFiles = new ArrayList();
try {
if (base == null) {
base = theBaseDir();
}
File []allTheFiles = base.listFiles();
for (int i = 0; i < allTheFiles.length; i++ ) {
File f = allTheFiles[i];
if (f.isDirectory()) {
File[] allFilesOfDirectory = allFiles( f );
allFiles.addAll( Arrays.asList( allFilesOfDirectory ) );
} else if (f.isFile()) {
if (f.canRead() && f.getName().endsWith( ".xml" )) {
allFiles.add( f );
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return (File[])allFiles.toArray(new File[0]);
}
File theBaseDir() {
File f = null;
try {
org.apache.excalibur.source.Source source = resolver.resolveURI(
baseContext );
String s = source.getURI();
f = new File( new URL(s).getFile() );
} catch (Exception e) {
e.printStackTrace();
}
return f;
}
String strippedFileName( File f ) {
String sf = f.toString();
int index = sf.indexOf("xdocs");
if (index >= 0) {
sf = sf.substring( index + 5 + 1);
}
sf = sf.replace( '\\', '/' );
return sf;
}
</xsp:logic>
<files>
<path><xsp:expr>theBaseDir()</xsp:expr></path>
<xsp:logic>
File []allFiles = allFiles(null);
for (int i = 0; allFiles != null && i < allFiles.length;
i++) {
File f = allFiles[i];
if (f.isFile()) {
<xsp:content>
<file>
<path><xsp:expr>strippedFileName(f)</xsp:expr></path>
<absolutePath><xsp:expr>f.getAbsolutePath()</xsp:expr></absolutePath>
</file>
</xsp:content>
}
}
</xsp:logic>
</files>
</xsp:page>