You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by eh...@apache.org on 2004/01/12 17:41:56 UTC
cvs commit: jakarta-lucene-sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search SearchTag.java
ehatcher 2004/01/12 08:41:56
Modified: contributions build.xml
contributions/taglib index.html readme.txt result.jsp
contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search
SearchTag.java
Log:
taglib cleanup, but still busted functionally
Revision Changes Path
1.4 +2 -3 jakarta-lucene-sandbox/contributions/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/build.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- build.xml 5 Jan 2004 16:35:10 -0000 1.3
+++ build.xml 12 Jan 2004 16:41:56 -0000 1.4
@@ -16,12 +16,11 @@
<subant target="">
<property name="dist.dir" location="${dist.dir}"/>
- <!-- Exclude LARM for now,
- until its build is brought up to speed
+ <!-- LARM now lives at SourceForge. taglib compiles, but JSP is busted
-->
<fileset dir="."
includes="*/build.xml"
- excludes="webcrawler-LARM/build.xml"
+ excludes="webcrawler-LARM/build.xml,taglib/build.xml"
/>
</subant>
</target>
1.3 +7 -7 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- index.html 29 May 2003 17:20:19 -0000 1.2
+++ index.html 12 Jan 2004 16:41:56 -0000 1.3
@@ -22,23 +22,23 @@
<h2 align="center">Test page for Lucene-taglib</h2>
<table border=0 width="100%">
<tr>
- <td colspan=3><b>Ledgend</b></td>
+ <td colspan=3><b>Legend</b></td>
</tr>
<tr>
<td style="width:100px;">Required field</td>
<td style="background-color:red; width:5px;"> </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
+ 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
+ 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>
@@ -70,7 +70,7 @@
<tr><td>analyzerType</td>
<td>
<select class="data" name="analyzerType">
- <option value="GERMANAN_ALYZER">GERMANAN_ALYZER</option>
+ <option value="GERMAN_ANALYZER">GERMAN_ANALYZER</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>
@@ -89,13 +89,13 @@
<tr><td colspan=4><%= rs.nextPage %><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><%= rs.previousPage %><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><%= rs.lastPage %><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><%= rs.score %><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
+ <tr><td colspan=4><%= rs.score %><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"><%= rs.pageList %></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><%= rs.getField(String name) %> 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><%= rs.getFields() %> 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> </td><th><LUCENE:Column </th><td><span class="required">id="col"</span></td><td> </td></tr>
<tr><td> </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> </td></tr>
<tr><td> </td><td>throwOnException</td><td><select class="data" name="columnthrowOnException"><option value="true">true</option><option class="default" value="false" SELECTED>false</option></select>></td><td> </td></tr>
1.3 +7 -4 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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- readme.txt 29 May 2003 17:20:19 -0000 1.2
+++ readme.txt 12 Jan 2004 16:41:56 -0000 1.3
@@ -1,3 +1,6 @@
+WARNING: THE CURRENT STATE OF THIS CODEBASE IS BROKEN! RESULTS.JSP
+NEEDS A BIT OF WORK TO FUNCTION PROPERLY.
+
INTRODUCTION
The lucene-taglib project provides a tag library for searching
a lucene-index.
@@ -6,13 +9,13 @@
1. download this project and create a context in your favorite
servelt container called lucene-taglib.
2. copy the file under the taglib directory into your new context.
-3. open result.jsp and locate the collection attribute of the
+3. open result.jsp and locate the collection attribute of the
<LUCENE:Search> tag.
4. change the collection attribute to point to a lucene-index
that you created using the system appropriate path.
-5. open index.jsp in your browser and enter search criteria
+5. open index.jsp in your browser and enter search criteria
and click the submit button.
-
+
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
@@ -62,7 +65,7 @@
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
+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.
1.4 +13 -17 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- result.jsp 29 May 2003 17:20:19 -0000 1.3
+++ result.jsp 12 Jan 2004 16:41:56 -0000 1.4
@@ -9,7 +9,7 @@
</style>
</head>
<body>
-<%
+<%
String startRow = "";
String maxRows = "";
String criteria = "";
@@ -25,8 +25,7 @@
String columnthrowOnException = "false";
String runOnce = "false";
String query = "";
-
- try{
+
query = request.getQueryString();
criteria = request.getParameter("criteria");
startRow = request.getParameter("startRow");
@@ -40,18 +39,15 @@
fieldthrowOnException = request.getParameter("fieldthrowOnException");
columnthrowOnException = request.getParameter("columnthrowOnException");
runOnce = request.getParameter("runOnce");
- }
- catch(Exception e){
- }
%>
<h3> Search results for "<%= criteria %>"</h3>
<table border=3>
- <LUCENE:Search id="rs"
- throwOnException="<%= throwOnException %>"
- collection="<%= collection %>"
- criteria="<%= criteria %>"
- startRow="<%= startRow %>"
+ <LUCENE:Search id="rs"
+ throwOnException="<%= throwOnException %>"
+ collection="<%= collection %>"
+ criteria="<%= criteria %>"
+ startRow="<%= startRow %>"
maxRows="<%= maxRows %>"
analyzerType="<%= analyzerType %>"
search="<%= search %>"
@@ -61,7 +57,7 @@
<tr>
<LUCENE:Column id="header" runOnce="true" throwOnException="false">
<% colCount = header.columnCount; %>
-
+
<th><b><%= header.columnName %></b></th>
</LUCENE:Column>
</tr>
@@ -69,17 +65,17 @@
<tr>
<td colspan="<%= col.columnCount %>"><b>[<%= rs.loopCount %>][<%= rs.rowCount %>]</b>
<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>
@@ -133,7 +129,7 @@
</select>
</td>
</tr>
-
+
</table>
</body>
</html>
1.4 +41 -55 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SearchTag.java 29 May 2003 17:20:19 -0000 1.3
+++ SearchTag.java 12 Jan 2004 16:41:56 -0000 1.4
@@ -28,22 +28,21 @@
import org.apache.lucene.search.Query;
/*
- *
+ *
* @company Network Web Application
* @url http://www.netwebapps.com
- * @author Bryan LaPlante
+ * @author Bryan LaPlante
*
*/
public class SearchTag extends BodyTagSupport{
-
+
private HashMap hitMap = null;
private ArrayList hitArray = null;
- private String collection = "";
private IndexSearcher searcher = null;
private Query query = null;
private Hits hits = null;
private int thispage = 0;
- private String criteria = "";
+ private String criteria = "";
private Iterator searchItr = null;
private Enumeration fields = null;
private HashMap aField = new HashMap();
@@ -55,14 +54,14 @@
private Document doc = null;
private ArrayList idxArray = new ArrayList();
private MultiSearcher msearcher = null;
- private final int GERMANAN_ALYZER = 0;
+ private final int GERMAN_ANALYZER = 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 int maxRows = 50;
public int rowCount = 0;
public int pageCount = 1;
public int hitCount = 0;
@@ -78,15 +77,15 @@
public int[] flagList = new int[0];
public String search = "contents";
public int analyzerType = STANDARD_ANALYZER;
-
-
+
+
public int doStartTag() throws JspException{
rowCount = startRow + ROWCOUNT++;
loopCount++;
pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE);
return EVAL_BODY_AGAIN;
}
-
+
public void doInitBody() throws JspException{
doSearch();
if(!abort){
@@ -98,9 +97,9 @@
}
}
}
-
+
public int doAfterBody() throws JspException{
-
+
if(abort){
hitCount = 0;
loopCount = 0;
@@ -108,7 +107,7 @@
pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE);
return SKIP_BODY;
}
-
+
try{
getBodyContent().writeOut(getPreviousOut());
getBodyContent().clearBody();
@@ -116,7 +115,7 @@
catch(IOException e){
throw new JspException(e.toString());
}
-
+
if(searchItr.hasNext()){
aField = (HashMap) searchItr.next();
rowCount = startRow + ROWCOUNT++;
@@ -126,7 +125,7 @@
}
return SKIP_BODY;
}
-
+
public int doEndTag() throws JspException{
if(abort){
@@ -134,11 +133,11 @@
pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE);
return EVAL_PAGE;
}
-
+
try{
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
String relativePath = req.getRequestURI();
- firstPage = relativePath + "?startRow=0&maxRows=" + maxRows;
+ firstPage = relativePath + "?startRow=0&maxRows=" + maxRows;
nextPage = relativePath + "?startRow=" + ((startRow + maxRows <= HITCOUNT)? startRow + maxRows : startRow) + "&maxRows=" + maxRows;
previousPage = relativePath + "?startRow=" + ((startRow - maxRows >=0)? startRow - maxRows : 0 ) + "&maxRows=" + maxRows;
lastPage = relativePath + "?startRow=" + (((HITCOUNT - maxRows) >= 0)? HITCOUNT - maxRows : 0) + "&maxRows=" + maxRows;
@@ -157,16 +156,15 @@
pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE);
return EVAL_PAGE;
}
-
+
public void release(){
hitMap = null;
hitArray = null;
- collection = "";
searcher = null;
query = null;
hits = null;
thispage = 0;
- criteria = "";
+ criteria = "";
searchItr = null;
fields = null;
aField = new HashMap();
@@ -179,20 +177,20 @@
idxArray = null;
msearcher = null;
}
-
+
public String getField(String name){
if(aField != null){
if(aField.containsKey(name)){
- return aField.get((String) name).toString();
+ return aField.get(name).toString();
}
}
return "";
}
-
+
public Set getFields(){
return aField.keySet();
}
-
+
public void addCollection(String name) throws JspException{
try {
@@ -204,7 +202,7 @@
}
}
}
-
+
public void doSearch() throws JspException{
try {
@@ -228,7 +226,7 @@
if(!abort){
// choosing the type of analyzer to use in this search
switch (analyzerType) {
- case GERMANAN_ALYZER:
+ case GERMAN_ANALYZER:
if(stopWords.length > 0){
analyzer = new GermanAnalyzer(stopWords);
}else{
@@ -294,7 +292,7 @@
}
abort = true;
}
-
+
if(!abort){
hitCount = hits.length();
HITCOUNT = hits.length();
@@ -347,12 +345,12 @@
}
}
}
- }
-
+ }
+
public void setCriteria(String criteria){
this.criteria = criteria;
}
-
+
public void setStartRow(String startRow){
try{
this.startRow = Integer.parseInt(startRow);
@@ -361,11 +359,11 @@
this.startRow = 0;
}
}
-
+
public void setStartRow(int startRow){
this.startRow = startRow;
}
-
+
public void setMaxRows(String maxRows){
try{
this.maxRows = Integer.parseInt(maxRows);
@@ -374,11 +372,11 @@
this.maxRows = 10;
}
}
-
+
public void setMaxRows(int maxRows){
this.maxRows = maxRows;
}
-
+
public void setCollection(String collection) throws JspException{
idxArray = new ArrayList();
String[] collectionArray = collection.split(",");
@@ -386,24 +384,22 @@
this.addCollection(collectionArray[i]);
}
}
-
+
public void setThrowOnException(String bool){
this.throwOnException = new Boolean(bool).booleanValue();
}
public void setThrowOnException(boolean b) {
throwOnException = b;
}
-
+
public int getStartRow(){
return startRow;
}
-
+
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()];
@@ -428,14 +424,11 @@
}
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){
@@ -455,33 +448,26 @@
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
+ * @param atype
+ * @todo this is crying for constants, not string comparisons
*/
public void setAnalyzerType(String atype) {
- if(atype.equalsIgnoreCase("GERMANAN_ALYZER")){
+ if(atype.equalsIgnoreCase("GERMAN_ALYZER")){
analyzerType = 0;
}else if(atype.equalsIgnoreCase("SIMPLE_ANALYZER")){
analyzerType = 1;
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org