lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject cvs commit: jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans HitsIterator.java IteratorAdapter.java SearchBean.java
Date Mon, 12 May 2003 14:32:23 GMT
ehatcher    2003/05/12 07:32:23

  Modified:    contributions/searchbean build.xml
               contributions/searchbean/src/java/org/apache/lucene/beans
                        HitsIterator.java IteratorAdapter.java
                        SearchBean.java
  Log:
  my changes to make it compile, also minor build file cleanup
  
  Revision  Changes    Path
  1.3       +8 -11     jakarta-lucene-sandbox/contributions/searchbean/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/searchbean/build.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- build.xml	11 May 2003 20:55:32 -0000	1.2
  +++ build.xml	12 May 2003 14:32:23 -0000	1.3
  @@ -6,15 +6,14 @@
           (and without typing -D each time it compiles it -->
     <property file="${user.home}/lucene.build.properties" /> 
     <property file="${user.home}/build.properties" />
  -  <property file="${basedir}/build.properties" />
  -  <property file="${basedir}/default.properties" />
  +  <property file="build.properties" />
  +  <property file="default.properties" />
  +  <property name="lib.dir" location="lib"/>
   
     <!-- Build classpath -->
     <path id="classpath">
  -    <pathelement location="${build.classes}"/>
  -    <pathelement location="${build.test.classes}"/>
       <pathelement location="."/>
  -    <fileset dir="lib.dir">
  +    <fileset dir="${lib.dir}">
         <include name="*.jar" />
       </fileset>
     </path>
  @@ -22,9 +21,8 @@
     <path id="junit.classpath">
       <pathelement location="${junit.classes}" />
       <pathelement location="${build.classes}"/>
  -    <fileset dir="lib.dir">
  -      <include name="*.jar" />
  -    </fileset>
  +    <pathelement location="${build.test.classes}"/>
  +    <path refid="classpath"/>
       <pathelement path="${java.class.path}" />
     </path>
   
  @@ -35,7 +33,6 @@
       <mkdir dir="${build.dir}"/>
       <mkdir dir="${build.classes}"/>
       <mkdir dir="${build.src}"/>
  -    <mkdir dir="lib.dir"/>
       
       <available
         property="junit.present"
  @@ -109,7 +106,7 @@
         includes="**/*.java"
         destdir="${build.test.classes}"
         debug="${debug}">
  -      <classpath refid="classpath"/>
  +      <classpath refid="junit.classpath"/>
       </javac>
     </target>
   
  @@ -133,7 +130,7 @@
         includes="**/*.java"
         destdir="${junit.classes}"
         debug="${debug}">
  -      <classpath refid="classpath"/>
  +      <classpath refid="junit.classpath"/>
       </javac>
   
       <junit printsummary="yes" haltonfailure="no" >
  
  
  
  1.3       +43 -43    jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/HitsIterator.java
  
  Index: HitsIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/HitsIterator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HitsIterator.java	7 Sep 2002 01:00:47 -0000	1.2
  +++ HitsIterator.java	12 May 2003 14:32:23 -0000	1.3
  @@ -25,37 +25,37 @@
    * @version 1.0
    */
   public class HitsIterator {
  -    
  +
       //static Logger logger = Logger.getLogger(HitsIterator.class.getName());
  -    
  +
       private int currentPosition = 0;
  -    
  +
       private Hits hitsCollection = null;
       private Object[] arrayOfIndividualHits = null;
  -    
  +
       private int totalHits = 0;
  -    
  +
       private int pageSize = 25; // default page size
  -    
  +
       private int currentPage = 1; // range from 1 to totalHits%pageSize
  -    
  +
       private int totalPages = -1; // set by constructor
  -    
  +
       private int endPagePosition = 0; // position currentPage ends
  -        
  +
       /** Creates new HitsIterator */
       private HitsIterator() {
       }
  -    
  +
       public HitsIterator(Hits hits) throws IOException{
           this(hits,null);
       }
  -    
  +
       public HitsIterator(Hits hits, String sortFlag) throws IOException{
           this.hitsCollection = hits;
           if (sortFlag != null){
  -            if ((sortFlag != "") && (sortFlag.equals(SearchBean.SORT_FIELD_RELEVANCE))){
  -                //logger.debug("Sorting hits by field "+sortFlag);
  +            if (sortFlag != "") {
  +                System.out.println("Sorting hits by field "+sortFlag);
                   sortByField(sortFlag);
                   //logger.debug("Completed sorting by field "+sortFlag);
               }
  @@ -63,7 +63,7 @@
           totalHits = getTotalHits();
           setPageCount();
       }
  -    
  +
       /** sorts hits by the given sort flag
        * fills an interal array
        * @param sortFlag field to sort results on
  @@ -75,12 +75,12 @@
               //logger.error("sort field is null");
               return;
           }
  -        
  +
           SortedField sf = SortedField.getSortedField(fieldName);
           if (sf !=null){
               c = (Comparator) new CompareDocumentsByField();
           } else {
  -            //logger.error("Sort field not found"); 
  +            //logger.error("Sort field not found");
               // use default sort of Lucene -- Relevance
               // Should I throw an exception here?
               arrayOfIndividualHits = null;
  @@ -94,32 +94,32 @@
           }
           long second = System.currentTimeMillis();
           //logger.debug("HitsIterator.sortByField(): filling Obj[] took "+(second-first));
  -        
  +
           Arrays.sort(arrayOfIndividualHits, c);
           //logger.debug("HitsIterator.sortByField(): sort took "+(System.currentTimeMillis()-second));
  -        
  +
       }
  -    
  -    
  +
  +
       private void setPageCount() {
           if (totalHits == 0){
               totalPages = 0;
               setCurrentPage(0);
           } else {
               totalPages = totalHits / pageSize;
  -            
  +
               //account for remainder if not exaxtly divisable
               if (totalHits % pageSize != 0)
               { totalPages++;}
               setCurrentPage(1); // reset currentPage to make sure not over the limit
           }
       }
  -    
  +
       public int getPageCount() {
           return totalPages;
       }
  -    
  -    
  +
  +
       public org.apache.lucene.document.Document setPosition(int position) throws IOException{
           if (position > totalHits) {
               return null;
  @@ -127,34 +127,34 @@
           currentPosition = position;
           return getDoc();
       }
  -    
  +
       public org.apache.lucene.document.Document next() throws IOException{
           currentPosition++;
  -        
  +
           if (currentPosition > totalHits) {
               currentPosition = totalHits;
               return null ;
           }
  -        
  +
           return getDoc();
       }
  -    
  +
       public org.apache.lucene.document.Document previous() throws IOException{
           currentPosition--;
  -        
  +
           if (currentPosition < 0)
           { return null;}
  -        
  +
           return getDoc();
       }
  -    
  +
       public boolean hasNext() {
           if (currentPosition < endPagePosition)
           { return true; }
  -        
  +
           return false;
       }
  -    
  +
       public org.apache.lucene.document.Document getDoc() throws IOException {
           // Determine if using relevnace or sorting by another field
           if (arrayOfIndividualHits == null)
  @@ -164,7 +164,7 @@
               return hitsCollection.doc(i);
           }
       }
  -    
  +
       public int getScore() throws Exception{
           // Determine if using relevnace or sorting by another field
           if (arrayOfIndividualHits == null)
  @@ -172,39 +172,39 @@
           else
               return (int) (((IndividualHit)arrayOfIndividualHits[currentPosition - 1]).getScore()*100.0f);
       }
  -    
  +
       public int getTotalHits() {
           return hitsCollection.length();
       }
  -    
  +
       public int getCurrentPosition() {
           return currentPosition;
       }
  -    
  +
       public int getPageSize() {
           return pageSize;
       }
  -    
  +
       public void setPageSize(int pageSize) {
           this.pageSize = pageSize;
           setPageCount();
       }
  -    
  +
       public void setCurrentPage(int currentPage) throws IndexOutOfBoundsException{
           if (currentPage > totalPages){
               currentPage = totalPages; // don't allow to go over max
               //throw new IndexOutOfBoundsException("currentPage greater than total pages");
           }
  -        
  +
           this.currentPage = currentPage;
           currentPosition = ((currentPage - 1) * pageSize);
           endPagePosition = Math.min( ((currentPage - 1)*pageSize) + pageSize, totalHits);
       }
  -    
  +
       public int getCurrentPage() {
           return currentPage;
       }
  -    
  +
       /**
        * set page number to next page, unless last page, then
        * always return last page number
  @@ -214,7 +214,7 @@
           setCurrentPage(currentPage++);
           return getCurrentPage();
       }
  -    
  +
       /**
        * set page number to previous page, unless first page,
        * then always return first page number
  
  
  
  1.2       +9 -2      jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/IteratorAdapter.java
  
  Index: IteratorAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/IteratorAdapter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IteratorAdapter.java	31 Aug 2002 01:19:42 -0000	1.1
  +++ IteratorAdapter.java	12 May 2003 14:32:23 -0000	1.2
  @@ -1,6 +1,7 @@
   package org.apache.lucene.beans;
   
   import java.util.Iterator;
  +import java.io.IOException;
   
   /**
    * Acts as an adapter for HitsIterator to comply with the Collections
  @@ -25,7 +26,13 @@
   
       public Object next()
       {
  -        return hitsIterator.next();
  +        Object obj = null;
  +        try {
  +            obj = hitsIterator.next();
  +        } catch (IOException e) {
  +            // ignore for now, returning null might be good enough?
  +        }
  +        return obj;
       }
   
       public void remove()
  
  
  
  1.3       +36 -35    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SearchBean.java	7 Sep 2002 01:00:52 -0000	1.2
  +++ SearchBean.java	12 May 2003 14:32:23 -0000	1.3
  @@ -32,7 +32,7 @@
    * @version 1.0
    */
   public class SearchBean extends Object {
  -    
  +
       static final String SORT_FIELD_RELEVANCE = "relevance";
       private String queryString = "";
       private String querySortField = SORT_FIELD_RELEVANCE; // default
  @@ -44,17 +44,17 @@
       private Searcher searcher = null;
       // static Logger logger = Logger.getLogger(SearchBean.class.getName());
       // static Logger searchLogger = Logger.getLogger("searchLog");
  -    
  +
       private SearchBean(){
       }
  -    
  +
       /** Creates new SearchBean
        * @param path to index
        */
       public SearchBean(Directory directory) {
           this.directory = directory;
       }
  -    
  +
       /** Creates new SearchBean
        * @param directory index
        * @param queryString string to search with
  @@ -63,7 +63,7 @@
           this(directory);
           setQueryString(queryString);
       }
  -    
  +
       /** Creates new SearchBean
        * @param directory index
        * @param queryString string to search with
  @@ -74,7 +74,7 @@
           setQueryString(queryString);
           setQuerySortField(querySortField);
       }
  -    
  +
       /** Creates new SearchBean
        * @param directory index
        * @param queryString string to search with
  @@ -87,20 +87,20 @@
           setQuerySortField(querySortField);
           setQueryType(queryType);
       }
  -    
  +
       /** main search method
        */
       public HitsIterator search() throws IOException, ParseException{
           return search(queryString,querySortField);
       }
  -    
  +
       /** main search method
        * @param queryString string to search with
        */
       public HitsIterator search(String queryString) throws IOException, ParseException{
           return search(queryString,queryString);
       }
  -    
  +
       /** main search method
        * @param queryString string to search with
        * @param querySortField field to sort on
  @@ -108,7 +108,7 @@
       public HitsIterator search(String queryString, String querySortField) throws IOException,
ParseException{
           return search(queryString, querySortField, queryType);
       }
  -    
  +
       /** main search method
        * @param queryString string to search with
        * @param querySortField field to sort on
  @@ -117,10 +117,10 @@
       public HitsIterator search(String queryString, String querySortField, String queryType)
   throws IOException, ParseException {
           long startTime = System.currentTimeMillis();
           Hits hits = searchHits(queryString, queryType);
  -        
  +
           //if (hits == null) {return null;}
           //if (hits.length() == 0) {return null;}
  -        
  +
           HitsIterator hi = new HitsIterator(hits, querySortField);
           long endTime = System.currentTimeMillis();
           setSearchTime(endTime - startTime);
  @@ -128,51 +128,52 @@
           //searchLogger.info("queryString = "+queryString + "sort field = "+ querySortField
+" #results = "+hits.length());
           return hi;
       }
  -    
  +
       /** does the actual searching
        */
       private Hits searchHits(String queryString, String queryType) throws IOException, ParseException{
  +        System.out.println("queryString = " + queryString);
           if (queryString == "") {
               return null;
           }
  -        
  +
           // Provide for multiple indices in the future
  -        
  +
           searcher = new IndexSearcher(directory);
           Query query = getQuery(queryString, defaultSearchField);
  -        //System.out.println("###querystring= "+query.toString(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>
        */
       public String toString(){
           return queryString+"|"+queryType+"|"+querySortField;
       }
  -    
  +
       /** setter for queryString
        */
       public void setQueryString
       (String queryString) {
           this.queryString = queryString;
       }
  -    
  +
       /** getter for queryString
        */
       public String getQueryString(){
           return queryString;
       }
  -    
  +
       /** getter for Lucene Query
        */
       private Query getQuery(String queryString, String searchField) throws ParseException
{
  @@ -182,89 +183,89 @@
           //System.out.println(query.toString());
           return query;
       }
  -    
  +
       /** Getter for property defaulSearchField.
        * @return Value of property defaulSearchField.
        */
       public String getDefaultSearchField() {
           return defaultSearchField;
       }
  -    
  +
       /** Setter for property defaulSearchField.
        * @param defaulSearchField New value of property defaulSearchField.
        */
       public void setDefaultSearchField(java.lang.String defaultSearchField) {
           this.defaultSearchField = defaultSearchField;
       }
  -    
  +
       /** Getter for property searchTime.
        * @return Value of property searchTime.
        */
       public long getSearchTime() {
           return searchTime;
       }
  -    
  +
       /** Setter for property searchTime.
        * @param searchTime New value of property searchTime.
        */
       public void setSearchTime(long searchTime) {
           this.searchTime = searchTime;
       }
  -    
  +
       /** Getter for property querySortField.
        * @return Value of property querySortField.
        */
       public java.lang.String getQuerySortField() {
           return querySortField;
       }
  -    
  +
       /** Setter for property querySortField.
        * @param querySortField New value of property querySortField.
        */
       public void setQuerySortField(String querySortField) {
           this.querySortField = querySortField;
       }
  -    
  +
       /** Getter for property hitsIterator.
        * @return Value of property hitsIterator.
        */
       public HitsIterator getHitsIterator() {
           return hitsIterator;
       }
  -    
  +
       /** Setter for property hitsIterator.
        * @param hitsIterator New value of property hitsIterator.
        */
       public void setHitsIterator(HitsIterator hitsIterator) {
           this.hitsIterator = hitsIterator;
       }
  -    
  +
       /** Getter for property queryType.
        * @return Value of property queryType.
        */
       public java.lang.String getQueryType() {
           return queryType;
       }
  -    
  +
       /** Setter for property queryType.
        * @param queryType New value of property queryType.
        */
       public void setQueryType(java.lang.String queryType) {
           this.queryType = queryType;
       }
  -    
  +
       /** Getter for property directory.
        * @return Value of property directory.
        */
       public org.apache.lucene.store.Directory getDirectory() {
           return directory;
  -    }    
  -    
  +    }
  +
       /** Setter for property directory.
        * @param directory New value of property directory.
        */
       public void setDirectory(org.apache.lucene.store.Directory directory) {
           this.directory = directory;
       }
  -    
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message