<%@ page import="historyPlaces.*, java.util.LinkedList, org.apache.lucene.document.*, org.apache.lucene.index.*, org.apache.lucene.search.*, org.apache.lucene.store.*, org.apache.lucene.analysis.*, org.apache.lucene.analysis.standard.*, org.apache.lucene.queryParser.*, java.io.*, java.util.*" %>
<%@ include file="header.inc" %>
<%  
out.print("<h2>Search a Place</h2>");

engine db = new engine();
    
    String indexDirectory = "/var/lib/tomcat4/webapps/dthtran/historyplaces/places-index/index/";
    
    Analyzer analyzer = new StandardAnalyzer();
    
    IndexWriter writer = new IndexWriter(indexDirectory, analyzer, true);
    
    // get all places
    LinkedList places = db.getPlaces();
    for(int i = 0; i < places.size(); i++){
		// Fields to add to Index
    	place curPlace = (place)places.get(i);
    	String placeName = curPlace.getPlaceName();
    	String comment = curPlace.getComment();
    	//out.println(curPlace.getPlaceID() + " | " + curPlace.getParentID() + "<br />");
    	Integer placeID = new Integer(curPlace.getPlaceID());
    	Integer parentID = new Integer(curPlace.getParentID());
    	String placeIDString = placeID.toString();
    	String parentIDString = parentID.toString();
    	//out.println("-----<br />");
    	//out.println(placeIDString + " | " + parentIDString + "<br />");
    	
    	// Create document
    	Document document = new Document();
    	document.add(Field.Text("name", placeName));
    	document.add(Field.Text("comment", comment));
    	document.add(Field.Text("pid", placeIDString));
		document.add(Field.Text("parentid", parentIDString));
    	
    	// Add document to writer
    	writer.addDocument(document);
    }
   
    // out of loop
    writer.optimize();
    writer.close();
%>    


<form action="placeSearch.jsp" method="get">
<input name="query" type="text" size="40"/>
<input type="submit" value="Search"/>
</form>
<p>Enter in the name of a place to begin your search (e.g. McMahon)</p>
<br />
<p>The focus of this part of the deliverable is to provide the user with an interface to search for a place and then have the results returned in an easy to read and understandable fashion. Photos that are associated with the searched place will be shown as well. Lucene was used to build the index and to search over the data files. All fields were available to be searched and were entered in as Text into the index. However, the only available fields to search are 'comment' (comment about place) and 'name' (name of place).</p>
<%@ include file="footer.inc" %>