Skip to content

Apache Lucene open-source search software

taglib cleanup, but still busted functionally

Erik Hatcher259f0f8e2fd7
diff --git a/sandbox/contributions/build.xml b/sandbox/contributions/build.xml
index 89f88863f86..b2e44188a10 100644
--- a/sandbox/contributions/build.xml
+++ b/sandbox/contributions/build.xml
@@ -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>
diff --git a/sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search/SearchTag.java b/sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search/SearchTag.java
index 9da91f32488..41b18b79e32 100755
--- a/sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search/SearchTag.java
+++ b/sandbox/contributions/taglib/WEB-INF/classes/com/netwebapps/taglib/search/SearchTag.java
@@ -28,22 +28,21 @@ import org.apache.lucene.search.MultiSearcher;
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 @@ public class SearchTag extends BodyTagSupport{
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 class SearchTag extends BodyTagSupport{
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 class SearchTag extends BodyTagSupport{
}
}
}
-
+
public int doAfterBody() throws JspException{
-
+
if(abort){
hitCount = 0;
loopCount = 0;
@@ -108,7 +107,7 @@ public class SearchTag extends BodyTagSupport{
pageContext.setAttribute(getId(),this,PageContext.PAGE_SCOPE);
return SKIP_BODY;
}
-
+
try{
getBodyContent().writeOut(getPreviousOut());
getBodyContent().clearBody();
@@ -116,7 +115,7 @@ public class SearchTag extends BodyTagSupport{
catch(IOException e){
throw new JspException(e.toString());
}
-
+
if(searchItr.hasNext()){
aField = (HashMap) searchItr.next();
rowCount = startRow + ROWCOUNT++;
@@ -126,7 +125,7 @@ public class SearchTag extends BodyTagSupport{
}
return SKIP_BODY;
}
-
+
public int doEndTag() throws JspException{
if(abort){
@@ -134,11 +133,11 @@ public class SearchTag extends BodyTagSupport{
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 @@ public class SearchTag extends BodyTagSupport{
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 @@ public class SearchTag extends BodyTagSupport{
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 class SearchTag extends BodyTagSupport{
}
}
}
-
+
public void doSearch() throws JspException{
try {
@@ -228,7 +226,7 @@ public class SearchTag extends BodyTagSupport{
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 @@ public class SearchTag extends BodyTagSupport{
}
abort = true;
}
-
+
if(!abort){
hitCount = hits.length();
HITCOUNT = hits.length();
@@ -347,12 +345,12 @@ public class SearchTag extends BodyTagSupport{
}
}
}
- }
-
+ }
+
public void setCriteria(String criteria){
this.criteria = criteria;
}
-
+
public void setStartRow(String startRow){
try{
this.startRow = Integer.parseInt(startRow);
@@ -361,11 +359,11 @@ public class SearchTag extends BodyTagSupport{
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 @@ public class SearchTag extends BodyTagSupport{
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 @@ public class SearchTag extends BodyTagSupport{
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 @@ public class SearchTag extends BodyTagSupport{
}
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 @@ public class SearchTag extends BodyTagSupport{
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;
diff --git a/sandbox/contributions/taglib/index.html b/sandbox/contributions/taglib/index.html
index 7dcda056d3b..9d47851f32a 100755
--- a/sandbox/contributions/taglib/index.html
+++ b/sandbox/contributions/taglib/index.html
@@ -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;">&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
+ 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>&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
+ <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>
diff --git a/sandbox/contributions/taglib/readme.txt b/sandbox/contributions/taglib/readme.txt
index 693ecb9b648..729701d485b 100755
--- a/sandbox/contributions/taglib/readme.txt
+++ b/sandbox/contributions/taglib/readme.txt
@@ -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 @@ INSTRUCTIONS
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 @@ 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
+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.
diff --git a/sandbox/contributions/taglib/result.jsp b/sandbox/contributions/taglib/result.jsp
index 100d8a9a7c9..de1b9db94c9 100755
--- a/sandbox/contributions/taglib/result.jsp
+++ b/sandbox/contributions/taglib/result.jsp
@@ -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>&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>
@@ -133,7 +129,7 @@
</select>
</td>
</tr>
-
+
</table>
</body>
</html>
\ No newline at end of file