jford       2004/10/13 15:24:02

  Modified:    jetspeed-api/src/java/org/apache/jetspeed/search
                        SearchEngine.java
               components/search/src/java/org/apache/jetspeed/search/lucene
                        SearchEngineImpl.java
  Added:       jetspeed-api/src/java/org/apache/jetspeed/search
                        SearchResults.java
               components/search/src/java/org/apache/jetspeed/search/lucene
                        SearchResultsImpl.java
  Log:
  Return SearchResults interface instead of iterator
  
  Revision  Changes    Path
  1.2       +1 -2      
jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/search/SearchEngine.java
  
  Index: SearchEngine.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/search/SearchEngine.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SearchEngine.java 28 Sep 2004 20:41:28 -0000      1.1
  +++ SearchEngine.java 13 Oct 2004 22:24:02 -0000      1.2
  @@ -16,7 +16,6 @@
   package org.apache.jetspeed.search;
   
   import java.util.Collection;
  -import java.util.Iterator;
   
   /**
    * @author <a href="mailto: [EMAIL PROTECTED]">Jeremy Ford</a>
  @@ -37,5 +36,5 @@
       
       boolean optimize();
       
  -    Iterator search(String query);
  +    SearchResults search(String query);
   }
  
  
  
  1.1                  
jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/search/SearchResults.java
  
  Index: SearchResults.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.search;
  
  import java.util.Iterator;
  import java.util.List;
  
  /**
   * @author <a href="mailto: [EMAIL PROTECTED]">Jeremy Ford</a>
   *
   */
  public interface SearchResults
  {
      public int size();
      
      public Iterator iterator();
      
      public ParsedObject get(int index);
      
      public List getResults();
      
      public List getResults(int fromIndex, int toIndex);
  }
  
  
  
  1.3       +7 -4      
jakarta-jetspeed-2/components/search/src/java/org/apache/jetspeed/search/lucene/SearchEngineImpl.java
  
  Index: SearchEngineImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jetspeed-2/components/search/src/java/org/apache/jetspeed/search/lucene/SearchEngineImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SearchEngineImpl.java     6 Oct 2004 16:38:04 -0000       1.2
  +++ SearchEngineImpl.java     13 Oct 2004 22:24:02 -0000      1.3
  @@ -32,6 +32,7 @@
   import org.apache.jetspeed.search.ObjectHandler;
   import org.apache.jetspeed.search.ParsedObject;
   import org.apache.jetspeed.search.SearchEngine;
  +import org.apache.jetspeed.search.SearchResults;
   import org.apache.lucene.analysis.Analyzer;
   import org.apache.lucene.analysis.standard.StandardAnalyzer;
   import org.apache.lucene.document.Document;
  @@ -360,7 +361,7 @@
       /* (non-Javadoc)
        * @see org.apache.jetspeed.search.SearchEngine#search(java.lang.String)
        */
  -    public Iterator search(String queryString)
  +    public SearchResults search(String queryString)
       {        
           Searcher searcher = null;
           Hits hits = null;
  @@ -405,7 +406,7 @@
           }
   
           int hitNum = hits.length();
  -        ArrayList results = new ArrayList(hitNum);
  +        ArrayList resultList = new ArrayList(hitNum);
           for(int i=0; i<hitNum; i++)
           {
               ParsedObject result = new BaseParsedObject();
  @@ -464,7 +465,7 @@
                            result.setURL(new URL(url.stringValue()));
                        }
                        
  -                     results.add(i, result);
  +                     resultList.add(i, result);
               }
               catch(IOException e)
               {
  @@ -483,7 +484,9 @@
                   //logger.error("Closing Searcher", ioe);
               }
           }
  -        return results.iterator();
  +        
  +        SearchResults results = new SearchResultsImpl(resultList);
  +        return results;
       }
       
       private Analyzer newAnalyzer() {
  
  
  
  1.1                  
jakarta-jetspeed-2/components/search/src/java/org/apache/jetspeed/search/lucene/SearchResultsImpl.java
  
  Index: SearchResultsImpl.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.search.lucene;
  
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.jetspeed.search.ParsedObject;
  import org.apache.jetspeed.search.SearchResults;
  
  /**
   * @author <a href="mailto: [EMAIL PROTECTED]">Jeremy Ford</a>
   *
   */
  public class SearchResultsImpl implements SearchResults
  {
      List results = null;
      
      public SearchResultsImpl(List results)
      {
          this.results = results;
      }
      
      /* (non-Javadoc)
       * @see org.apache.jetspeed.search.SearchResults#size()
       */
      public int size()
      {
          return results.size();
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.search.SearchResults#iterator()
       */
      public Iterator iterator()
      {
          return results.iterator();
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.search.SearchResults#get(int)
       */
      public ParsedObject get(int index)
      {
          return (ParsedObject)results.get(index);
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.search.SearchResults#getResults()
       */
      public List getResults()
      {
          return results;
      }
  
      /* (non-Javadoc)
       * @see org.apache.jetspeed.search.SearchResults#getResults(int, int)
       */
      public List getResults(int fromIndex, int toIndex)
      {
          return results.subList(fromIndex, toIndex);
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to