Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: joist/java/org/joist/search SearchResultItem.java SearchServlet.java SearchSwishe.java SelfTest.java

Project highlights: Architectural Overview

joist
Discussion topic

Back to topic list

CVS update: joist/java/org/joist/search SearchResultItem.java SearchServlet.java SearchSwishe.java SelfTest.java

Author stack
Full name Michael Stack
Date 2000-11-01 18:20:34 PST
Message User: stack
  Date: 00/11/01 18:20:34

  Modified: java/org/joist/search SearchResultItem.java
                        SearchServlet.java SearchSwishe.java SelfTest.java
  Log:
  New spec. for how result URLs are to be returned. Pass necessary info. where's it's needed. Sync method calls and constructors
  
  Revision Changes Path
  1.6 +146 -29 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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SearchResultItem.java 2000/10/31 06:13:44 1.5
  +++ SearchResultItem.java 2000/11/02 02:20:34 1.6
  @@ -51,14 +51,14 @@
   * «Immutable -- Read-Only.»
   *
   * @author <a href="mailto:stack@c​ollab.net">St.Ack​</a>
  -* @version $Id: SearchResultItem.java,v 1.5 2000/10/31 06:13:44 stack Exp $
  +* @version $Id: SearchResultItem.java,v 1.6 2000/11/02 02:20:34 stack Exp $
   */
   public class SearchResultItem
   {
       /** Class version string
       */
       public static final String versionID
  - = "$Id: SearchResultItem.java,v 1.5 2000/10/31 06:13:44 stack Exp $";
  + = "$Id: SearchResultItem.java,v 1.6 2000/11/02 02:20:34 stack Exp $";
   
   
       /** Search engine ranking.
  @@ -85,6 +85,46 @@
        * Used by the getFileRelativeToHtDoc( ) method.
        */
       private String htdocPath = null;
  +
  +
  + /** Domain to use.
  + * Needed to manufacture search result url
  + * according to receipe described at head of getSourceCastURL.
  + * @see #getSourceCaseURL
  + */
  + private String domain = null;
  +
  +
  + /** Port to use.
  + * Needed to manufacture search result url
  + * according to receipe described at head of getSourceCastURL.
  + * @see #getSourceCaseURL
  + */
  + private String port = null;
  +
  +
  + /** Protocol to use.
  + * Needed to manufacture search result url
  + * according to receipe described at head of getSourceCastURL.
  + * @see #getSourceCaseURL
  + */
  + private String protocol = null;
  +
  +
  + /** Protocol default.
  + */
  + private final static String PROTOCOL_DEFAULT = "http";
  +
  +
  + /** Define for '/www/'.
  + */
  + private final static String SLASH_WWW_SLASH = "/www/";
  +
  +
  + /** Default port 80 define.
  + */
  + public static final String DEFAULT_PORT_80
  + = "80";
   
   
       /** Constructor
  @@ -98,7 +138,17 @@
       * @param inTitle Title of the file. May be null.
       * @param inHtDocPath Path to htdocs. Used by the
       * getFileRelativeToHtDoc method.
  - * Can be null.
  + * Cannot be null. It's too important.
  + * @param inDomain Pass me a domain. I need this to make up a
  + * search result url according to receipe described at head of
  + * getSourceCastURL. Cannot be null. Will throw exception if
  + * it is.
  + * @param inPort Port to use making up search result url
  + * according to receipe described at head of getSourceCastURL.
  + * If null, we assume port 80.
  + * @param inProtocol Protocol to use making up search result url
  + * according to receipe described at head of getSourceCastURL.
  + * If null we assume 'http'.
       *
       * @exception NullPointerException If passed in inURL object is empty.
       */
  @@ -106,42 +156,32 @@
                                   int inSize,
                                   java.net.URL inURL,
                                   String inTitle,
  - String inHtdocPath )
  + String inHtdocPath,
  + String inDomain,
  + String inPort,
  + String inProtocol )
           throws NullPointerException
       {
           if( inURL == null )
               throw new NullPointerException( "inURL is null" );
           url = inURL;
   
  + if( inHtdocPath == null )
  + throw new NullPointerException( "inHtdocPath is null" );
  + htdocPath = inHtdocPath.trim( );
  +
  + if( inDomain == null )
  + throw new NullPointerException( "inDomain is null" );
  + domain = inDomain.trim( );
  +
  + port = inPort.trim( );
  + protocol = inProtocol.trim( );
           ranking = inRanking;
           size = inSize;
           title = inTitle.trim( );
  - htdocPath = inHtdocPath.trim( );
       }
   
   
  - /** Constructor
  - *
  - * @param inRanking Search ranking. Meaning varies from search-engine
  - * to search-engine. Enter -1 or 0 if not returned
  - * by the search engine.
  - * @param inSize Size of returned file. Enter -1 or 0 if not
  - * returned by the search engine.
  - * @param inURL File or URL to search-engine result.
  - * @param inTitle Title of the file. May be null.
  - *
  - * @exception NullPointerException If passed in inURL object is empty.
  - */
  - public SearchResultItem( int inRanking,
  - int inSize,
  - java.net.URL inURL,
  - String inTitle )
  - throws NullPointerException
  - {
  - this( inRanking, inSize, inURL, inTitle, null );
  - }
  -
  -
       /** Get search-engine ranking
       * @return Returns an int. It's meaning will differ across search-engines.
       * Will need some kind of impossible mapping function if we ever want to
  @@ -198,8 +238,9 @@
   
       /** Return the 'file' portion of the url w/
       * the htdoc path stripped off the front.
  - * Does nothing if htdoc is null.
  - * @return 'File' portion of the url
  + * Does nothing if htdoc is null.
  + * @return 'File' portion of the url.
  + * Has a leading '/'.
       */
       public String getFileRelativeToHtDoc( )
       {
  @@ -229,5 +270,81 @@
       public String getTitle( )
       {
           return title;
  + }
  +
  +
  + /** Run a special sourcecast transformation on the search engine result.
  + *
  + * Talking to Jason Robbins today, 11/01/2000, he explained the following
  + * transform for the results returned by swish-e. The transform is to be
  + * used as the URL that a user clicks on in the search page when they want
  + * to go to a found item.
  + * <p>
  + * Here is the receipe. If swish-e returns
  + * /home/stack/cvsroot/​sandbox/data/helm/ht​docs/bsdchess/www/in​dex.html,
  + * we should manufacture a result URL of http://bsdchess.wire​open.org/index.html.​
  + * More formally, using the PROTOCOL, PORT, DOMAIN and HTDOC passed to this
  + * constructor, rearrange the swish-e result file path extracting the project
  + * name and parring back the file path to what's left stripping to after the
  + * 'www' -- the PATH_REMAINDER -- as: PROTOCOL://PROJECT.D​OMAIN:PORT/PATH_REMA​INDER
  + * <p>
  + * I expect the rules to change.
  + *
  + * @return String of the form 'PROTOCOL://PROJECT.​DOMAIN:PORT/PATH_REM​AINDER
  + * Returns null for fields for which we can't determine a value.
  + *
  + * @exception NullPointerException If passed in inURL object is empty.
  + */
  + public String getSourceCastURL( )
  + throws NullPointerException
  + {
  + StringBuffer strBuffer = new StringBuffer( ); // StrBuffer to build url in.
  + String projectName = null; // Name of project.
  + String resource = null; // Part of file-path that follows '...htdocs/project/www/'
  +
  + // Before i do anything, get the project name
  + // and resource. relativeURL as returned by
  + // getFileRelativeToHtDoc( )
  + // looks like /PROJECT_NAME/www/some_file, etc.
  + // Cut it up into projectName and PATH_REMAINDER
  + //
  + String relativeURL = getFileRelativeToHtDoc( );
  + if( relativeURL == null )
  + throw new NullPointerException( "getFileRelativeToHtDoc( ) returned null" );
  + if( relativeURL.startsWith( java.io.File.separator ) )
  + relativeURL = relativeURL.substring( 1 ); // Strip leading '/'
  + int index = relativeURL.indexOf( SLASH_WWW_SLASH );
  + if( index < 0 )
  + {
  + throw new IndexOutOfBoundsException( "getFileRelativeToHtDoc( )"
  + + " does not have expected 'project'/www/'resource' pattern: "
  + + relativeURL );
  + }
  + projectName = relativeURL.substring( 0, index );
  + if( projectName.length( ) <= 0 )
  + throw new NullPointerException( "projectName is zero length" );
  + resource = relativeURL.substring( index + SLASH_WWW_SLASH.length( ) );
  + if( resource.length( ) <= 0 )
  + throw new NullPointerException( "resource is zero length" );
  +
  + // Now start making up the url
  + //
  + strBuffer.append( ( protocol == null )
  + ? PROTOCOL_DEFAULT
  + : protocol );
  + strBuffer.append( "://" );
  + strBuffer.append( projectName );
  + strBuffer.append( "." );
  + strBuffer.append( domain );
  + if( port != null
  + || port.equals( DEFAULT_PORT_80 ) )
  + {
  + strBuffer.append( ":" );
  + strBuffer.append( port );
  + }
  + strBuffer.append( "/" );
  + strBuffer.append( resource );
  +
  + return strBuffer.toString( );
       }
   }
  
  
  
  1.6 +6 -3 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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SearchServlet.java 2000/10/31 06:03:51 1.5
  +++ SearchServlet.java 2000/11/02 02:20:34 1.6
  @@ -97,7 +97,7 @@
   * </ol>
   *
   * @author <a href="mailto:stack@c​ollab.net">St.Ack​</a>
  -* @version $Id: SearchServlet.java,v 1.5 2000/10/31 06:03:51 stack Exp $
  +* @version $Id: SearchServlet.java,v 1.6 2000/11/02 02:20:34 stack Exp $
   */
   public class SearchServlet
       extends org.joist.security.U​nsecureServlet
  @@ -106,7 +106,7 @@
       /** Class version string
       */
       public static final String versionID
  - = "$Id: SearchServlet.java,v 1.5 2000/10/31 06:03:51 stack Exp $";
  + = "$Id: SearchServlet.java,v 1.6 2000/11/02 02:20:34 stack Exp $";
       
       
       /** Logging object.
  @@ -186,7 +186,10 @@
                       SearchSwishe swishe
                           = new SearchSwishe(
                               myProperties.getProperty( BINARY_PATH ),
  - myProperties.getProperty( DOC_ROOT ) );
  + myProperties.getProperty( DOC_ROOT ),
  + myProperties.getProperty( DOMAIN_KEY ),
  + myProperties.getProperty( HTTP_PORT_KEY ),
  + null /* Need to ask how to figure protocol */ );
                           
                       SearchResult searchresult
                           = swishe.search( objQuery );
  
  
  
  1.6 +67 -23 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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SearchSwishe.java 2000/10/31 06:13:44 1.5
  +++ SearchSwishe.java 2000/11/02 02:20:34 1.6
  @@ -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.5 2000/10/31 06:13:44 stack Exp $
  +* @version $Id: SearchSwishe.java,v 1.6 2000/11/02 02:20:34 stack Exp $
   * @see <a href="http://sunsite.berke​ley.edu/SWISH-E/Manu​al">Swish-e Documentation</a>
   */
   public class SearchSwishe
  @@ -68,7 +68,7 @@
       /** Class version string
       */
       private static final String versionID
  - = "$Id: SearchSwishe.java,v 1.5 2000/10/31 06:13:44 stack Exp $";
  + = "$Id: SearchSwishe.java,v 1.6 2000/11/02 02:20:34 stack Exp $";
   
   
       /** Define key for pulling system property DEBUG.
  @@ -200,37 +200,65 @@
       */
       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.
  - * @exception java.io.FileNotFoundException If swish-e
  - * binary does not exist.
  - * @exception gnu.regexp.REException Should never happen.
  - * Let caller figure what to do w/ it.
  +
  +
  + /** Domain to use.
  + * Needed to manufacture search result url
  + * according to receipe described at head of getSourceCastURL
  + * in searchresultitem.
  + * @see SearchResultItem#get​SourceCastURL
  + */
  + private String domain = null;
  +
  +
  + /** Port to use.
  + * Needed to manufacture search result url
  + * according to receipe described at head of getSourceCastURL
  + * in searchresultitem.
  + * @see SearchResultItem#get​SourceCastURL
  + */
  + private String port = null;
  +
  +
  + /** Protocol to use.
  + * Needed to manufacture search result url
  + * according to receipe described at head of getSourceCastURL
  + * in searchresultitem.
  + * @see SearchResultItem#get​SourceCastURL
       */
  - public SearchSwishe( String inBinary )
  - throws java.io.FileNotFoundException,
  - gnu.regexp.REException,
  - NullPointerException
  - {
  - this( inBinary, null );
  - }
  + private String protocol = null;
  +
   
       /** Constructor.
       *
       * @param inBinary Path to the swish-e binary
       * @param inDocRoot May be null. Document root for search.
  + * @param inDomain Pass me a domain. I need this to make up a
  + * search result url according to receipe described at head of
  + * getSourceCastURL in searchresultitem. Cannot be null.
  + * Will throw exception if it is.
  + * @param inPort Port to use making up search result url
  + * according to receipe described at head of getSourceCastURL.
  + * in searchresultitem. Cannot be null.
  + * Will throw exception if it is.
  + * @param inProtocol Protocol to use making up search result url
  + * according to receipe described at head of getSourceCastURL.
  + * in searchresultitem. Cannot be null.
  + *
       * @exception NullPointerException If passed in params
       * are null or empty.
       * @exception java.io.FileNotFoundException If swish-e
       * binary does not exist.
       * @exception gnu.regexp.REException Should never happen.
       * Let caller figure what to do w/ it.
  + *
  + * @see SearchResultItem#get​SourceCastURL
       */
  - public SearchSwishe( String inBinary, String inDocRoot )
  + public SearchSwishe( String inBinary,
  + String inDocRoot,
  + String inDomain,
  + String inPort,
  + String inProtocol )
           throws java.io.FileNotFoundException,
                   gnu.regexp.REException,
                   NullPointerException
  @@ -243,7 +271,16 @@
                   + inBinary
                   + "> does not exist" );
   
  - docRoot = inDocRoot;
  + if( inDocRoot == null )
  + throw new NullPointerException( "inDocRoot is null" );
  + docRoot = inDocRoot.trim( );
  +
  + if( inDomain == null )
  + throw new NullPointerException( "inDomain is null" );
  + domain = inDomain.trim( );
  +
  + port = inPort;
  + protocol = inProtocol;
   
           // Make all the regular expressions i'll need
           //
  @@ -508,7 +545,10 @@
                           size,
                           url,
                           title,
  - docRoot ) );
  + docRoot,
  + domain,
  + port,
  + protocol ) );
               }
           } // End of label_results if..else
   
  @@ -654,7 +694,11 @@
                   + "null. Set it on the command-line "
                   + "w/ -Dquery=\"SOME_QUERY\"" );
   
  - SearchSwishe swishe = new SearchSwishe( "/usr/bin/swish-e" );
  + SearchSwishe swishe = new SearchSwishe( "/usr/bin/swish-e",
  + "/home/stack/cvsroot​/sandbox/data/helm/h​tdoc",
  + "marx.collab.net",
  + "8500",
  + "http" );
           Query query
               = new Query( strQuery,
                   "/home/stack/cvsroot​/sandbox/search/swis​h.idx",
  
  
  
  1.2 +31 -9 joist/java/org/joist​/search/SelfTest.jav​a
  
  Index: SelfTest.java
  ====================​====================​====================​=======
  RCS file: /cvs/joist/java/org/​joist/search/SelfTes​t.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SelfTest.java 2000/10/25 20:11:05 1.1
  +++ SelfTest.java 2000/11/02 02:20:34 1.2
  @@ -81,7 +81,7 @@
   *
   * @see <a href="http://www.junit.org">JUnit Site</a>
   * @author <a href="mailto:stack@c​ollab.net">St.Ack​</a>
  -* @version $Id: SelfTest.java,v 1.1 2000/10/25 20:11:05 stack Exp $
  +* @version $Id: SelfTest.java,v 1.2 2000/11/02 02:20:34 stack Exp $
   */
   public class SelfTest
       extends junit.framework.TestCase
  @@ -89,7 +89,7 @@
       /** Class version string
       */
       public static final String versionID
  - = "$Id: SelfTest.java,v 1.1 2000/10/25 20:11:05 stack Exp $";
  + = "$Id: SelfTest.java,v 1.2 2000/11/02 02:20:34 stack Exp $";
       
       
       /** Use this key to pull query from system properties.
  @@ -178,14 +178,20 @@
       {
          try
          {
  - SearchSwishe swishe = new SearchSwishe( PATH_TO_BINARY );
  + SearchSwishe swishe
  + = new SearchSwishe( PATH_TO_BINARY,
  + "/home/stack/cvsroot​/sandbox/data/helm/h​tdoc",
  + "marx.collab.net",
  + "8500",
  + "http" );
               assertNotNull( "Swishe object is null", swishe );
               Query query
                   = new Query( strQuery,
                       index,
                       PAGES_PER_QUERY );
               assertNotNull( "Query object is null", query );
  - SearchResult searchresult = swishe.search( query );
  + SearchResult searchresult
  + = swishe.search( query );
               assertNotNull( "SearchResult object is null", searchresult );
               com.sun.java.util.co​llections.List items
                   = searchresult.getSear​chResultItems( );
  @@ -216,14 +222,19 @@
       {
          try
          {
  - SearchSwishe swishe = new SearchSwishe( PATH_TO_BINARY );
  + SearchSwishe swishe = new SearchSwishe( PATH_TO_BINARY,
  + "/home/stack/cvsroot​/sandbox/data/helm/h​tdoc",
  + "marx.collab.net",
  + "8500",
  + "http" );
               assertNotNull( "Swishe object is null", swishe );
               Query query
                   = new Query( "BAD_QUERY_BAD_QUERY",
                       index,
                       PAGES_PER_QUERY );
               assertNotNull( "Query object is null", query );
  - SearchResult searchresult = swishe.search( query );
  + SearchResult searchresult
  + = swishe.search( query );
               assertNotNull( "SearchResult object is null", searchresult );
          }
           
  @@ -241,7 +252,12 @@
       {
          try
          {
  - SearchSwishe swishe = new SearchSwishe( PATH_TO_BINARY );
  + SearchSwishe swishe
  + = new SearchSwishe( PATH_TO_BINARY,
  + "/home/stack/cvsroot​/sandbox/data/helm/h​tdoc",
  + "marx.collab.net",
  + "8500",
  + "http" );
               assertNotNull( "Swishe object is null", swishe );
               Query query
                   = new Query( strQuery,
  @@ -267,7 +283,12 @@
       {
          try
          {
  - SearchSwishe swishe = new SearchSwishe( PATH_TO_BINARY );
  + SearchSwishe swishe
  + = new SearchSwishe( PATH_TO_BINARY,
  + "/home/stack/cvsroot​/sandbox/data/helm/h​tdoc",
  + "marx.collab.net",
  + "8500",
  + "http" );
               assertNotNull( "Swishe object is null", swishe );
               Query query
                   = new Query( strQuery,
  @@ -277,7 +298,8 @@
               SearchResult searchresult = null;
               for( int i = 0; i < 10; i++ )
               {
  - searchresult = swishe.search( query );
  + searchresult
  + = swishe.search( query );
                   assertNotNull( "SearchResult object is null", searchresult );
               }
          }

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

Messages

Show all messages in topic

CVS update: joist/java/org/joist/search SearchResultItem.java SearchServlet.java SearchSwishe.java SelfTest.java stack Michael Stack 2000-11-01 18:20:34 PST
Messages per page: