I added a static field for the default search Field.

I have added a SearchBean.close() to people can close the searcher.


git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150811 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Peter Carlson 2002-09-07 01:00:52 +00:00
parent 18d1f6e5df
commit a75302f000
1 changed files with 13 additions and 4 deletions

View File

@ -33,13 +33,15 @@ import java.io.IOException;
*/
public class SearchBean extends Object {
static final String SORT_FIELD_RELEVANCE = "relevance";
private String queryString = "";
private String querySortField = "relevance"; // default
private String querySortField = SORT_FIELD_RELEVANCE; // default
private String queryType = "";
private Directory directory;
private HitsIterator hitsIterator = null;
private String defaultSearchField = "text";
private long searchTime = 0;
private Searcher searcher = null;
// static Logger logger = Logger.getLogger(SearchBean.class.getName());
// static Logger searchLogger = Logger.getLogger("searchLog");
@ -116,8 +118,8 @@ public class SearchBean extends Object {
long startTime = System.currentTimeMillis();
Hits hits = searchHits(queryString, queryType);
if (hits == null) {return null;}
if (hits.length() == 0) {return null;}
//if (hits == null) {return null;}
//if (hits.length() == 0) {return null;}
HitsIterator hi = new HitsIterator(hits, querySortField);
long endTime = System.currentTimeMillis();
@ -136,7 +138,7 @@ public class SearchBean extends Object {
// Provide for multiple indices in the future
Searcher searcher = new IndexSearcher(directory);
searcher = new IndexSearcher(directory);
Query query = getQuery(queryString, defaultSearchField);
//System.out.println("###querystring= "+query.toString(defaultSearchField));
Hits hits = searcher.search(query);
@ -145,6 +147,13 @@ public class SearchBean extends Object {
return hits;
}
/**
* frees resources associated with SearchBean search
*/
public void close() throws IOException{
searcher.close();
}
/** <queryString> | <queryType> | <querySortField>
*/
public String toString(){