/*============================================================================ Project: Simple JAVA Search Engine for Keyword Search JAVA Source file for the class SearchEngine COPYRIGHT (C), 1998-2000, Thomas Baier, R Core Development Team * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, a copy is available at * http://www.r-project.org/Licenses/ $Rev: 42315 $ $LastChangedDate: 2007-07-25 12:27:41 +0200 (Wed, 25 Jul 2007) $ $Author: ripley $ ============================================================================*/ import java.applet.*; import java.awt.*; import java.net.*; import java.io.*; import java.util.*; public class SearchEngine extends Applet { public SearchEngine () { iIndexTable = null; iSearchTerm = null; Tracer.write ("SearchEngine initializing\n"); return; } public String getAppletInfo () { return "Name: SearchEngine\r\n" + "Author: Thomas Baier\r\n" + "(C) 1998-2000 Thomas Baier, R Core Development Team"; } public void init () { resize(640, 240); // get the name of the index file String indexName = getParameter (cIndexKeyword); String searchTerm = getParameter (cSearchKeyword); Tracer.write ("Index file is \"" + indexName + "\"\n"); Tracer.write ("Search term is \"" + searchTerm + "\"\n"); // use a default index file if none specified if (indexName == null) { indexName = cIndexFile; } iSearchTerm = searchTerm; /* * examine the URL to get the search term... * * if the URL ends with ?SEARCHTERM=xxxxx we know, xxxxx is the search term */ { URL url = getDocumentBase (); String urlString = url.toString (); int index = urlString.indexOf ("?" + cSearchKeyword + "="); Tracer.write ("URL is \"" + urlString + "\"\n"); // if found, take the rest as the search string if (index >= 0) { iSearchTerm = urlString.substring (index + 2 + cSearchKeyword.length ()); Tracer.write ("found search term \"" + iSearchTerm + "\" in URL\n"); } } readIndexFile (indexName); return; } public void destroy () { return; } public void paint (Graphics g) { return; } public void start () { Tracer.start (); return; } public void stop () { Tracer.stop (); return; } /* perform the search and return result as string */ public String search (String key, boolean searchDesc, boolean searchKeywords, boolean searchAliases) { iSearchTerm = key; Tracer.write ("Search for \"" + iSearchTerm + "\" started\n"); if(searchDesc){ Tracer.write("Searching in Descriptions\n"); } if(searchKeywords){ Tracer.write("Searching in Keywords\n"); } if(searchAliases){ Tracer.write("Searching in Aliases\n"); } Vector foundItems = null; if (iSearchTerm != null) { foundItems = iIndexTable.search (iSearchTerm, searchDesc, searchKeywords, searchAliases); } else { foundItems = null; } String result = null; // if nothing found, return a special string if (foundItems == null) { result = "No matches for \"" + iSearchTerm + "\" have been found!