You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by pa...@apache.org on 2003/05/07 02:17:16 UTC

cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene TestLuceneSearch.java SearchResults.java SearchResult.java LuceneSearchService.java LuceneSearch.java

paulsp      2003/05/06 17:17:16

  Added:       src/java/org/apache/jetspeed/services/lucene
                        TestLuceneSearch.java SearchResults.java
                        SearchResult.java LuceneSearchService.java
                        LuceneSearch.java
  Log:
  Early commit of Lucene search service.   Note this is a
  work in progress and not ready for use.
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene/TestLuceneSearch.java
  
  Index: TestLuceneSearch.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.services.lucene;
  
  // Java imports
  import java.util.HashMap;
  
  // Cactus and Junit imports
  import junit.awtui.TestRunner;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  // Jetspeed imports
  import org.apache.jetspeed.services.lucene.LuceneSearch;
  import org.apache.jetspeed.services.lucene.SearchResult;
  import org.apache.jetspeed.services.lucene.SearchResults;
  
  // Turbine imports
  import org.apache.turbine.services.TurbineServices;
  import org.apache.turbine.util.TurbineConfig;
  import org.apache.turbine.util.StringUtils;
  
  // Lucene imports
  import org.apache.lucene.document.Document;
  import org.apache.lucene.search.Hits;
  
  /**
   * TestIdGenerator
   *
   * @author <a href="paulsp@apache.org">Paul Spencer</a>
   * @version $Id: TestLuceneSearch.java,v 1.1 2003/05/07 00:17:16 paulsp Exp $
   */
  public class TestLuceneSearch extends TestCase {
      
      /**
       * Configuration object to run Turbine outside a servlet container
       * ( uses turbine.properties )
       */
      private static TurbineConfig config = null;
      
      /**
       * Sets up TurbineConfig using the system property:
       * <pre>turbine.properties</pre>
       */
      static
      {
          try
          {
              config = new TurbineConfig( "../webapp",
              "/WEB-INF/conf/TurbineResources.properties");
              config.init();
          }
          catch (Exception e)
          {
              fail(StringUtils.stackTrace(e));
          }
      }
      
      /**
       * Defines the testcase name for JUnit.
       *
       * @param name the testcase's name.
       */
      public TestLuceneSearch(String name) {
          super( name );
      }
      
      /**
       * Start the tests.
       *
       * @param args the arguments. Not used
       */
      public static void main(String args[]) {
          TestRunner.main( new String[] { TestLuceneSearch.class.getName() } );
      }
   
      public void setup() {
      }
      /**
       * Creates the test suite.
       *
       * @return a test suite (<code>TestSuite</code>) that includes all methods
       *         starting with "test"
       */
      public static Test suite() {
          // All methods starting with "test" will be executed in the test suite.
          return new TestSuite( TestLuceneSearch.class );
      }
      
      /**
       *
       * @throws Exception
       */
      public void testVerifyJetspeedSearch() throws Exception
      {
          SearchResult result = null;
          SearchResults results  = LuceneSearch.search( "+jetspeed +overview");
          System.out.println("hits = " + results.size());
          for (int i = 0; i < results.size(); i++)
          {
              result = results.get(i);
              System.out.println("Score = " + result.getScore());
              System.out.println("title = " + result.getTitle());
              System.out.println("summary = " + result.getDescription());
              System.out.println("url = " + result.getDocumentURL());
          }
      }
  
  }
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene/SearchResults.java
  
  Index: SearchResults.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.services.lucene;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
  *
   * @author  paul
   */
  public class SearchResults
  {
      private List results = null;
      
      public SearchResults()
      {
          init(0);
      }
      public SearchResults(int initialCapacity)
      {
          init(initialCapacity);
      }
      
      private void init(int initialCapacity)
      {
          results = new ArrayList(initialCapacity);
      }
      
      public boolean add(SearchResult searchResult)
      {
          return results.add(searchResult);
      }
      
      public void add(int index, SearchResult searchResult)
      {
          results.add(index, searchResult);
          return;
      }
      
      public SearchResult get(int index)
      {
        return (SearchResult) results.get(index);
      }
      
      public int size()
      { 
          return results.size();
      }
      
      
  }
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene/SearchResult.java
  
  Index: SearchResult.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.services.lucene;
  
  /**
   *
   * @author  paul
   */
  public class SearchResult
  {
      
      /** Holds value of property documentURL. */
      private String documentURL;
      
      /** Holds value of property title. */
      private String title;
      
      /** Holds value of property description. */
      private String description;
      
      /** Holds value of property score. */
      private float score;
      
      /** Getter for property targetURL.
       * @return Value of property targetURL.
       *
       */
      public String getDocumentURL()
      {
          return this.documentURL;
      }
      
      /** Setter for property targetURL.
       * @param targetURL New value of property targetURL.
       *
       */
      public void setDocumentURL(String documentURL)
      {
          this.documentURL = documentURL;
      }
      
      /** Getter for property title.
       * @return Value of property title.
       *
       */
      public String getTitle()
      {
          return this.title;
      }
      
      /** Setter for property title.
       * @param title New value of property title.
       *
       */
      public void setTitle(String title)
      {
          this.title = title;
      }
      
      /** Getter for property description.
       * @return Value of property description.
       *
       */
      public String getDescription()
      {
          return this.description;
      }
      
      /** Setter for property description.
       * @param description New value of property description.
       *
       */
      public void setDescription(String description)
      {
          this.description = description;
      }
      
      /** Getter for property score.
       * @return Value of property score.
       *
       */
      public float getScore()
      {
          return this.score;
      }
      
      /** Setter for property score.
       * @param score New value of property score.
       *
       */
      public void setScore(float score)
      {
          this.score = score;
      }
      
  }
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene/LuceneSearchService.java
  
  Index: LuceneSearchService.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.services.lucene;
  
  // Java imports
  import java.io.File;
  import java.io.IOException;
  import java.net.URL;
  import javax.servlet.ServletConfig;
  
  // Jetspeed imports
  
  // Turbine imports
  import org.apache.turbine.services.InitializationException;
  import org.apache.turbine.services.resources.ResourceService;
  import org.apache.turbine.services.Service;
  import org.apache.turbine.services.servlet.TurbineServlet;
  import org.apache.turbine.services.TurbineBaseService;
  import org.apache.turbine.services.TurbineServices;
  import org.apache.turbine.util.Log;
  
  // Lucene imports
  import org.apache.lucene.analysis.Analyzer;
  import org.apache.lucene.analysis.standard.StandardAnalyzer;
  import org.apache.lucene.document.Document;
  import org.apache.lucene.index.IndexWriter;
  import org.apache.lucene.queryParser.QueryParser;
  import org.apache.lucene.search.IndexSearcher;
  import org.apache.lucene.search.Hits;
  import org.apache.lucene.search.Query;
  import org.apache.lucene.search.Searcher;
  
  public class LuceneSearchService extends TurbineBaseService
  {
      
      public static final String SERVICE_NAME = "LuceneSearch";
      private static final String CONFIG_DIRECTORY = "directory";
      private static final String CONFIG_DESCRIPTION_FIELDNAME = "fieldname.description";
      private static final String CONFIG_TITLE_FIELDNAME = "fieldname.title";
      private static final String CONFIG_URL_FIELDNAME = "fieldname.url";
      private String descriptionFieldName = null;
      private String indexRoot = null;
      private Searcher searcher = null;
      private String titleFieldName = null;
      private String urlFieldName  = null;
      
      /** Creates a new instance of SearchService */
      public LuceneSearchService()
      {
      }
      
      /**
       * This is the early initialization method called by the
       * Turbine <code>Service</code> framework
       * @param conf The <code>ServletConfig</code>
       * @exception throws a <code>InitializationException</code> if the service
       * fails to initialize
       */
      public synchronized void init(ServletConfig conf) throws InitializationException
      {
          
          // already initialized
          if (getInit()) return;
          
          initConfiguration(conf);
          
          // initialization done
          setInit(true);
          
      }
      
      /**
       * This is the lateinitialization method called by the
       * Turbine <code>Service</code> framework
       *
       * @exception throws a <code>InitializationException</code> if the service
       * fails to initialize
       */
      public void init() throws InitializationException
      {
          Log.info( "Late init for " + LuceneSearchService.SERVICE_NAME + " called" );
          while( !getInit() )
          {
              //Not yet...
              try
              {
                  Thread.sleep( 100 );
                  Log.info( "Waiting for init of " + LuceneSearchService.SERVICE_NAME + "..." );
              } catch (InterruptedException ie )
              {
                  Log.error( ie );
              }
          }
      }
      
      /**
       * This is the shutdown method called by the
       * Turbine <code>Service</code> framework
       */
      public void shutdown()
      {
      }
      
      /**
       * Loads the configuration parameters for this service from the
       * JetspeedResources.properties file.
       *
       * @exception throws a <code>InitializationException</code> if the service
       * fails to initialize
       */
      private void initConfiguration(ServletConfig conf) throws InitializationException
      {
          if (getInit())
          {
              return;
          }
          
          // get configuration parameters from Jetspeed Resources
          ResourceService serviceConf = ((TurbineServices)TurbineServices.getInstance())
          .getResources(LuceneSearchService.SERVICE_NAME);
          
          // Get config properties
          descriptionFieldName  = serviceConf.getString( CONFIG_DESCRIPTION_FIELDNAME);
          titleFieldName  = serviceConf.getString( CONFIG_TITLE_FIELDNAME);
          urlFieldName  = serviceConf.getString( CONFIG_URL_FIELDNAME);
          indexRoot = serviceConf.getString( CONFIG_DIRECTORY);
          
          //
          // The following section opens or creates the search index
          //
          //
          File rootDir = new File(indexRoot);
          
          //If the rootDir does not exist, treat it as context relative
          if (!rootDir.exists())
          {
              if (indexRoot != null)
              {
                  String rootDirPath = TurbineServlet.getRealPath("") + indexRoot;
                  rootDir = new File(rootDirPath);
                  if (!rootDir.exists())
                  {
                      rootDir.mkdir();
                      Log.info("Created index directory '" + rootDir.getPath() + "'");
                  }
              }
          }
          
          try
          {
              searcher = new IndexSearcher( rootDir.getPath());
          }
          catch (Exception e)
          {
              try
              {
                  Analyzer analyzer = new StandardAnalyzer();
                  IndexWriter indexWriter = new IndexWriter( rootDir, new StandardAnalyzer(), true);
                  indexWriter.close();
                  indexWriter = null;
                  Log.info("Created Lucene Index in " + rootDir.getPath());
                  searcher = new IndexSearcher(rootDir.getPath());
              }
              catch (Exception e1)
              {
                  Log.error(this.getClass().getName() + ".initConfiguration - Getting or creating IndexSearcher");
                  Log.error(e);
                  throw new InitializationException("Getting or creating Index Searcher");
              }
          }
          
          //Mark that we are done
          setInit(true);
      }
      
      /**
       * Search
       *
       * @param searchString is the what is being searched for
       * @return Hits, if no hits then null.
       */
      public SearchResults search(String searchString)
      {
          Hits hits = null;
          try
          {
              Analyzer analyzer = new StandardAnalyzer();
              
              Query query = QueryParser.parse(searchString, "contents", analyzer);
              System.out.println("Searching for: " + query.toString("contents"));
              
              hits = searcher.search(query);
          }
          catch (Exception e)
          {
              Log.error(e);
          }
          
          // Copy hits to the result list
          int hitCount = hits.length();
          Document doc = null;
          SearchResults results = new SearchResults(hitCount);
          for (int counter = 0; counter < hitCount; counter++)
          {
              SearchResult result = new SearchResult();
              try
              {
                  doc = hits.doc(counter);
                  result.setScore(hits.score(counter));
                  result.setDescription(doc.getField(this.descriptionFieldName).toString());
                  result.setTitle(doc.getField(this.titleFieldName).toString());
                  result.setDocumentURL(doc.getField(this.urlFieldName).toString());
                  results.add(counter, result);
              }
              catch (IOException ioe)
              {
                  Log.error(ioe);
                  throw new Error("Error retrieving search results", ioe);
              }
              result = null;
          }
          return results;
      }
  
      /** 
       * Add a page to be indexed.
       *
       * @return true is page added sucessfully added.
       * @task Next to be implemented
       */
      public boolean add(URL pageToAdd)
      {
          return false;
      }
      
      public String[] getSearchSets()
      {
          return null;
      }
  }
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene/LuceneSearch.java
  
  Index: LuceneSearch.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.services.lucene;
  
  import java.net.URL;
  // Jetspeed imports
  import org.apache.jetspeed.services.lucene.LuceneSearchService;
  
  // Turbine imports
  import org.apache.turbine.services.TurbineServices;
  
  
  /**
   * Static accessor for the LuceneSearchService
   *
   * @author <a href="mailto:paulsp@apache.org">Paul Spencer</a>
   * @version $Id: LuceneSearch.java,v 1.1 2003/05/07 00:17:16 paulsp Exp $
   */
  public abstract class LuceneSearch {
  
      /** Creates new LuceneSearchService */
      public LuceneSearch() {
      }
  
      /**
       * Utility method for accessing the service 
       * implementation
       *
       * @return a LuceneSearchServiceimplementation instance
       */
      protected static LuceneSearchService getService()
      {
          return (LuceneSearchService)TurbineServices
              .getInstance().getService(LuceneSearchService.SERVICE_NAME);
      }
  
      /**
       * Search the default index
       *
       * @param searchString to use
       * @return Hits
       */    
      public static SearchResults search(String searchString)
      {
          return getService().search( searchString);
      }
  
      public static boolean add(URL pageToAdd)
      {
          return getService().add(pageToAdd);
      }
  
  }
  
  
  

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


AW: cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/lucene TestLuceneSearch.java SearchResults.java SearchResult.java LuceneSearchService.java LuceneSearch.java

Posted by Joachim Müller <jo...@wemove.com>.
Hi Paul.

With great interest I have seen your cvs commit on the 
lucene service. Currently I am working on a similar 
approach. I want to share my thoughts:

In my opinion there are 2 different approaches. 

1.) index only the content of the portlets (i.e. just the
messages of a news portlet) together with the content id's,
templates and actions. The advantage of this approach is, that
only useful information will be indexed. The big disadvantage 
is of course that for every indexable content (portlet) type 
the developer must add an interface to lucene and register it
with the service. (I am not perfectly sure about this. Maybe
there is a way to index portlets separatly.)

2.) index a whole website using a spider. The advantage is
that every content will be indexed automatically.


I am trying to follow the second approach.

I ran into some problems:

a) Different users can have different content displayed on their configurable pages. To be very accurate, there should be an index for every user. (For me this problem is not too serious, because our 
users can configure very little.) This would lead into quite a few
performance issues I believe.


b) All urls have a session ID attached. The spider should filter the session ID and store only the url without the session ID. When 
searching inside the portal, the session id of the current user
has to be attached to the url of the search results.


c) The spider should be able to recognise the meta tags INDEX, FOLLOW. This is not a big thing. The problem lies in jetspeed, since I must be
able to set this metatags from within a portlet. (As I remember the
Meta tags are set in the default template.) What, if a page combines
portlets that should be indexed and portlets that should not be 
indexed.


Do you have any comments on this? What are your plans, what is your concept. I am very interested! ;-)


Best regards.

Joachim