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/test/org/apache/lucene TestSearchBean.java
Date Fri, 23 Jan 2004 16:51:56 GMT
ehatcher    2004/01/23 08:51:56

  Modified:    contributions/searchbean/src/java/org/apache/lucene/beans
                        CompareDocumentsByField.java SearchBean.java
                        SortedField.java
               contributions/searchbean/src/test/org/apache/lucene
                        TestSearchBean.java
  Log:
  code cleanup.  tests pass
  
  Revision  Changes    Path
  1.2       +14 -26    jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/CompareDocumentsByField.java
  
  Index: CompareDocumentsByField.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/CompareDocumentsByField.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CompareDocumentsByField.java	23 May 2002 00:44:53 -0000	1.1
  +++ CompareDocumentsByField.java	23 Jan 2004 16:51:56 -0000	1.2
  @@ -1,32 +1,20 @@
   package org.apache.lucene.beans;
   
  -import org.apache.lucene.document.Document;
  -import org.apache.lucene.document.DateField;
   import org.apache.lucene.beans.IndividualHit;
  -import java.util.Date;
   
  -//import org.apache.log4j.Logger;
   
  -public class CompareDocumentsByField implements java.util.Comparator
  -{
  -       // static private Logger logger = Logger.getLogger(CompareDocumentsByDate.class.getName());
  -	public CompareDocumentsByField()
  -	{
  -	}
  -	
  -	public int compare(Object hit1, Object hit2)
  -	{
  -		String myDate1 = ((IndividualHit)hit1).getField();
  -		String myDate2 = ((IndividualHit)hit2).getField();
  -                if ((myDate1 == null) || (myDate2 == null)){
  -                    //logger.error("A date was null, the score is "+((IndividualHit) hit1).getScore());
  -                    //return -1;
  -                }
  -		return -1*(myDate1.compareTo(myDate2)); 	//sort in descending order
  -	}
  -	
  -	public boolean equals(Object o1)
  -	{
  -		return false;
  -	}
  +public class CompareDocumentsByField implements java.util.Comparator {
  +  public int compare(Object hit1, Object hit2) {
  +    String myDate1 = ((IndividualHit) hit1).getField();
  +    String myDate2 = ((IndividualHit) hit2).getField();
  +    if ((myDate1 == null) || (myDate2 == null)) {
  +//logger.error("A date was null, the score is "+((IndividualHit) hit1).getScore());
  +//return -1;
  +    }
  +    return -1 * (myDate1.compareTo(myDate2)); 	//sort in descending order
  +  }
  +
  +  public boolean equals(Object o1) {
  +    return false;
  +  }
   }
  
  
  
  1.4       +8 -56     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SearchBean.java	12 May 2003 14:32:23 -0000	1.3
  +++ SearchBean.java	23 Jan 2004 16:51:56 -0000	1.4
  @@ -10,16 +10,12 @@
   import org.apache.lucene.search.IndexSearcher;
   import org.apache.lucene.search.Query;
   import org.apache.lucene.search.Hits;
  -import org.apache.lucene.search.HitCollector;
   import org.apache.lucene.store.Directory;
   import org.apache.lucene.analysis.Analyzer;
  -import org.apache.lucene.analysis.StopAnalyzer;
   import org.apache.lucene.analysis.standard.StandardAnalyzer;
   import org.apache.lucene.queryParser.QueryParser;
   import org.apache.lucene.queryParser.ParseException;
   
  -import java.util.Vector;
  -
   import org.apache.lucene.beans.HitsIterator;
   
   import java.io.IOException;
  @@ -45,11 +41,7 @@
       // 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;
  @@ -161,20 +153,16 @@
           return queryString+"|"+queryType+"|"+querySortField;
       }
   
  -    /** setter for queryString
  -     */
  -    public void setQueryString
  -    (String queryString) {
  +    public void setQueryString(String queryString) {
           this.queryString = queryString;
       }
   
  -    /** getter for queryString
  -     */
       public String getQueryString(){
           return queryString;
       }
   
  -    /** getter for Lucene Query
  +    /** Parses the query
  +     * @todo allow for user defined analyzer
        */
       private Query getQuery(String queryString, String searchField) throws ParseException
{
           //String defaultSearchField = "text";
  @@ -184,87 +172,51 @@
           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) {
  +    public void setDefaultSearchField(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() {
  +    public String getQueryType() {
           return queryType;
       }
   
  -    /** Setter for property queryType.
  -     * @param queryType New value of property queryType.
  -     */
  -    public void setQueryType(java.lang.String queryType) {
  +    public void setQueryType(String queryType) {
           this.queryType = queryType;
       }
   
  -    /** Getter for property directory.
  -     * @return Value of property directory.
  -     */
  -    public org.apache.lucene.store.Directory getDirectory() {
  +    public Directory getDirectory() {
           return directory;
       }
   
  -    /** Setter for property directory.
  -     * @param directory New value of property directory.
  -     */
  -    public void setDirectory(org.apache.lucene.store.Directory directory) {
  +    public void setDirectory(Directory directory) {
           this.directory = directory;
       }
   
  
  
  
  1.3       +16 -15    jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/SortedField.java
  
  Index: SortedField.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/SortedField.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SortedField.java	7 Sep 2002 01:00:57 -0000	1.2
  +++ SortedField.java	23 Jan 2004 16:51:56 -0000	1.3
  @@ -20,17 +20,18 @@
    * @author  carlson
    */
   public class SortedField {
  -    
  +
       private String fieldName;
  -    
  +
       private String[] fieldValues;
  -    
  +
       private static Hashtable fieldList = new Hashtable(); //keeps track of all fields
  -    
  +
       /** Creates a new instance of SortedField */
  -    public SortedField() {
  +    private SortedField(String fieldName) {
  +      this.fieldName = fieldName;
       }
  -    
  +
       /** add a field so that is can be used to sort
        * @param fieldName the name of the field to add
        * @param indexPath path to Lucene index directory
  @@ -39,7 +40,7 @@
           IndexReader ir = IndexReader.open(indexPath);
           addField(fieldName, ir);
       }
  -    
  +
       /** add a field so that is can be used to sort
        * @param fieldName the name of the field to add
        * @param indexFile File pointing to Lucene index directory
  @@ -48,8 +49,8 @@
           IndexReader ir = IndexReader.open(indexFile);
           addField(fieldName, ir);
       }
  -    
  -    
  +
  +
       /** add a field so that is can be used to sort
        * @param fieldName the name of the field to add
        * @param directory Lucene Directory
  @@ -58,15 +59,15 @@
           IndexReader ir = IndexReader.open(directory);
           addField(fieldName, ir);
       }
  -    
  +
       private static void addField(String fieldName, IndexReader ir) throws IOException{
  -        SortedField sortedField = new SortedField();
  +        SortedField sortedField = new SortedField(fieldName);
           sortedField.addSortedField(fieldName,ir);
           //long start = System.currentTimeMillis();
           fieldList.put(fieldName, sortedField);
           //logger.info("adding data from field "+fieldName+" took "+(System.currentTimeMillis()-start));
       }
  -    
  +
       /** adds the data from the index into a string array
        */
       private void addSortedField(String fieldName, IndexReader ir) throws IOException{
  @@ -81,7 +82,7 @@
           }
           ir.close();
       }
  -    
  +
       /** returns the value of the field
        * @param globalID Lucene's global document ID
        * @return value of field
  @@ -89,7 +90,7 @@
       public String getFieldValue(int globalID) {
           return fieldValues[globalID];
       }
  -    
  +
       /** provides way to retrieve a SortedField once you add it
        * @param fieldName name of field to lookup
        * @return SortedField field to use when sorting
  @@ -97,7 +98,7 @@
       public static SortedField getSortedField(String fieldName){
           return  (SortedField) fieldList.get(fieldName);
       }
  -    
  +
       /** Getter for property fieldName.
        * @return Value of property fieldName.
        */
  
  
  
  1.3       +13 -26    jakarta-lucene-sandbox/contributions/searchbean/src/test/org/apache/lucene/TestSearchBean.java
  
  Index: TestSearchBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/searchbean/src/test/org/apache/lucene/TestSearchBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestSearchBean.java	7 Sep 2002 01:01:01 -0000	1.2
  +++ TestSearchBean.java	23 Jan 2004 16:51:56 -0000	1.3
  @@ -54,8 +54,6 @@
    * <http://www.apache.org/>.
    */
   
  -import org.apache.lucene.search.IndexSearcher;
  -import org.apache.lucene.index.Term;
   import org.apache.lucene.index.IndexWriter;
   import org.apache.lucene.store.RAMDirectory;
   import org.apache.lucene.store.Directory;
  @@ -64,7 +62,6 @@
   import org.apache.lucene.document.Field;
   import org.apache.lucene.index.IndexReader;
   import org.apache.lucene.queryParser.ParseException;
  -import org.apache.lucene.queryParser.QueryParser;
   
   import org.apache.lucene.beans.SearchBean;
   import org.apache.lucene.beans.HitsIterator;
  @@ -74,53 +71,43 @@
   
   import java.io.IOException;
   
  -/**
  - *
  - *
  - */
   public class TestSearchBean extends TestCase{
  -    public TestSearchBean(String name) {
  -        super(name);
  -    }
  -    
  -    /*
  -     *
  -     */
  +
       public void testSearchBean() throws IOException, ParseException {
           Directory indexStore = createIndex();
           SortedField.addField("text",indexStore);
           //IndexSearcher searcher = new IndexSearcher(indexStore);
  -        
  +
           SearchBean sb = new SearchBean(indexStore);
           HitsIterator hi = sb.search("metal");
  -        
  +
           assertEquals(1, hi.getTotalHits());
  -        
  +
           assertEquals(1, hi.getPageCount());
  -        
  +
           assertEquals("metal",hi.next().get("text"));
       }
  -    
  +
       public void testUnoptimizedSearchBean() throws IOException, ParseException {
           Directory indexStore = createIndex();
           IndexReader reader = IndexReader.open(indexStore);
           reader.delete(0);
           //
           reader.close();
  -        
  +
           SortedField.addField("text",indexStore);
           //IndexSearcher searcher = new IndexSearcher(indexStore);
  -        
  +
           SearchBean sb = new SearchBean(indexStore);
           HitsIterator hi = sb.search("metal");
  -        
  +
           assertEquals(0, hi.getTotalHits());
  -        
  +
           assertEquals(0, hi.getPageCount());
  -        
  +
           //assertEquals("metal",hi.next().get("text"));
       }
  -    
  +
       public Directory createIndex() throws IOException{
           RAMDirectory indexStore = new RAMDirectory();
           IndexWriter writer = new IndexWriter(indexStore, new StandardAnalyzer(), true);
  @@ -132,7 +119,7 @@
           writer.addDocument(doc2);
           writer.optimize();
           writer.close();
  -        return (Directory) indexStore;
  +        return indexStore;
       }
   }
   
  
  
  

---------------------------------------------------------------------
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