You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by ca...@apache.org on 2002/09/07 03:00:52 UTC

cvs commit: jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans SearchBean.java

carlson     2002/09/06 18:00:52

  Modified:    contributions/searchbean/src/java/org/apache/lucene/beans
                        SearchBean.java
  Log:
  I added a static field for the default search Field.

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

  
  Revision  Changes    Path
  1.2       +13 -4     jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/SearchBean.java
  
  Index: SearchBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/SearchBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SearchBean.java	23 May 2002 00:45:04 -0000	1.1
  +++ SearchBean.java	7 Sep 2002 01:00:52 -0000	1.2
  @@ -33,13 +33,15 @@
    */
   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 @@
           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,13 +138,20 @@
           
           // 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);
           //System.out.println("Number hits = "+hits.length());
           //logger.debug("queryString = "+query.toString(searchField)+" hits = "+hits.length()+" queryType = "+queryType+" indexPath = "+indexPath );
           return hits;
  +    }
  +    
  +    /**
  +     * frees resources associated with SearchBean search
  +     */
  +    public void close() throws IOException{
  +        searcher.close();
       }
       
       /** <queryString> | <queryType> | <querySortField>
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>