lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject cvs commit: jakarta-lucene-sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search SearchTag.java SearchTagTei.java
Date Thu, 29 May 2003 17:20:19 GMT
ehatcher    2003/05/29 10:20:19

  Modified:    contributions/snowball/src/java/org/apache/lucene/analysis/snowball
                        SnowballFilter.java
               contributions/taglib index.html readme.txt result.jsp
               contributions/taglib/WEB-INF lucene-taglib.tld web.xml
               contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search
                        SearchTag.java SearchTagTei.java
  Log:
  new stuff from Bryan
  
  Revision  Changes    Path
  1.3       +2 -2      jakarta-lucene-sandbox/contributions/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballFilter.java
  
  Index: SnowballFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/snowball/src/java/org/apache/lucene/analysis/snowball/SnowballFilter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SnowballFilter.java	20 Dec 2002 23:05:19 -0000	1.2
  +++ SnowballFilter.java	29 May 2003 17:20:18 -0000	1.3
  @@ -91,7 +91,7 @@
         stemmer = (SnowballProgram) stemClass.newInstance();
         stemMethod = stemClass.getMethod("stem", new Class[0]);
       } catch (Exception e) {
  -      throw new RuntimeException(e);
  +      throw new RuntimeException();
       }
     }
   
  @@ -104,7 +104,7 @@
       try {
         stemMethod.invoke(stemmer, EMPTY_ARGS);
       } catch (Exception e) {
  -      throw new RuntimeException(e);
  +      throw new RuntimeException();
       }
       return new Token(stemmer.getCurrent(),
                        token.startOffset(), token.endOffset(), token.type());
  
  
  
  1.2       +114 -8    jakarta-lucene-sandbox/contributions/taglib/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/taglib/index.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- index.html	21 May 2003 01:22:22 -0000	1.1
  +++ index.html	29 May 2003 17:20:19 -0000	1.2
  @@ -1,8 +1,114 @@
  -<html>
  -    <head>
  -        <title>Hello World</title>
  -    </head>
  -    <body>
  -        Hello World
  -    </body>
  -</html>
  +<html>
  +<head>
  +	<title>Using Lucene Taglib</title>
  +	<style>
  +	BODY { background-color:#FFFFFF; font-size:12pt;}
  +	TH { color:#009696; }
  +	SPAN { color:color:#009696; font-size:8pt; }
  +	SPAN.required { color:red; font-size:12pt;}
  +	PRE { color:#7B007B; }
  +	OPTION { color:blue; font-size:10pt; font-weight:bold; }
  +	TD { vertical-align:top; color:blue; }
  +	SELECT.data { color:blue; width:175px; }
  +	INPUT { color:blue; width:175px; }
  +	SPAN.default { color:Fuchsia; }
  +	.default { color:Fuchsia; }
  +	SPAN.object { color:Purple; font-size:12pt; }
  +	SPAN.explained { color:black; font-size:10pt; }
  +	</style>
  +</head>
  +<body>
  +
  +<h2 align="center">Test page for Lucene-taglib</h2>
  +<table border=0 width="100%">
  +<tr>
  +	<td colspan=3><b>Ledgend</b></td>
  +</tr>
  +<tr>
  +	<td style="width:100px;">Required field</td>
  +	<td style="background-color:red; width:5px;">&nbsp;</td>
  +    <td rowspan="4" valign="top" style="padding-left:10px;" align="justify">
  +	<span class="explained">
  +	This page has been set up so that you can dynamically change the 
  +	parameters used by the taglib to produce different results. Hopefully
  +	this tag library is abstract enough to address the majority of situations.
  +	
  +	The ledgend on the left shows which parameters are required and there
  +	default values. If you set throwOnException to false the errors caused by
  +	bad input parameter should not crash the page rather no results will be returned.
  +	On the other hand setting it to true will show any errors encountered by the tag.
  +	Some knowledge of the Lucene search engine is required to take advantage of the
  +	the search tags advanced features such as changing the analyzer and using 
  +	fieldList's and flagList's. more documentation on each tag can be found in
  +	the docs directory in the index.html file.
  +	</span>
  +	</td>
  +</tr>
  +<tr>
  +	<td>Default value</td>
  +	<td style="background-color:Fuchsia">&nbsp;</td>
  +</tr>
  +<tr>
  +	<td>String</td>
  +	<td style="background-color:blue">&nbsp;</td>
  +</tr>
  +<tr>
  +	<td>Object</td>
  +	<td style="background-color:Purple;">&nbsp;</td>
  +</tr>
  +</table>
  +
  +<form action="result.jsp" method="get">
  +<input type="submit">
  +<table cellpadding=0 cellspacing=0 border=0>
  +	<tr><th>&lt;LUCENE:Search	</th><td><span class="required">id="rs"</span></td><td>&nbsp;</td><td>&nbsp;</td></tr>
  +	<tr><td>throwOnException</td><td><select class="data" name="throwOnException"><option
value="true">true</option><option class="default" value="false" SELECTED>false</option></select></td><td>&nbsp;</td><td>&nbsp;</td></tr>
  +	<tr><td><span class="required">collection</span></td><td><input
type="text" name="collection" value="E:/search/lucene/index,E:/opt/lucene/index"></td><td
colspan=2><span>"comma separated directory/path(s)"</span></td></tr>
  +	<tr><td><span class="required">criteria</span></td><td><input
type="text" name="criteria"></td><td><span>"String"</span></td><td>&nbsp;</td></tr>
  +	<tr><td>startRow</td><td><input type="text" name="startRow"
value="0"></td><td><span class="default">"0"</span></td><td>&nbsp;</td></tr>
  +	<tr><td>maxRows</td><td><input type="text" name="maxRows" value="50"></td><td><span
class="default">"50"</span></td><td>&nbsp;</td></tr>
  +	<tr><td>analyzerType</td>
  +	<td>
  +	<select class="data" name="analyzerType">
  +		<option value="GERMANAN_ALYZER">GERMANAN_ALYZER</option>
  +		<option value="SIMPLE_ANALYZER">SIMPLE_ANALYZER</option>
  +		<option class="default" value="STANDARD_ANALYZER" selected>STANDARD_ANALYZER</option>
  +		<option value="STOP_ANALYZER">STOP_ANALYZER</option>
  +		<option value="WHITESPACE_ANALYZER">WHITESPACE_ANALYZER</option>
  +	</select>
  +	</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  +	<tr><td>search</td><td><input type="text" name="search" value="contents"></td><td><span
class="default">"contents"</span></td><td>&nbsp;</td></tr>
  +	<tr><td>stopWords</td><td><input type="text" name="stopWords"></td><td><span>"comma,separated,list"</span></td><td>&nbsp;</td></tr>
  +	<tr><td>fieldList</td><td><input type="text" name="fieldList"
value="contents"></td><td><span>"comma,separated,list"</span></td><td>&nbsp;</td></tr>
  +	<tr><td>flagList</td><td><input type="text" name="flagList"
value="NORMAL"></td><td><span>"NORMAL,PROHIBITED,REQUIRED"</span>&gt;</td><td>&nbsp;</td></tr>
  +	<tr><td colspan=4>&lt;%= rs.loopCount %&gt; <br><span class="explained">int
value of the current interation of the search tag</span></td></tr>
  +	<tr><td colspan=4>&lt;%= rs.rowCount %&gt;<br><span class="explained">int
value of the current result in hitCount</span></td></tr>
  +	<tr><td colspan=4>&lt;%= rs.hitCount %&gt;<br><span class="explained">int
value representing the total number of results</span></td></tr>
  +	<tr><td colspan=4>&lt;%= rs.pageCount %&gt;<br><span class="explained">int
value of the offset between the maxrows and the total number of hits</span></td></tr>
  +	<tr><td colspan=4>&lt;%= rs.firstPage %&gt;<br><span class="explained">variable
containing the query string needed by a navigation element to return you to the first page
of the result</span></td></tr>
  +	<tr><td colspan=4>&lt;%= rs.nextPage %&gt;<br><span class="explained">variable
containing the query string needed by a navigation element to move to the next page of the
result</span></td></tr>
  +	<tr><td colspan=4>&lt;%= rs.previousPage %&gt;<br><span class="explained">variable
containing the query string needed by a navigation element to return to the previous page
of the result</span></td></tr>
  +	<tr><td colspan=4>&lt;%= rs.lastPage %&gt;<br> <span class="explained">variable
containing the query string needed by a navigation element to move to the last page of the
result</span></td></tr>
  +	<tr><td colspan=4>&lt;%= rs.score %&gt;<br> <span class="explained">returns
a string representation of the float value stored in every lucene index as the value score.
<br>if you want to translate it into something useful to a user you will need to create

  +	<br>new Float(tagid.getField("score")).floatValue() and then you can use your own
conversion method <br>
  +	as this will return you the original float value that was stored in the index. </span></td></tr>
  +	<tr><td colspan=4 style="color:black"><span class="object">&lt;%=
rs.pageList %&gt;</span><br> <span style="font-size:10pt;">returns a
LinkedList of query strings needed to produce links to the number of page represented <br>by
the offset of the current page and the maxrows being displayed on each page. </span></td></tr>
  +	<tr><td colspan=4>&lt;%= rs.getField(String name) %&gt; used by the
Field tag<br> <span class="explained">used to retreive the named field from the
index for that iteration of the loop. <br>If no such name exists in the index such as
author the method will return an empty string.</span></td></tr>
  +	<tr><td colspan=4>&lt;%= rs.getFields() %&gt; used by the Column tag<br>
<span class="explained">used to retrieve a Set view of all of the fields contained in
the index for each iteration of the loop, <br>most generally would be used to write
your table headers when the field names are not known until runtime</span></td></tr>
  +	
  +	<tr><td>&nbsp;</td><th>&lt;LUCENE:Column </th><td><span
class="required">id="col"</span></td><td>&nbsp;</td></tr>
  +	<tr><td>&nbsp;</td><td>runOnce</td><td><select
class="data" name="runOnce"><option value="true">true</option><option class="default"
value="false" SELECTED>false</option></select></td><td>&nbsp;</td></tr>
  +	<tr><td>&nbsp;</td><td>throwOnException</td><td><select
class="data" name="columnthrowOnException"><option value="true">true</option><option
class="default" value="false" SELECTED>false</option></select>&gt;</td><td>&nbsp;</td></tr>
  +	<tr><td>&nbsp;</td><td colspan=3>&lt;%= col.columnCount
%&gt; <span class="explained">int value of the current iteration of the column tag</span></td></tr>
  +	<tr><td>&nbsp;</td><td colspan=3>&lt;%= col.columnName
%&gt;<span class="explained"> String value of the field name at columnCount</span></td></tr>
  +	<tr><td>&nbsp;</td><td>&nbsp;</td><th>&lt;LUCENE:Field
</th><td><span class="required">id="fld"</span></td></tr>
  +	<tr><td>&nbsp;</td><td>&nbsp;</td><td><span
class="required">name</span></td><td>"&lt;%= col.columnName %&gt;"</td></tr>
  +	<tr><td>&nbsp;</td><td>&nbsp;</td><td>throwOnException</td><td><select
class="data" name="fieldthrowOnException"><option value="true">true</option><option
class="default" value="false" SELECTED>false</option></select>&gt;</td></tr>
  +	<tr><td>&nbsp;</td><td>&nbsp;</td><td colspan=2>&lt;%=
fld.value %&gt; <span class="explained">String value of the columnName</span></td></tr>
  +	<tr><td>&nbsp;</td><td>&nbsp;</td><th>&lt;/LUCENE:Field&gt;</th><td>&nbsp;</td></tr>
  +	<tr><td>&nbsp;</td><th>&lt;/LUCENE:Column&gt;</th><td>&nbsp;</td><td>&nbsp;</td><tr>
  +	<tr><th>&lt;/LUCENE:Search&gt;</th><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
  +</table>
  +</form>
  +</body>
  +</html>
  \ No newline at end of file
  
  
  
  1.2       +48 -10    jakarta-lucene-sandbox/contributions/taglib/readme.txt
  
  Index: readme.txt
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/taglib/readme.txt,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- readme.txt	12 May 2003 14:02:35 -0000	1.1
  +++ readme.txt	29 May 2003 17:20:19 -0000	1.2
  @@ -16,18 +16,56 @@
   DOCUMENTATION:
   you will find documentation and an over view of the tag library in
   the docs folder of this project and the javadocs in the api folder
  -respectivley.
  +respectively.
   
   BUGS:
   I tried to create a .war file for this project but I am having trouble
   getting it to deploy properly.
   
  -PLANNED:
  -I am planning to document the result.jsp file line for line to explain
  -how to display a search result when you do not know what the names of 
  -the search fields stored in the lucene-index. That is the way the result
  -page is currently written.
  -
  -Time permitting I want to write a couple of child tags for telling the search
  -tag that there are multiple index to be searched and to let it do the other
  -types of searches such as fuzzy and range queries.
  \ No newline at end of file
  +More like a heads up than a bug I discovered that if you have tag pooling \
  +turned on in Tomcat that values passed to a custom tag will not change in
  +the event that an exception is thrown. Catching the exception inside of
  +the tag or page does not help, to update the values at this point you
  +have to turn off tag pooling. Follow the instructions below to do this
  +in Tomcat.
  +
  +----------------------------------------------------------------------------
  +
  +  From: Bill Barker
  +  Subject: Re: HELP:Tagpool sharing problems
  +  Date: Mon, 28 Apr 2003 22:20:20 -0700
  +
  +----------------------------------------------------------------------------
  +
  +In $CATALINA_HOME/conf/web.xml, locate the <servlet-name>jsp</servlet-name>
  +servlet, and add:
  +  <init-param>
  +    <param-name>enablePooling</param-name>
  +    <param-value>false</param-value>
  +  </init-param>
  +
  +This will turn off tag-pooling.  You'll also need to clear out
  +$CATALINA_HOME/work so that the JSP pages get re-compiled.
  +
  +If you just want it turned off for one context, then you can place the
  +definition of the jsp servlet in your own web.xml.
  +
  +If you are using:
  +  <servlet>
  +    <servlet-name>myJspPage</servlet-name>
  +    <jsp-page>myJspPage.jsp</jsp-page>
  +  </servlet>
  +then you also need to add the enablePooling init-param to your servlet's
  +definition.
  +
  +
  +HISTORY:
  +1.	Added more robust error handling and the ability to turn it on and
  +	off with a throwOnException attribute. (All tags)
  +2.	Added a Column tag for outputting the field names found in a 
  +	Lucene index.
  +3.	Added a Field tag for retrieving a value for a field in a search
  +	result either produced by the Column tag or known in advance.
  +4.	Added new example pages to illustrate how to use the new tags
  +5.	The Collection tag has been deprecated, use the collection attribute
  +	of the Search tag instead.
  \ No newline at end of file
  
  
  
  1.3       +116 -41   jakarta-lucene-sandbox/contributions/taglib/result.jsp
  
  Index: result.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/taglib/result.jsp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- result.jsp	21 May 2003 01:22:22 -0000	1.2
  +++ result.jsp	29 May 2003 17:20:19 -0000	1.3
  @@ -1,53 +1,92 @@
   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  -<%@ taglib uri="/WEB-INF/lucene-taglib.tld" prefix="JSP"%>
  -<%@ include file="header.jsp"%>
  +<%@ taglib uri="/WEB-INF/lucene-taglib.tld" prefix="LUCENE"%>
   <%@ page import="java.util.*"%>
  -
  +<html>
  +<head>
  +	<title>Using Lucene Taglib</title>
  +	<style>
  +	BODY{background-color:#F5F5F5}
  +	</style>
  +</head>
  +<body>
   <% 
  -	String startRow = "0";
  -	String maxRows = "10";
  -	String query = request.getParameter("query");
  +	String startRow = "";
  +	String maxRows = "";
  +	String criteria = "";
  +	int colCount = 0;
  +	String analyzerType = "STANDARD_ANALYZER";
  +	String search = "contents";
  +	String stopWords="";
  +	String fieldList="";
  +	String flagList="";
  +	String collection = "E:/search/lucene/index,E:/opt/lucene/index";
  +	String throwOnException = "false";
  +	String fieldthrowOnException = "false";
  +	String columnthrowOnException = "false";
  +	String runOnce = "false";
  +	String query = "";
  +	
   	try{
  +		query = request.getQueryString();
  +		criteria = request.getParameter("criteria");
   		startRow = request.getParameter("startRow");
   		maxRows = request.getParameter("maxRows");
  +		analyzerType = request.getParameter("analyzerType");
  +		search = request.getParameter("search");
  +		stopWords = request.getParameter("stopWords");
  +		fieldList = request.getParameter("fieldList");
  +		flagList = request.getParameter("flagList");
  +		throwOnException = request.getParameter("throwOnException");
  +		fieldthrowOnException = request.getParameter("fieldthrowOnException");
  +		columnthrowOnException = request.getParameter("columnthrowOnException");
  +		runOnce = request.getParameter("runOnce");
   	}
   	catch(Exception e){
   	}
   %>
  -
  +<h3> Search results for "<%= criteria %>"</h3>
   <table border=3>
   
  -	<JSP:Search throwOnException="false" id="rs" collection="E:/opt/lucene/index" criteria="<%=
query %>" startRow="<%= startRow %>" maxRows="<%= maxRows %>">
  -	<%
  -		
  -		Set allFields = rs.getFields();
  -		int fieldSize = allFields.size();
  -		Iterator fieldIter = allFields.iterator();
  -		
  -		while(fieldIter.hasNext()){
  -			String nextField = (String) fieldIter.next();
  -			if(!nextField.equalsIgnoreCase("summary")){
  -	%>
  -				<tr><td><b><%= nextField %></b></td><td><%=
rs.getField(nextField) %></td></tr>
  -			<%
  -			}else{
  -			%>
  -				<tr><td colspan="2"><b><%= rs.hitCount %>|<%= nextField
%></b></td></tr>
  -				<tr><td colspan="2"><%= rs.getField(nextField) %></td></tr>
  -			<%
  -			}
  -		}
  -		
  -	%>
  -	</JSP:Search>
  +	<LUCENE:Search id="rs" 
  +				throwOnException="<%= throwOnException %>" 
  +				collection="<%= collection %>" 
  +				criteria="<%= criteria %>" 
  +				startRow="<%= startRow %>" 
  +				maxRows="<%= maxRows %>"
  +				analyzerType="<%= analyzerType %>"
  +				search="<%= search %>"
  +				stopWords="<%= stopWords %>"
  +				fieldList="<%= fieldList %>"
  +				flagList="<%= flagList %>">
  +		<tr>
  +		<LUCENE:Column id="header" runOnce="true" throwOnException="false">
  +			<% colCount = header.columnCount; %>
  +			
  +			<th><b><%= header.columnName %></b></th>
  +		</LUCENE:Column>
  +		</tr>
  +		<LUCENE:Column id="col" throwOnException="<%= columnthrowOnException %>" runOnce="<%=
runOnce %>">
  +		<tr>
  +			<td colspan="<%= col.columnCount %>"><b>[<%= rs.loopCount %>][<%=
rs.rowCount %>]</b>&nbsp;
  +				<LUCENE:Field id="fld" name="<%= col.columnName %>" throwOnException="<%=
fieldthrowOnException %>">
  +				
  +					<% if(col.columnName.equalsIgnoreCase("url")){ %>
  +						<a href="<%= fld.value %>">
  +					<% } %>
  +					
  +					<%= fld.value %>
  +					
  +					<% if(col.columnName.equalsIgnoreCase("url")){ %>
  +						</a>
  +					<% } %>
  +					
  +				</LUCENE:Field>
  +			</td>
  +		</tr>
  +		</LUCENE:Column>
  +	</LUCENE:Search>
   <%
  -	int count = 0;
  -	try{
  -		count = new Integer(rs.hitCount).intValue();
  -	}catch(Exception e){
  -		out.print(e);
  -	}
  -	if(count <= 0){
  +	if(rs.hitCount <= 0){
   %>
   	<tr>
   		<td colspan=2>No results have been found</td>
  @@ -56,9 +95,45 @@
   	}
   %>
   	<tr>
  -		<td colspan=2><%= rs.hitCount %></td>
  +		<td><b>hitCount</b></td>
  +		<td colspan="<%= colCount-1 %>"><%= rs.hitCount %></td>
  +	</tr>
  +	<tr>
  +		<td><b>pageCount</b></td>
  +		<td colspan="<%= colCount-1 %>"><%= rs.pageCount %></td>
  +	</tr>
  +	<tr>
  +		<td><b>firstPage</b></td>
  +		<td colspan="<%= colCount-1 %>"><a href="<%= rs.firstPage %><%=
query %>"><%= rs.firstPage %></a></td>
  +	</tr>
  +	<tr>
  +		<td><b>nextPage</b></td>
  +		<td colspan="<%= colCount-1 %>"><a href="<%= rs.nextPage %><%=
query %>"><%= rs.nextPage %></a></td>
  +	</tr>
  +	<tr>
  +		<td><b>previousPage</b></td>
  +		<td colspan="<%= colCount-1 %>"><a href="<%= rs.previousPage %><%=
query %>"><%= rs.previousPage %></a></td>
  +	</tr>
  +	<tr>
  +		<td><b>lastPage</b></td>
  +		<td colspan="<%= colCount-1 %>"><a href="<%= rs.lastPage %><%=
query %>"><%= rs.lastPage %></a></td>
  +	</tr>
  +	<tr>
  +		<td colspan="<%= colCount %>">
  +		<select name="pagelist" onchange="location.href=this.value">
  +		<%
  +		Iterator pages = rs.pageList.iterator();
  +		while(pages.hasNext()){
  +			String listNext = (String) pages.next();
  +			%>
  +			<option value="<%= listNext %><%= query %>"><%= listNext %></option>
  +			<%
  +		}
  +		%>
  +		</select>
  +		</td>
   	</tr>
  -	</table>
   	
  -
  -<%@include file="footer.jsp"%>
  +</table>
  +</body>
  +</html>
  \ No newline at end of file
  
  
  
  1.3       +65 -4     jakarta-lucene-sandbox/contributions/taglib/WEB-INF/lucene-taglib.tld
  
  Index: lucene-taglib.tld
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/taglib/WEB-INF/lucene-taglib.tld,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- lucene-taglib.tld	21 May 2003 01:22:22 -0000	1.2
  +++ lucene-taglib.tld	29 May 2003 17:20:19 -0000	1.3
  @@ -34,7 +34,7 @@
   		</attribute>
   		<attribute>
   			<name>collection</name>
  -			<required>false</required>
  +			<required>true</required>
   			<rtexprvalue>true</rtexprvalue>
   		</attribute>
   		<attribute>
  @@ -47,16 +47,77 @@
   			<required>false</required>
   			<rtexprvalue>true</rtexprvalue>
   		</attribute>
  +		<attribute>
  +			<name>analyzerType</name>
  +			<required>false</required>
  +			<rtexprvalue>true</rtexprvalue>
  +		</attribute>
  +		<attribute>
  +			<name>fieldList</name>
  +			<required>false</required>
  +			<rtexprvalue>true</rtexprvalue>
  +		</attribute>
  +		<attribute>
  +			<name>flagList</name>
  +			<required>false</required>
  +			<rtexprvalue>true</rtexprvalue>
  +		</attribute>
  +		<attribute>
  +			<name>search</name>
  +			<required>false</required>
  +			<rtexprvalue>true</rtexprvalue>
  +		</attribute>
  +		<attribute>
  +			<name>stopWords</name>
  +			<required>false</required>
  +			<rtexprvalue>true</rtexprvalue>
  +		</attribute>
   	</tag>
   	<tag>
  -		<name>Collection</name>
  -		<tagclass>com.netwebapps.taglib.search.CollectionTag</tagclass>
  +		<name>Column</name>
  +		<tagclass>com.netwebapps.taglib.search.ColumnTag</tagclass>
  +		<teiclass>com.netwebapps.taglib.search.ColumnTagTei</teiclass>
  +		<bodycontent>JSP</bodycontent>
   		<info>
   			Adds an additional collection to the search tag.
   		</info>
   		<attribute>
  -			<name>directory</name>
  +			<name>id</name>
  +			<required>true</required>
  +			<rtexprvalue>true</rtexprvalue>
  +		</attribute>
  +		<attribute>
  +			<name>runOnce</name>
  +			<required>false</required>
  +			<rtexprvalue>true</rtexprvalue>
  +		</attribute>
  +		<attribute>
  +			<name>throwOnException</name>
  +			<required>false</required>
  +			<rtexprvalue>true</rtexprvalue>
  +		</attribute>
  +	</tag>
  +	<tag>
  +		<name>Field</name>
  +		<tagclass>com.netwebapps.taglib.search.FieldTag</tagclass>
  +		<teiclass>com.netwebapps.taglib.search.FieldTagTei</teiclass>
  +		<bodycontent>JSP</bodycontent>
  +		<info>
  +			Output the value for the named field in a search result, empty by default.
  +		</info>
  +		<attribute>
  +			<name>id</name>
   			<required>true</required>
  +			<rtexprvalue>true</rtexprvalue>
  +		</attribute>
  +		<attribute>
  +			<name>name</name>
  +			<required>true</required>
  +			<rtexprvalue>true</rtexprvalue>
  +		</attribute>
  +		<attribute>
  +			<name>throwOnException</name>
  +			<required>false</required>
   			<rtexprvalue>true</rtexprvalue>
   		</attribute>
   	</tag>
  
  
  
  1.2       +1 -1      jakarta-lucene-sandbox/contributions/taglib/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/taglib/WEB-INF/web.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- web.xml	12 May 2003 14:02:36 -0000	1.1
  +++ web.xml	29 May 2003 17:20:19 -0000	1.2
  @@ -7,8 +7,8 @@
           <session-timeout>30</session-timeout>
       </session-config>
       <welcome-file-list>
  -        <welcome-file>index.jsp</welcome-file>
           <welcome-file>index.html</welcome-file>
  +        <welcome-file>index.jsp</welcome-file>
           <welcome-file>index.htm</welcome-file>
       </welcome-file-list>
   </web-app>
  
  
  
  1.3       +272 -54   jakarta-lucene-sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search/SearchTag.java
  
  Index: SearchTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search/SearchTag.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SearchTag.java	21 May 2003 01:22:22 -0000	1.2
  +++ SearchTag.java	29 May 2003 17:20:19 -0000	1.3
  @@ -1,21 +1,37 @@
   package com.netwebapps.taglib.search;
   
  +import java.io.File;
  +import java.io.IOException;
   import java.util.*;
  -import javax.servlet.jsp.*;
  -import javax.servlet.jsp.tagext.*;
  -import javax.servlet.http.*;
  -import java.io.*;
  -
  -import org.apache.lucene.analysis.*;
  -import org.apache.lucene.document.*;
  -import org.apache.lucene.index.*;
  -import org.apache.lucene.search.*;
  -import org.apache.lucene.queryParser.*;
  +
  +import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.jsp.JspException;
  +import javax.servlet.jsp.PageContext;
  +import javax.servlet.jsp.tagext.BodyTagSupport;
  +
  +import org.apache.lucene.analysis.Analyzer;
  +import org.apache.lucene.analysis.SimpleAnalyzer;
  +import org.apache.lucene.analysis.StopAnalyzer;
  +import org.apache.lucene.analysis.WhitespaceAnalyzer;
  +import org.apache.lucene.analysis.de.GermanAnalyzer;
  +import org.apache.lucene.analysis.de.WordlistLoader;
  +import org.apache.lucene.analysis.standard.StandardAnalyzer;
  +import org.apache.lucene.document.Document;
  +import org.apache.lucene.document.Field;
  +import org.apache.lucene.index.IndexReader;
  +import org.apache.lucene.queryParser.ParseException;
  +import org.apache.lucene.queryParser.QueryParser;
  +import org.apache.lucene.queryParser.MultiFieldQueryParser;
  +import org.apache.lucene.search.Hits;
  +import org.apache.lucene.search.IndexSearcher;
  +import org.apache.lucene.search.MultiSearcher;
  +import org.apache.lucene.search.Query;
   
   /*
    * 
  - * @author Bryan LaPlante
  - * @param 
  + * @company Network Web Application
  + * @url http://www.netwebapps.com
  + * @author Bryan LaPlante 
    *
    */
   public class SearchTag extends BodyTagSupport{
  @@ -32,49 +48,52 @@
   	private Enumeration fields = null;
   	private HashMap aField = new HashMap();
   	private int ROWCOUNT = 0;
  -	private int PAGECOUNT = 1;
  +	private int PAGECOUNT = 0;
   	private int HITCOUNT = 0;
   	private boolean abort = false;
   	private Analyzer analyzer = null;
  +	private Document doc = null;
  +	private ArrayList idxArray = new ArrayList();
  +	private MultiSearcher msearcher = null;
  +	private final int GERMANAN_ALYZER = 0;
  +	private final int SIMPLE_ANALYZER = 1;
  +	private final int STANDARD_ANALYZER = 2;
  +	private final int STOP_ANALYZER = 3;
  +	private final int WHITESPACE_ANALYZER = 4;
   
   	public int startRow = 0;
   	public int maxRows = 50;  
  -	public String rowCount = "0";
  -	public String pageCount = "1";
  -	public String hitCount = "0";
  +	public int rowCount = 0;
  +	public int pageCount = 1;
  +	public int hitCount = 0;
  +	public int loopCount = 0;
   	public String firstPage = "";
   	public String nextPage = "";
   	public String previousPage = "";
   	public String lastPage = "";
   	public LinkedList pageList = new LinkedList();
   	public boolean throwOnException = false;
  +	public String[] stopWords = new String[0];
  +	public String[] fieldList = new String[0];
  +	public int[] flagList = new int[0];
  +	public String search = "contents";
  +	public int analyzerType = STANDARD_ANALYZER;
   	
   	
   	public int doStartTag() throws JspException{
  -		
  -		doSearch();
  -		if(abort){
  -			rowCount = new Integer(startRow + ROWCOUNT).toString();
  -			pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE);
  -			return SKIP_BODY;
  -		}
  -		searchItr = hitArray.iterator();
  -		if(searchItr.hasNext()){
  -			aField = (HashMap) searchItr.next();
  -			rowCount = new Integer(startRow + ROWCOUNT++).toString();
  -			pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE);
  -			return EVAL_BODY_AGAIN;
  -		}
  -		return SKIP_BODY; 
  +		rowCount = startRow + ROWCOUNT++;
  +		loopCount++;
  +		pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE);
  +		return EVAL_BODY_AGAIN;
   	}
   	
   	public void doInitBody() throws JspException{
  +		doSearch();
   		if(!abort){
  -			doSearch();
   			searchItr = hitArray.iterator();
   			if(searchItr.hasNext()){
   				aField = (HashMap) searchItr.next();
  -				rowCount = new Integer(startRow + ROWCOUNT).toString();
  +				rowCount = startRow + ROWCOUNT++;
   				pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE);
   			}
   		}
  @@ -83,7 +102,9 @@
   	public int doAfterBody() throws JspException{
   		
   		if(abort){
  -			rowCount = new Integer(startRow + ROWCOUNT).toString();
  +			hitCount = 0;
  +			loopCount = 0;
  +			rowCount = startRow + ROWCOUNT;
   			pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE);
   			return SKIP_BODY;
   		}
  @@ -98,7 +119,8 @@
   		
   		if(searchItr.hasNext()){
   			aField = (HashMap) searchItr.next();
  -			rowCount = new Integer(startRow + ROWCOUNT++).toString();
  +			rowCount = startRow + ROWCOUNT++;
  +			loopCount++;
   			pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE);
   			return EVAL_BODY_AGAIN;
   		}
  @@ -108,6 +130,8 @@
   	public int doEndTag() throws JspException{
   
   		if(abort){
  +			hitCount = 0;
  +			pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE);
   			return EVAL_PAGE;
   		}
   		
  @@ -135,6 +159,25 @@
   	}
   	
   	public void release(){
  +		hitMap = null;
  +		hitArray = null;
  +		collection = "";
  +		searcher = null;
  +		query = null;
  +		hits = null;
  +		thispage = 0;
  +		criteria = ""; 
  +		searchItr = null;
  +		fields = null;
  +		aField = new HashMap();
  +		ROWCOUNT = 0;
  +		PAGECOUNT = 1;
  +		HITCOUNT = 0;
  +		abort = false;
  +		analyzer = null;
  +		doc = null;
  +		idxArray = null;
  +		msearcher = null;
   	}
   	
   	public String getField(String name){
  @@ -150,10 +193,32 @@
   		return aField.keySet();
   	}
   	
  +
  +	public void addCollection(String name) throws JspException{
  +		try {
  +			searcher = new IndexSearcher(IndexReader.open(name));
  +			idxArray.add(searcher);
  +		} catch (IOException e) {
  +			if(throwOnException){
  +				throw new JspException("Error occured while opening " + name + " ]: " + e);
  +			}
  +		}
  +	}
  +	
   	public void doSearch() throws JspException{
   
   		try {
  -			searcher = new IndexSearcher(IndexReader.open(collection));
  +			if(idxArray.size() > 0){
  +				IndexSearcher[] idxToArray = new IndexSearcher[idxArray.size()];
  +				Iterator idxIter = idxArray.iterator();
  +				int arrayCount = 0;
  +				while(idxIter.hasNext()){
  +					idxToArray[arrayCount++] = (IndexSearcher) idxIter.next();
  +				}
  +				msearcher = new MultiSearcher(idxToArray);
  +			}else{
  +				throw new JspException("No collection has been specified");
  +			}
   		} catch (IOException e) {
   			if(throwOnException){
   				throw new JspException("IndexSearcher(IndexReader.open(collection)): " + e);
  @@ -161,31 +226,80 @@
   			abort = true;
   		}
   		if(!abort){
  -			analyzer = new StopAnalyzer();
  +			// choosing the type of analyzer to use in this search
  +			switch (analyzerType) {
  +				case GERMANAN_ALYZER:
  +					if(stopWords.length > 0){
  +						analyzer = new GermanAnalyzer(stopWords);
  +					}else{
  +						if(throwOnException){
  +							throw new JspException("In order to use a GermanAnalyzer you must provide a list
of stop words");
  +						}
  +						abort = true;
  +					}
  +					break;
  +				case SIMPLE_ANALYZER:
  +					analyzer = new SimpleAnalyzer();
  +					break;
  +				case STANDARD_ANALYZER:
  +					if(stopWords.length > 0){
  +						analyzer = new StandardAnalyzer(stopWords);
  +					}else{
  +						analyzer = new StandardAnalyzer();
  +					}
  +					break;
  +				case STOP_ANALYZER:
  +					if(stopWords.length > 0){
  +						analyzer = new StopAnalyzer(stopWords);
  +					}else{
  +						analyzer = new StopAnalyzer();
  +					}
  +					break;
  +				case WHITESPACE_ANALYZER:
  +					analyzer = new WhitespaceAnalyzer();
  +					break;
  +
  +				default :
  +				if(stopWords.length > 0){
  +					analyzer = new StandardAnalyzer(stopWords);
  +				}else{
  +					analyzer = new StandardAnalyzer();
  +				}
  +					break;
  +			}
   
   			try {
  -				query = QueryParser.parse(criteria, "contents", analyzer);
  +				// choose a query parser
  +				if(fieldList.length > 0){
  +					if(flagList.length > 0){
  +						query = MultiFieldQueryParser.parse(criteria,fieldList,flagList,analyzer);
  +					}else{
  +						query = MultiFieldQueryParser.parse(criteria,fieldList,analyzer);
  +					}
  +				}else{
  +					query = QueryParser.parse(criteria, search, analyzer);
  +				}
   			} catch (ParseException e) {
   				if(throwOnException){
  -					throw new JspException("QueryParser.parse(criteria,contents,analyzer): " + e);
  +					throw new JspException("If using fieldList and or flagList check to see you have the
same number of items in each: " + e);
   				}
   				abort = true;
   			}
   			if(!abort){
   				try {
  -					hits = searcher.search(query);
  +					hits = msearcher.search(query);
   				} catch (IOException e) {
   					if(throwOnException){
  -						throw new JspException("searcher.search(query): " + e);
  +						throw new JspException("msearcher.search(query): " + e);
   					}
   					abort = true;
   				}
   		
   				if(!abort){
  -					hitCount = new Integer(hits.length()).toString();
  +					hitCount = hits.length();
   					HITCOUNT = hits.length();
  -					PAGECOUNT = PAGECOUNT = (int) (( (double) startRow) / maxRows );
  -					pageCount = new Integer(PAGECOUNT).toString();
  +					PAGECOUNT = (int) (( (double) startRow) / maxRows );
  +					pageCount = PAGECOUNT;
   					thispage = maxRows;
   					if ((startRow + maxRows) > hits.length()) {
   							thispage = hits.length() - startRow;
  @@ -193,7 +307,6 @@
   					hitArray = new ArrayList();
   					for (int i = startRow; i < (thispage + startRow); i++) {
   						hitMap = new HashMap();
  -						Document doc = null;
   						try {
   							doc = hits.doc(i);
   						} catch (IOException e) {
  @@ -225,11 +338,16 @@
   				}
   			}
   		}
  -	}
  -	
  -	/* setters */
  -	
  -	
  +		if(msearcher != null){
  +			try {
  +				msearcher.close();
  +			} catch (IOException e) {
  +				if(throwOnException){
  +					throw new JspException("A problem occured trying to close the searcher : " + e);
  +				}
  +			}
  +		}
  +	}	
   	
   	public void setCriteria(String criteria){
   		this.criteria = criteria;
  @@ -261,15 +379,20 @@
   		this.maxRows = maxRows;
   	}
   	
  -	public void setCollection(String collection){
  -		this.collection = collection;
  +	public void setCollection(String collection) throws JspException{
  +		idxArray = new ArrayList();
  +		String[] collectionArray = collection.split(",");
  +		for(int i=0; i<collectionArray.length; i++){
  +			this.addCollection(collectionArray[i]);
  +		}
   	}
   	
   	public void setThrowOnException(String bool){
   		this.throwOnException = new Boolean(bool).booleanValue();
   	}
  -	
  -	/* getters */
  +	public void setThrowOnException(boolean b) {
  +		throwOnException = b;
  +	}
   	
   	public int getStartRow(){
   		return startRow;
  @@ -278,4 +401,99 @@
   	public int getMaxRows(){
   		return maxRows;
   	}
  +	/**
  +	 * @param string -- a comma seperated list of stop words.
  +	 */
  +	public void setStopWords(String swords) throws JspException{
  +		Hashtable wordTable = new Hashtable();
  +		String[] temp = new String[wordTable.size()];
  +		if(swords.split(",").length > 0){
  +			String[] words = swords.split(",");
  +			for (int i = 0; i < words.length; i++) {
  +				if(new File(words[i]).isFile()){
  +					wordTable.putAll(WordlistLoader.getWordtable(words[i]));
  +				}else{
  +					wordTable.put(words[i], words[i]);
  +				}
  +			}
  +			temp = new String[wordTable.size()];
  +
  +			int count = 0;
  +			if(wordTable.size() > 0){
  +				Iterator wtIter = wordTable.keySet().iterator();
  +				while (wtIter.hasNext()){
  +					temp[count++] = (String) wtIter.next();
  +				}
  +			}
  +		}
  +		stopWords = temp;
  +	}
  +	
  +//	public void setStopWords(String[] swords) throws JspException{
  +//		stopWords = swords;
  +//	}
  +
  +	/**
  +	 * @param string
  +	 */
  +	public void setFlagList(String fg) {
  +		int[] list = new int[0];
  +		if(fg.split(",").length > 0){
  +			String[] ssplit = fg.split(",");
  +			Integer fsplit = new Integer(fg.split(",").length);
  +			list = new int[fsplit.intValue()];
  +			for(int i=0; i < fsplit.intValue(); i++){
  +				if(ssplit[i].equalsIgnoreCase("NORMAL")){
  +					list[i] = MultiFieldQueryParser.NORMAL_FIELD;
  +				}else if(ssplit[i].equalsIgnoreCase("PROHIBITED")){
  +					list[i] = MultiFieldQueryParser.PROHIBITED_FIELD;
  +				}else if(ssplit[i].equalsIgnoreCase("REQUIRED")){
  +					list[i] = MultiFieldQueryParser.REQUIRED_FIELD;
  +				}
  +			}
  +		}
  +		flagList = list;
  +	}
  +
  +	/**
  +	 * @param string
  +	 */
  +	public void setFieldList(String fl) {
  +		if(fl.split(",").length > 0){
  +			fieldList = fl.split(",");
  +		}
  +	}
  +	/**
  +	 * @param string
  +	 */
  +	public void setFieldList(String[] fl) {
  +		fieldList = fl;
  +	}
  +
  +	/**
  +	 * @param string
  +	 */
  +	public void setSearch(String string) {
  +		search = string;
  +	}
  +
  +	/**
  +	 * @param string
  +	 */
  +	public void setAnalyzerType(String atype) {
  +		if(atype.equalsIgnoreCase("GERMANAN_ALYZER")){
  +			analyzerType = 0;
  +		}else if(atype.equalsIgnoreCase("SIMPLE_ANALYZER")){
  +			analyzerType = 1;
  +		}else if(atype.equalsIgnoreCase("STANDARD_ANALYZER")){
  +			analyzerType = 2;
  +		}else if(atype.equalsIgnoreCase("STOP_ANALYZER")){
  +			analyzerType = 3;
  +		}else if(atype.equalsIgnoreCase("WHITESPACE_ANALYZER")){
  +			analyzerType = 4;
  +		}else{
  +			analyzerType = 2;
  +		}
  +	}
  +
   }
  
  
  
  1.2       +2 -1      jakarta-lucene-sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search/SearchTagTei.java
  
  Index: SearchTagTei.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search/SearchTagTei.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SearchTagTei.java	12 May 2003 14:02:36 -0000	1.1
  +++ SearchTagTei.java	29 May 2003 17:20:19 -0000	1.2
  @@ -1,7 +1,8 @@
   package com.netwebapps.taglib.search;
   
   /**
  - * @author Network Web Application
  + * @company Network Web Application
  + * @url http://www.netwebapps.com
    * @author Bryan LaPlante 
    *
    */
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message