Package org.erowid.sperosearch

The applet (and supporting classes) that provides search functionality against the search index generated by Sperowider, during its index phase.

See:
          Description

Class Summary
SearcherApplet Description: Provides searching functionality to web pages.
SearchIndexReader Executes an actual search query over the generated search index.
SearchResultEntry An entry returned by the SperoSearch search engine.
SearchResults A set of SearchResultEntry objects, generated by a call to SearchIndexReader.search(String).
 

Package org.erowid.sperosearch Description

The applet (and supporting classes) that provides search functionality against the search index generated by Sperowider, during its index phase.

When the applet is compiled into a .jar, that file will need to be signed (using the jarsigner app), and then the applet should be placed into the output directory (above the searchindex directory) where the Sperowider run has downloaded files.

Here's a sample (from a version of Erowid's search.html) of how to use the search applet :

<html>
<head>
<title>Sperowider Search Page</title>

<script language="JavaScript">

//
// Starts the search process by calling the search() method on the search applet. This then
// starts the checkSearchResults() loop.
//
function runSearch(PageNumber) {
	var SearchCrit = document.SearchForm.s.value;
	if (SearchCrit.length < 1) { return;}
	
	document.searchapplet.search(SearchCrit);
	document.getElementById('results').innerHTML = "Searching ...";
	
	setTimeout("checkSearchResults(" + PageNumber + ")", 100);
}

//
// Checks for search results. If they're present, calls displaySearchResults. Otherwise, 
// it calls itself after a delay.
//
function checkSearchResults(PageNumber) {
	if (!document.searchapplet.isSearchOver()) {
		showProgress();
		setTimeout("checkSearchResults(" + PageNumber + ")", 100);
	}
	else {
		displaySearchResults(PageNumber);
	}
}

//
// Displays the search results.
//
function displaySearchResults(PageNumber) {
	var SearchCrit = document.SearchForm.s.value;
	var Searcher = document.searchapplet;

	var TextSearchCriteria = SearchCrit;
	var BodyString = "";

	BodyString += "<br><B>\n";
	BodyString += "<FONT SIZE=\"5\">Search results for:</FONT><BR>\n";
	BodyString += "<FONT SIZE=\"3\">" + TextSearchCriteria + "</FONT><BR>\n";
	BodyString += "</B>\n";

	var NumResults = Searcher.getResultCount();
	var StartNum = 0;

	var MaxResults = 10;
	StartNum = MaxResults * PageNumber;
	var EndNum = StartNum + MaxResults;
	if (EndNum > NumResults) { EndNum = NumResults;}

	if (NumResults < 1)  {
	  BodyString += "No Matches for search were found.<BR><BR>\n";
	}

	
	BodyString += "<HR NOSHADE SIZE=1>\n";
	BodyString += "<B>\n";
	BodyString += "Documents " + (StartNum + 1) + " - " + EndNum + " of " + NumResults + " matches\n";
	BodyString += "</B>\n";
	BodyString += "<HR NOSHADE SIZE=1>\n";

	for (i = StartNum; i < EndNum ; i++) {
		showProgress();
	
		var MatchWeight = Searcher.getResultWeight(i);
		var URL = Searcher.getResultURL(i);
		var Tit = Searcher.getResultTitle(i);
		var regT = /^\s*Erowid\s+.*\s*Vaults?\s*\:/g;
		var Title = new String(Tit);
		Title = Title.replace(regT,"");
		var Description = Searcher.getResultDescription(i);
		var Thing = "<dl><dt><strong><a href=\"" + URL + "\">" + Title + "</a></strong></dt>\n";
		
		//if (is_gecko) {
		//	Thing += "<br>\n";
		//}

		Thing += "<dd>" + Description + "<br>\n";
		Thing += "<i><a href=\"" + URL + "\">" + URL + "</a></i>\n";
		Thing += "    <font size=\"-1\">(" + MatchWeight + ")</font>\n";
		Thing += "</dd></dl>\n";
		BodyString += Thing;
	}

	if (MaxResults < NumResults) {
		var NumPages = Math.floor(NumResults / MaxResults) + 1;
		BodyString += "<table>\n";
		BodyString += "<tr>\n";
		BodyString += "<td>Pages:</td>\n";

		if (PageNumber != 0) {
			var PrevPage = PageNumber - 1;
			BodyString += "<td><a href=\"javascript:runSearch(" + PrevPage + ");\"><img src=\"http://www.erowid.org/cgi-bin/search/images/buttonl.gif\" border=0 align=middle width=60 height=\"24\" alt=\"next\"></a></td>\n";
		}

		for (i = 0; i < NumPages; i++) {
			showProgress();
		
			var ThisPageNumber = i + 1;
			if (i == PageNumber) {
				BodyString += "  <td>" + ThisPageNumber + "</td>\n";
			}
			else {
				BodyString += "  <td><a href=\"javascript:runSearch(" + i + ");\">" + 		ThisPageNumber + "</a></td>\n";
			}
		}
	
		var NextPage = PageNumber + 1;
		BodyString += "<td><a href=\"javascript:runSearch(" + NextPage + ");\"><img src=\"http://www.erowid.org/cgi-bin/search/images/buttonr.gif\" border=0 align=middle width=60 height=\"24\" alt=\"next\"></a></td>\n";
		BodyString += "</tr>\n";
		BodyString += "</table>\n";
	}

	document.getElementById('results').innerHTML = BodyString;
}

//
// Utility function to show some progress
//
function showProgress() {
	document.getElementById('results').innerHTML = document.getElementById('results').innerHTML + ".";
}

</script>

</head>

<BODY BGCOLOR="#000000" TEXT="#999977" LINK="#BC5717" VLINK="#AC8A24" ALINK="#CC9933" BACKGROUND="http://www.erowid.org/images/backgrounds/bkg_border_flower_green.jpg">

<div id="header">
	<TABLE><TR><TD>
	<IMG SRC="http://www.erowid.org/images/spacer.gif" WIDTH=78 HEIGHT=1 BORDER="0">
	</TD><TD>
	<IMG SRC="http://www.erowid.org/images/header_blk.gif" WIDTH=600 HEIGHT=69 BORDER=0 USEMAP="#header"><BR><BR><BR>
	<FONT FACE="Arial">

	<APPLET	CODE="org/erowid/sperosearch/SearcherApplet" 
			WIDTH="200" 
			HEIGHT="50" 
			NAME="searchapplet" 
			archive="sperosearch.jar" 
			bgcolor="0">
	</APPLET>

	<form name="SearchForm" onSubmit="runSearch(0); return false;">
		<input type="text" name="s" value="" />
		<input type="submit" value="Search" />
	</form>
</div>

<div id="results">
</div>

<div id="footer">
	<br/><br/><br/>

	<script LANGUAGE="JavaScript">
	<!--

	document.SearchForm.s.focus();
	PageNumber = " + PageNumber + ";

	// -->
	</script>
</div>

</body>
</html>



spero logo small Sperowider is
© 2005 Erowid.org