Skip to content

Commit

Permalink
- Fixed issues with creating too many instances of SearchEngine2
Browse files Browse the repository at this point in the history
- moved interactive search to use GET instead of POST since it is a read operation
  • Loading branch information
n8fr8 committed Oct 19, 2010
1 parent 87f1a16 commit f95098e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
25 changes: 16 additions & 9 deletions src/main/java/gov/nysenate/openleg/SearchServlet.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package gov.nysenate.openleg;

import gov.nysenate.openleg.model.Bill;
import gov.nysenate.openleg.model.Transcript;
import gov.nysenate.openleg.search.*;
import gov.nysenate.openleg.search.SearchEngine2;
import gov.nysenate.openleg.search.SearchResultSet;
import gov.nysenate.openleg.search.SenateResponse;
import gov.nysenate.openleg.util.BillCleaner;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.lucene.queryParser.ParseException;

import com.google.gson.Gson;

public class SearchServlet extends HttpServlet implements OpenLegConstants
{
Expand All @@ -30,6 +25,8 @@ public class SearchServlet extends HttpServlet implements OpenLegConstants

private static Logger logger = Logger.getLogger(SearchServlet.class);

private SearchEngine2 searchEngine = null;

/**
* Constructor of the object.
*/
Expand All @@ -42,6 +39,13 @@ public SearchServlet() {
*/
public void destroy() {
super.destroy();

try {
searchEngine.closeSearcher();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/**
Expand Down Expand Up @@ -295,7 +299,7 @@ else if (startDate != null)
// public SenateResponse search(String searchText, String format, int start, int max, String sortField, boolean reverseSort) throws ParseException, IOException {

String searchFormat = "json";
SenateResponse sr = new SearchEngine2().search(term,searchFormat,start,pageSize,sortField,sortOrder);
SenateResponse sr = searchEngine.search(term,searchFormat,start,pageSize,sortField,sortOrder);

srs = new SearchResultSet();
srs.setTotalHitCount((Integer)sr.getMetadata().get("totalresults"));
Expand Down Expand Up @@ -331,6 +335,9 @@ else if (startDate != null)
*/
public void init() throws ServletException {
logger.info("SearchServlet:init()");

searchEngine = new SearchEngine2();

}

}
4 changes: 4 additions & 0 deletions src/main/java/gov/nysenate/openleg/lucene/Lucene.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ public synchronized void closeWriter() throws IOException {
//

public IndexSearcher openSearcher() throws IOException {

if (indexSearcher == null) {
logger.info("opening search index: " + getDirectory().toString());
indexSearcher = new IndexSearcher(getDirectory(), true);
}

return indexSearcher;
}

Expand Down Expand Up @@ -148,6 +151,7 @@ public LuceneResult search(String searchText, int start, int max, String sortFie

public synchronized void closeSearcher() throws IOException {
if (indexSearcher != null) {
logger.info("closing search index");
indexSearcher.close();
indexSearcher = null;
}
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/gov/nysenate/openleg/search/SearchEngine2.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,8 @@ else if (line.startsWith("create"))

public SearchEngine2() {

//super("C:\\n-lucene\\");
super("/usr/local/openleg/lucene/2");

/*
* "/usr/local/openleg/lucene";
* "C:\\n-lucene\\";
* "/Users/jaredwilliams/Documents/workspace/openleg/lucene2";
*/

logger = Logger.getLogger(SearchEngine2.class);
}

Expand Down
3 changes: 0 additions & 3 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ View Recent:
Community: <a href="<%=appPath%>/comments">View and respond to recent comments</a>
</div>
</form>
<br/><br/>
<a href="http://www.nysenate.gov/blogs/2010/mar/31/announcing-open-legislation-v15-dusty-daedalus">March 31st 2010 Update: Open Legislation v1.5 is released!</a><br/>
Faster search, complex queries, updated user interface and more!
<br/>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $(function () {
{
document.getElementById("quickresult").style.visibility = "visible";
$.ajax({
type: "POST",
type: "GET",
url: "/legislation/search/",
data: dataString,
cache: false,
Expand Down

0 comments on commit f95098e

Please sign in to comment.