Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: joist/java/org/joist/search Query.java SearchInterface.java SearchResult.java SearchResultItem.java SearchServlet.java SearchSwishe.java

Project highlights: Architectural Overview

joist
Discussion topic

Back to topic list

CVS update: joist/java/org/joist/search Query.java SearchInterface.java SearchResult.java SearchResultItem.java SearchServlet.java SearchSwishe.java

Author stack
Full name Michael Stack
Date 2000-10-25 13:31:17 PDT
Message User: stack
  Date: 00/10/25 13:31:17

  Modified: java/org/joist/search Query.java SearchInterface.java
                        SearchResult.java SearchResultItem.java
                        SearchServlet.java SearchSwishe.java
  Log:
  Tried to make my code look like everyone else's (Failed). Changed data members from protected to private.
  
  Revision Changes Path
  1.3 +41 -36 joist/java/org/joist​/search/Query.java
  
  Index: Query.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/search/Query.j​ava,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Query.java 2000/10/24 18:32:03 1.2
  +++ Query.java 2000/10/25 20:31:17 1.3
  @@ -43,16 +43,16 @@
    * This software consists of voluntary contributions made by many
    * individuals on behalf of Collab.Net.
    */
  - package org.joist.search;
  +package org.joist.search;
    
    
   /** Class to pass query and query arguments to Search.
   * <p>
   * &laquo;Immutable -- Read-Only.&raquo;
   * <p>
  -* Queries go against one index only. To run a search against
  -* multiple indexes, run the query multiple times specifying
  -* a different index each time.
  +* Queries objects of this class go against one index only. To
  +* run a search against multiple indexes, run the query multiple
  +* times specifying a different index each time.
   * <p>
   * Different search engines may have more facility to pass
   * in a query -- just subclass or add to this class when
  @@ -60,31 +60,33 @@
   * paging through returned results.
   *
   * @author <a href="mailto:stack@c​ollab.net">St.Ack​</a>
  -* @version $Id: Query.java,v 1.2 2000/10/24 18:32:03 stack Exp $
  +* @version $Id: Query.java,v 1.3 2000/10/25 20:31:17 stack Exp $
   */
   public class Query
   {
       /** Class version string
       */
       public static final String versionID
  - = "$Id: Query.java,v 1.2 2000/10/24 18:32:03 stack Exp $";
  + = "$Id: Query.java,v 1.3 2000/10/25 20:31:17 stack Exp $";
       
       
       /** Number of search result items to return per query.
       */
  - protected int resultsPerQuery = -1;
  + private int resultsPerQuery = -1;
       
       
       /** Query string to pass search.
       */
  - protected String query = null;
  + private String queryString = null;
       
       
       /** Index we're to use.
       * This is full-path or a index 'name'.
  - * Depends on the search-engine being called
  + * For swishe, its full-path. May be
  + * just a unique name when we use other
  + * indexes.
       */
  - protected String searchIndex = null;
  + private String searchIndex = null;
       
       
       /** Upper limit on how many queries results we'll return.
  @@ -97,16 +99,18 @@
       
       
       /** Constructor
  - * @param inQuery Query to run
  - * @param inResultsPerQuery How many results to return. Usually
  - * forms part of query. Can be zero. Then we return the
  - * default setting for results per page. Cannot be negative.
  - * @param inSearchIndex Name of search index that this query is
  - * to go against. Can be name or full-path to index. Depends
  - * on the search-engine.
       *
  - * @exception NullPointerException If passed in params are null
  - * or empty.
  + * @param inQuery Query object to run
  + * @param inResultsPerQuery How many results to return.
  + * Usually forms part of query. Can be zero. Then we
  + * return the default setting for results per page.
  + * Cannot be negative.
  + * @param inSearchIndex Name of search index that this
  + * query is to go against. Can be name or full-path to
  + * index. Depends on the search-engine.
  + *
  + * @exception NullPointerException If passed in params
  + * are null or empty.
       * @exception IndexOutOfBoundsException If passed in
       * inResultsPerQuery is less than 0 or greater than
       * QUERY_RESULTS_UPPER_LIMIT, our arbitrary upper-bound.
  @@ -120,28 +124,30 @@
                   IndexOutOfBoundsException,
                   java.io.FileNotFoundException
       {
  - if( inQuery == null || inQuery.length( ) <= 0 )
  - throw new NullPointerException( "inQuery is null or empty" );
  - query = inQuery;
  + if( ( inQuery == null ) || ( inQuery.length( ) <= 0 ) )
  + throw new NullPointerException("inQuery is null or empty");
  + queryString = inQuery;
                
  -
           // Test for non-null index and that it exists
           //
  - if( inSearchIndex == null
  - || inSearchIndex.length( ) <= 0 )
  + if( ( inSearchIndex == null )
  + || ( inSearchIndex.length( ) <= 0 ) )
               throw new NullPointerException( "inSearchIndex is null or empty" );
           java.io.File fileIndex = new java.io.File( inSearchIndex );
           if( !fileIndex.exists( ) )
  - throw new java.io.FileNotFoundException( "inSearchIndex swish-e at location <"
  + throw new java.io.FileNotFoundException( "inSearchIndex at location <"
                   + inSearchIndex
                   + "> does not exist" );
           searchIndex = inSearchIndex;
           
  - if( inResultsPerQuery < 0 || inResultsPerQuery > QUERY_RESULTS_UPPER_LIMIT )
  + // Test inResultsPerQuery is w/i bounds
  + //
  + if( ( inResultsPerQuery < 0 )
  + || ( inResultsPerQuery > QUERY_RESULTS_UPPER_LIMIT ) )
               throw new IndexOutOfBoundsException( "inResultsPerQuery <"
  - + Integer.toString( inResultsPerQuery )
  - + "> is negative or greater than our upper-bound limit, "
  - + Integer.toString( QUERY_RESULTS_UPPER_LIMIT ) );
  + + Integer.toString( inResultsPerQuery )
  + + "> is negative or greater than our upper-bound limit, "
  + + Integer.toString( QUERY_RESULTS_UPPER_LIMIT ) );
           resultsPerQuery = inResultsPerQuery;
       }
       
  @@ -149,6 +155,7 @@
       /** Constructor override.
       * Doesn't supply the inResultsPerQuery. Rely on search-engine
       * using its default for results per query.
  + *
       * @param inQuery Query to run
       * @param inSearchIndex Name of search index that this query is
       * to go against. Can be name or full-path to index. Depends
  @@ -163,23 +170,21 @@
       * index does not exist.
       */
       public Query( String inQuery,
  - String inSearchIndex )
  + String inSearchIndex )
           throws NullPointerException,
                   IndexOutOfBoundsException,
                   java.io.FileNotFoundException
       {
           this( inQuery, inSearchIndex, 0 );
       }
  -
  -
  -
       
  +
       /** Accessor for query String
       * @result Returns query string.
       */
  - public String getQuery( )
  + public String getQueryString( )
       {
  - return query;
  + return queryString;
       }
       
       
  
  
  
  1.3 +9 -5 joist/java/org/joist​/search/SearchInterf​ace.java
  
  Index: SearchInterface.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/search/SearchI​nterface.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SearchInterface.java 2000/10/24 18:32:19 1.2
  +++ SearchInterface.java 2000/10/25 20:31:17 1.3
  @@ -43,16 +43,17 @@
    * This software consists of voluntary contributions made by many
    * individuals on behalf of Collab.Net.
    */
  - package org.joist.search;
  +package org.joist.search;
    
    
   /** Search interface.
   * Implementations of this interface will differ
   * across search engines. Try to insulate against
  -* the differences by defining this interface.
  +* the differences having all search engine
  +* interfaces implement this interface.
   *
   * @author <a href="mailto:stack@c​ollab.net">St.Ack​</a>
  -* @version $Id: SearchInterface.java,v 1.2 2000/10/24 18:32:19 stack Exp $
  +* @version $Id: SearchInterface.java,v 1.3 2000/10/25 20:31:17 stack Exp $
   * @see <a href="http://projects.coll​ab.net/project/eng/s​tack/projects/search​/search.html">Search Interface Survey and Design</a>
   */
   public interface SearchInterface
  @@ -60,12 +61,15 @@
       /** Class version string
       */
       public static final String versionID
  - = "$Id: SearchInterface.java,v 1.2 2000/10/24 18:32:19 stack Exp $";
  + = "$Id: SearchInterface.java,v 1.3 2000/10/25 20:31:17 stack Exp $";
           
       
       /** Run a search w/ passed in Query.
  + *
       * @param inQuery Query object to run search with.
  + *
       * @return A search result object.
  + *
       * @exception SearchResultException If query causes
       * the search-engine to return an error -- 'Could
       * not open the index', or 'Please enter at least
  @@ -75,7 +79,7 @@
       * a Runtime.exec( ) or we're having troubles reading from
       * the network.
       */
  - public SearchResult query( Query inQuery )
  + public SearchResult search( Query inQuery )
           throws SearchResultException,
                   java.io.IOException;
   }
  
  
  
  1.3 +17 -17 joist/java/org/joist​/search/SearchResult​.java
  
  Index: SearchResult.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/search/SearchR​esult.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SearchResult.java 2000/10/24 18:33:16 1.2
  +++ SearchResult.java 2000/10/25 20:31:17 1.3
  @@ -43,7 +43,7 @@
    * This software consists of voluntary contributions made by many
    * individuals on behalf of Collab.Net.
    */
  - package org.joist.search;
  +package org.joist.search;
    
    
   /** Class to hold search results.
  @@ -56,30 +56,30 @@
   * etc., as well as a SearchResultItem per result returned.
   *
   * @author <a href="mailto:stack@c​ollab.net">St.Ack​</a>
  -* @version $Id: SearchResult.java,v 1.2 2000/10/24 18:33:16 stack Exp $
  +* @version $Id: SearchResult.java,v 1.3 2000/10/25 20:31:17 stack Exp $
   */
   public class SearchResult
   {
       /** Class version string
       */
       public static final String versionID
  - = "$Id: SearchResult.java,v 1.2 2000/10/24 18:33:16 stack Exp $";
  + = "$Id: SearchResult.java,v 1.3 2000/10/25 20:31:17 stack Exp $";
       
       
       /** Array of search results.
       * Keep the order returned by the search-engine.
       * Item 0 should be highest ranked. Later we can
  - * come along and do sorts on other than on ranking.
  + * come along and do sorts on other than ranking.
       * Maybe this should be a set. Then we're guaranteed
       * uniqueness. Or SortedSet might help when it comes
       * to sorting time.
       */
  - protected com.sun.java.util.co​llections.List resultItems = null;
  + private com.sun.java.util.co​llections.List resultItems = null;
       
       
       /** Name of index results came from.
       */
  - protected String indexName = null;
  + private String indexName = null;
       
       
       /** Number of hits.
  @@ -88,25 +88,25 @@
       * help the user when there are more results than
       * results-per-page will allow them see.
       */
  - protected int numberOfHits = 0;
  + private int numberOfHits = 0;
       
       
       /** The Query object that was responsible for these results.
       */
  - protected Query query = null;
  + private Query query = null;
       
       
       /** When index was last updated.
       * A date as a string (conversion to Date ain't worth the bother).
       */
  - protected String indexModDate = null;
  + private String indexModDate = null;
       
       
       /** Search result index statistics.
       * Some stats returned by the search-engine describing the index..
       * For example, a Swish-e string would be '19 words, 2 files'.
       */
  - protected String indexStats = null;
  + private String indexStats = null;
       
       
       /** Search words.
  @@ -114,18 +114,18 @@
       * reports it searched on. Often different from
       * what is in the Query object.
       */
  - protected String searchengineSearchWords = null;
  + private String searchengineSearchWords = null;
       
       
       /** Pointer to the index used.
       * This is path or url to index. May be null.
       */
  - protected String indexPointer = null;
  + private String indexPointer = null;
       
       
       /** Index description. May be null
       */
  - protected String description = null;
  + private String description = null;
       
       
       /** Constructor
  @@ -168,8 +168,8 @@
            
           if( inNumberOfHits < 0 )
               throw new IndexOutOfBoundsException( "inNumberOfHits <"
  - + Integer.toString( inNumberOfHits )
  - + "> negative or not equal to size of resultItems" );
  + + Integer.toString( inNumberOfHits )
  + + "> negative or not equal to size of resultItems" );
           numberOfHits = inNumberOfHits;
           
           indexName = inIndexName;
  @@ -282,7 +282,7 @@
                               : "null" );
           strBuffer.append( ", numberOfHits " );
           strBuffer.append( Integer.toString( getNumberOfHits( ) ) );
  - strBuffer.append( ", indexModDate " );
  + strBuffer.append(", indexModDate ");
           strBuffer.append( ( getIndexModDate( ) != null )
                               ? getIndexModDate( )
                               : "null" );
  @@ -316,7 +316,7 @@
                   strBuffer.append( Integer.toString( i ) );
                   strBuffer.append( ": ranking " );
                   strBuffer.append( Integer.toString( item.getRanking( ) ) );
  - strBuffer.append( ", size " );
  + strBuffer.append(", size ");
                   strBuffer.append( Integer.toString( item.getSize( ) ) );
                   strBuffer.append( ", url " );
                   strBuffer.append( item.getUrl( ).toString( ) );
  
  
  
  1.3 +7 -7 joist/java/org/joist​/search/SearchResult​Item.java
  
  Index: SearchResultItem.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/search/SearchR​esultItem.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SearchResultItem.java 2000/10/24 18:34:35 1.2
  +++ SearchResultItem.java 2000/10/25 20:31:17 1.3
  @@ -51,34 +51,34 @@
   * &laquo;Immutable -- Read-Only.&raquo;
   *
   * @author <a href="mailto:stack@c​ollab.net">St.Ack​</a>
  -* @version $Id: SearchResultItem.java,v 1.2 2000/10/24 18:34:35 stack Exp $
  +* @version $Id: SearchResultItem.java,v 1.3 2000/10/25 20:31:17 stack Exp $
   */
   public class SearchResultItem
   {
       /** Class version string
       */
       public static final String versionID
  - = "$Id: SearchResultItem.java,v 1.2 2000/10/24 18:34:35 stack Exp $";
  + = "$Id: SearchResultItem.java,v 1.3 2000/10/25 20:31:17 stack Exp $";
       
       
       /** Search engine ranking.
       */
  - protected int ranking = -1;
  + private int ranking = -1;
       
       
       /** File size
       */
  - protected int size = -1;
  + private int size = -1;
       
       
       /** File or URL pointing to file found.
       */
  - protected java.net.URL url = null;
  + private java.net.URL url = null;
       
       
       /** File title -- usually the HTML TITLE
       */
  - protected String title = null;
  + private String title = null;
       
       
       /** Constructor
  @@ -102,7 +102,7 @@
           if( inURL == null )
               throw new NullPointerException( "inURL is null" );
           url = inURL;
  -
  +
           ranking = inRanking;
           size = inSize;
           title = inTitle;
  
  
  
  1.3 +33 -18 joist/java/org/joist​/search/SearchServle​t.java
  
  Index: SearchServlet.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/search/SearchS​ervlet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SearchServlet.java 2000/10/24 18:34:01 1.2
  +++ SearchServlet.java 2000/10/25 20:31:17 1.3
  @@ -97,7 +97,7 @@
   * </ol>
   *
   * @author <a href="mailto:stack@c​ollab.net">St.Ack​</a>
  -* @version $Id: SearchServlet.java,v 1.2 2000/10/24 18:34:01 stack Exp $
  +* @version $Id: SearchServlet.java,v 1.3 2000/10/25 20:31:17 stack Exp $
   */
   public class SearchServlet
       extends org.joist.security.U​nsecureServlet
  @@ -105,58 +105,72 @@
       /** Class version string
       */
       public static final String versionID
  - = "$Id: SearchServlet.java,v 1.2 2000/10/24 18:34:01 stack Exp $";
  + = "$Id: SearchServlet.java,v 1.3 2000/10/25 20:31:17 stack Exp $";
       
       
       /** Logging object.
       */
  - static protected Log log
  + private Log log
           = new Log( "search", "Simple Search" );
           
           
       /** Are we in debug state?
       */
  - protected static final boolean DEBUG
  + private static final boolean DEBUG
           = true;
       
       
       /** Property in zone.properties file w/ path to index.
  + * Leave it protected rather than private since it's
  + * read-only anyways.
       */
       protected static final String INDEX_PATH
           = "SWISH_E_INDEX";
       
       
       /** Property in servlet property file w/ path to swishe binary.
  + * Leave it protected rather than private since it's
  + * read-only anyways.
       */
       protected static final String BINARY_PATH
           = "swisheBinary";
       
       
       /** Key to pull 'action' from context w/ getForm( )
  + * Leave it protected rather than private since it's
  + * read-only anyways.
       */
       protected static final String ACTION_KEY
           = "action";
       
       
       /** Key to pull the resultsPerPage from context w/ getForm( )
  + * Leave it protected rather than private since it's
  + * read-only anyways.
       */
       protected static final String RESULTS_PER_PAGE_KEY
           = "resultsPerPage";
       
       
       /** Key to pull the query from context w/ getForm( )
  + * Leave it protected rather than private since it's
  + * read-only anyways.
       */
       protected static final String QUERY_KEY
           = "query";
       
       
       /** The Search action -- the value under our search input button.
  + * Leave it protected rather than private since it's
  + * read-only anyways.
       */
       protected static final String SEARCH_ACTION
           = "Search";
       
       
       /** Key to put searchresult into context with.
  + * Leave it protected rather than private since it's
  + * read-only anyways.
       */
       protected static final String SEARCH_RESULT_KEY
           = "searchresult";
  @@ -184,26 +198,26 @@
           {
               String query
                   = processField( context,
  - QUERY_KEY,
  - "",
  - "Query",
  - missingFields );
  + QUERY_KEY,
  + "",
  + "Query",
  + missingFields );
                                   
               String resultsPerPage
                   = processField( context,
  - RESULTS_PER_PAGE_KEY,
  - "",
  - "Results per Page (Hidden Field)",
  - missingFields );
  + RESULTS_PER_PAGE_KEY,
  + "",
  + "Results per Page (Hidden Field)",
  + missingFields );
           
               String action
                   = ( String )context.get( ACTION_KEY );
               
  - if( DEBUG )
  + if( DEBUG )
                   log.debug( "Action: " + action );
               
               
  - label_action_test: if( action != null
  + label_action_test: if( ( action != null )
                                       && action.equals( SEARCH_ACTION ) )
               {
                   if( !isValidUserInput( missingFields ) )
  @@ -216,18 +230,19 @@
                   else
                   {
                       String index = myProperties.getProperty( INDEX_PATH );
  - if( DEBUG )
  + if(DEBUG)
                           log.debug( index );
                           
                       Query objQuery
                           = new Query( query,
  - index,
  - Integer.parseInt( resultsPerPage ) );
  + index,
  + Integer.parseInt( resultsPerPage ) );
                   
                       SearchSwishe swishe
                           = new SearchSwishe( myProperties.getProperty( BINARY_PATH ) );
                           
  - SearchResult searchresult = swishe.query( objQuery );
  + SearchResult searchresult
  + = swishe.search( objQuery );
                                       
                        if( DEBUG )
                           log.debug( "Number Of Hits: "
  
  
  
  1.3 +81 -87 joist/java/org/joist​/search/SearchSwishe​.java
  
  Index: SearchSwishe.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/search/SearchS​wishe.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SearchSwishe.java 2000/10/24 18:31:28 1.2
  +++ SearchSwishe.java 2000/10/25 20:31:17 1.3
  @@ -59,7 +59,7 @@
   * in a title or header tag (if it's an HTML file), etc.
   * </p>
   * @author <a href="mailto:stack@c​ollab.net">St.Ack​</a>
  -* @version $Id: SearchSwishe.java,v 1.2 2000/10/24 18:31:28 stack Exp $
  +* @version $Id: SearchSwishe.java,v 1.3 2000/10/25 20:31:17 stack Exp $
   * @see <a href="http://sunsite.berke​ley.edu/SWISH-E/Manu​al">Swish-e Documentation</a>
   */
   public class SearchSwishe
  @@ -67,31 +67,37 @@
   {
       /** Class version string
       */
  - public static final String versionID
  - = "$Id: SearchSwishe.java,v 1.2 2000/10/24 18:31:28 stack Exp $";
  + private static final String versionID
  + = "$Id: SearchSwishe.java,v 1.3 2000/10/25 20:31:17 stack Exp $";
   
   
       /** Define key for pulling system property DEBUG.
       */
  - public static final String DEBUG_KEY
  + private static final String DEBUG_KEY
           = "DEBUG";
       
   
       /** True if we're in debugging mode
  + * Leave it protected rather than private since it's
  + * read-only anyways.
       */
  - public boolean DEBUG
  + protected boolean DEBUG
           = ( new Boolean( System.getProperty( DEBUG_KEY ) ) ).booleanValue( );
       
       
       /** Use this key to pull query from system properties.
  + * Leave it protected rather than private since it's
  + * read-only anyways.
       */
  - public static final String QUERY_PARAM_KEY
  + protected static final String QUERY_PARAM_KEY
           = "query";
       
       
       /** Search result format version string.
       * This class will only work against search results
  - * that match this regular expression
  + * that match this regular expression.
  + * Leave it protected rather than private since it's
  + * read-only anyways.
       */
       protected static final String FORMAT_VERSION_RE
           = "# SWISH format 1.3";
  @@ -99,7 +105,7 @@
       
       /** The swish-e binary.
       */
  - protected java.io.File swisheBinary
  + private java.io.File swisheBinary
           = null;
       
   
  @@ -107,7 +113,7 @@
       * Written as a regular expression in case we do more than
       * one explicit version. Search across multilines.
       */
  - protected gnu.regexp.RE reFormatVersion
  + private gnu.regexp.RE reFormatVersion
           = null;
               
       
  @@ -116,19 +122,19 @@
       * across multi-lines so we jump over preamble
       * to get to first header line.
       */
  - protected gnu.regexp.RE reHeaderKeyValues
  + private gnu.regexp.RE reHeaderKeyValues
           = null;
           
   
       /** Search result error line Regular Expression.
       */
  - protected gnu.regexp.RE reErrorLine
  + private gnu.regexp.RE reErrorLine
           = null;
       
           
       /** The 'No Results' regular expression.
       */
  - protected gnu.regexp.RE reNoResults
  + private gnu.regexp.RE reNoResults
           = null;
           
        
  @@ -144,54 +150,55 @@
       * to see how swish-e returned it. Swish-e strips all
       * '"' characters from the title
       */
  - protected gnu.regexp.RE reSearchResultLine
  + private gnu.regexp.RE reSearchResultLine
           = null;
   
       
       /** Search result header key for index name
       */
  - protected final static String INDEX_NAME
  + private final static String INDEX_NAME
           = "Name";
       
       
       /** Search result header key for index date
       */
  - protected final static String INDEX_MOD_DATE
  + private final static String INDEX_MOD_DATE
           = "Indexed on";
       
   
       /** Search result header key for index stats
       */
  - protected final static String INDEX_STATS
  + private final static String INDEX_STATS
           = "Counts";
       
       
       /** Search result header key for number of hits
       */
  - protected final static String NUMBER_OF_HITS
  + private final static String NUMBER_OF_HITS
           = "Number of hits";
       
       
       /** Search result header key for index path.
       * May be an url or full path.
       */
  - protected final static String INDEX_PATH
  + private final static String INDEX_PATH
           = "Pointer";
       
    
       /** Search result header key for description.
       */
  - protected final static String INDEX_DESCRIPTION
  + private final static String INDEX_DESCRIPTION
           = "Description";
       
       
       /** Search result header key for search engine search words.
       */
  - protected final static String SEARCH_WORDS
  + private final static String SEARCH_WORDS
           = "Search words";
       
           
       /** Constructor.
  + *
       * @param inBinary Path to the swish-e binary
       * @exception NullPointerException If passed in params
       * are null or empty.
  @@ -219,7 +226,8 @@
               = new gnu.regexp.RE( FORMAT_VERSION_RE, gnu.regexp.RE.REG_MULTILINE );
               
           reHeaderKeyValues
  - = new gnu.regexp.RE( "# ([^:\n\r]*): (.*)", gnu.regexp.RE.REG_MULTILINE );
  + = new gnu.regexp.RE( "# ([^:\n\r]*): (.*)",
  + gnu.regexp.RE.REG_MULTILINE );
   
           reErrorLine
               = new gnu.regexp.RE( "err: (.*)" ); // Error line. Won't work if i put a '^' at start, even w/ REG_ANCHORINDEX
  @@ -249,7 +257,7 @@
       * @see #parseSearchResult( Query, String ) Conditions that
       * will throw a SearchResultException
       */
  - public SearchResult query( Query inQuery )
  + public SearchResult search( Query inQuery )
           throws SearchResultException,
                   java.io.IOException
       {
  @@ -261,36 +269,27 @@
                   = runSwishe( inQuery );
               searchresult
                   = parseSearchResult( inQuery,
  - swisheSearchResultStr );
  + swisheSearchResultStr );
           }
           
  + // Exceptions caught and converted to generic
  + // SearchResultException. Do this because
  + // exceptions below are particular to swishe
  + // search implementation.
  + //
           catch( InterruptedException interruptedException )
           {
  - // This exception is specific to Runtime.exec( )
  - // Let's recast it as a SearchResultException
  - // -- make it more generic, and rethrow it.
  - //
               throw new SearchResultException( interruptedException.toString( ) );
           }
           
           
           catch( NumberFormatException numberformatexception )
           {
  - // Should never get this exception. If we do
  - // something wrong w/ results returned. Specific
  - // to how we're doing Swish-e so convert to
  - // the generic error.
  - //
               throw new SearchResultException( numberformatexception.toString( ) );
           }
           
           catch( java.net.MalformedURLException malformedURLexception )
           {
  - // Should never get this exception. If we do
  - // something wrong w/ results returned. Specific
  - // to how we're doing Swish-e so convert to
  - // the generic error.
  - //
               throw new SearchResultException( malformedURLexception.toString( ) );
           }
           
  @@ -361,6 +360,25 @@
       * Throw a SearchResultException
       * </pre>
       * </p>
  + * <p>Implemenation tactic:
  + * <pre>
  + * Tactic is to first find our search results format version
  + * string. If no match, throw an exception.
  + *
  + * Next look for headers. Put all i find into a header hash.
  + *
  + * Then there is the search result body. Switch off what's on
  + * the first line. If it begins w/ 'err:', then its an error of
  + * some kind. Go into error processing either throwing an
  + * exception or just reporting the 'No Results' that Swish-e
  + * reports as an 'Error'. If no error, make a ResultSetItem
  + * per line found and keep a running list in searchResultItems.
  + *
  + * Keep an index. Use this to walk through the passed in
  + * string of search results.
  + * </pre>
  + * </p>
  + *
       * @param inSearchResults String of swish-e search results.
       * @param inQuery The query object that generated the search results.
       *
  @@ -380,37 +398,18 @@
           com.sun.java.util.co​llections.List searchResultItems = null;
           java.util.Hashtable hashOfHeaders = new java.util.Hashtable( );
           gnu.regexp.REMatch match = null; // General match pointer. Reused.
  - String strPtr = null; // General string pointer. Reused.
  + String strPtr = null; // General string pointer. Reused.
           int index = 0; // Index to walk through inSearchResults with
  -
  -
  - // Tactic is to first find our search results format version
  - // string. If no match, throw an exception.
  - //
  - // Next look for headers. Put all i find into a header hash.
  - //
  - // Then there is the search result body. Switch off what's on
  - // the first line. If it begins w/ 'err:', then its an error of
  - // some kind. Go into error processing either throwing an
  - // exception or just reporting the 'No Results' that Swish-e
  - // reports as an 'Error'. If no error, make a ResultSetItem
  - // per line found and keep a running list in searchResultItems.
  - //
  - // Keep an index. Use this to walk through the passed in
  - // string of search results.
  - //
  -
  -
  +
           // Look for the Search Result Format String. Search if no match.
           //
           match = reFormatVersion.getMatch( inSearchResults );
           if( match == null )
               throw new SearchResultException( "Search Result Format "
  - + "not found: "
  - + FORMAT_VERSION_RE );
  + + "not found: "
  + + FORMAT_VERSION_RE );
           index = match.getEndIndex( ); // Move on our index
           
  -
           // Run through the search result headers.
           //
           while( ( match = reHeaderKeyValues.getMatch( inSearchResults, index ) )
  @@ -421,9 +420,9 @@
               index = match.getEndIndex( ); // Move on our index.
               hashOfHeaders.put(
                   inSearchResults.substring( match.getSubStartIndex( 1 ),
  - match.getSubEndIndex( 1 ) ),
  + match.getSubEndIndex( 1 ) ),
                   inSearchResults.substring( match.getSubStartIndex( 2 ),
  - match.getSubEndIndex( 2 ) ) );
  + match.getSubEndIndex( 2 ) ) );
           }
           
           if( DEBUG )
  @@ -431,7 +430,10 @@
           
           
           // Is the first line of the search result body an error
  - // or a set or result items?
  + // or a set or result items? If error is other than the
  + // 'No match' error, throw exception. If 'No match',
  + // fall out bottom returning empty SearchResult. If
  + // set of results, make up a SearchItemResult.
           //
           label_results: if( ( match = reErrorLine.getMatch( inSearchResults, index ) )
                           != null )
  @@ -450,37 +452,32 @@
               searchResultItems
                   = new com.sun.java.util.co​llections.ArrayList(​ );
           
  -
               while( ( match = reSearchResultLine.getMatch( inSearchResults, index ) )
                       != null )
               {
                   index = match.getEndIndex( ); // Move on our index.
                  
  -
                   strPtr = inSearchResults.substring( match.getSubStartIndex( 1 ),
  - match.getSubEndIndex( 1 ) );
  + match.getSubEndIndex( 1 ) );
                   ranking = Integer.parseInt( strPtr.trim( ) );
                   
  -
                   strPtr = inSearchResults.substring( match.getSubStartIndex( 2 ),
  - match.getSubEndIndex( 2 ) );
  + match.getSubEndIndex( 2 ) );
                   strPtr = strPtr.trim( );
                   if( strPtr.startsWith( "/" ) )
                       url = new java.net.URL( "file", null, strPtr );
                   else
  - throw new java.net.MalformedURLException( "'file' is only protocol handled" );
  -
  + throw new java.net.MalformedURLException(
  + "'file' is only protocol handled" );
   
                   strPtr = inSearchResults.substring( match.getSubStartIndex( 3 ),
  - match.getSubEndIndex( 3 ) );
  + match.getSubEndIndex( 3 ) );
                   title = strPtr.trim( );
   
  -
                   strPtr = inSearchResults.substring( match.getSubStartIndex( 4 ),
  - match.getSubEndIndex( 4 ) );
  + match.getSubEndIndex( 4 ) );
                   size = Integer.parseInt( strPtr.trim( ) );
   
  -
                   searchResultItems.add(
                       new SearchResultItem( ranking,
                                               size,
  @@ -528,7 +525,6 @@
       {
           java.io.StringWriter stringwriter = null;
           
  -
           // Make up the query to Swish-e. It looks like this:
           //
           // /usr/bin/swish-e -m MAX_RESULT_COUNT -f PATH_TO_INDEX -w QUERY
  @@ -540,12 +536,11 @@
           strBufferCmd.append( " -f " );
           strBufferCmd.append( inQuery.getSearchIndex( ) );
           strBufferCmd.append( " -w ");
  - strBufferCmd.append( inQuery.getQuery( ) );
  + strBufferCmd.append( inQuery.getQueryString( ) );
           String strCommand = strBufferCmd.toString( );
           if( DEBUG )
               log( "Command to run: " + strCommand );
           
  -
           // Run the swish-e command. Wait on its completion.
           //
           Runtime runtime = Runtime.getRuntime( );
  @@ -553,13 +548,12 @@
           int processResult = process.waitFor( );
           if( processResult != 0 )
               throw new java.io.IOException( "process.waitFor( ) returned non-zero: "
  - + Integer.toString( processResult ) );
  + + Integer.toString( processResult ) );
           processResult = process.exitValue( );
           if( processResult != 0 )
               throw new java.io.IOException( "process.exitValue( ) is non-zero: "
  - + Integer.toString( processResult ) );
  + + Integer.toString( processResult ) );
                   
  -
           // Read the process output. Ingore the error output.
           // In http://java.sun.com/​j2se/1.3/docs/api/ja​va/lang/Process.html​#getInputStream()
           // it suggests using a buffered stream.
  @@ -629,17 +623,17 @@
           //
           String strQuery = System.getProperty( QUERY_PARAM_KEY );
   
  -
           if( strQuery == null )
               throw new NullPointerException( "The 'query' system property is "
  - + "null. Set it on the command-line "
  - + "w/ -Dquery=\"SOME_QUERY\"" );
  + + "null. Set it on the command-line "
  + + "w/ -Dquery=\"SOME_QUERY\"" );
                                               
           SearchSwishe swishe = new SearchSwishe( "/usr/bin/swish-e" );
  - Query query = new Query( strQuery,
  - "/home/stack/cvsroot​/sandbox/search/swis​h.idx",
  - 20 );
  - SearchResult searchresult = swishe.query( query );
  + Query query
  + = new Query( strQuery,
  + "/home/stack/cvsroot​/sandbox/search/swis​h.idx",
  + 20 );
  + SearchResult searchresult = swishe.search( query );
           System.out.println( searchresult.toString( ) );
           return;
       }

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: joist/java/org/joist/search Query.java SearchInterface.java SearchResult.java SearchResultItem.java SearchServlet.java SearchSwishe.java stack Michael Stack 2000-10-25 13:31:17 PDT
Messages per page: