portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jf...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/search SearchService.java Search.java
Date Thu, 15 Jul 2004 00:14:12 GMT
jford       2004/07/14 17:14:12

  Modified:    src/java/org/apache/jetspeed/services/search/lucene
                        LuceneSearchService.java
               src/java/org/apache/jetspeed/services/search
                        SearchService.java Search.java
  Log:
  Search enhancement to manually optimize index
  
  PR: JS1-498
  Submitted by:	Enrique Lara
  
  Revision  Changes    Path
  1.13      +44 -10    jakarta-jetspeed/src/java/org/apache/jetspeed/services/search/lucene/LuceneSearchService.java
  
  Index: LuceneSearchService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/search/lucene/LuceneSearchService.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- LuceneSearchService.java	19 Jun 2004 20:29:17 -0000	1.12
  +++ LuceneSearchService.java	15 Jul 2004 00:14:12 -0000	1.13
  @@ -64,6 +64,10 @@
   
   /**
    * Lucene implementation of search service.
  + * 
  + * This implemenation currently does not synchronize the add/update/removal.
  + * If this service is used in a multi-threaded manner, it would be advisable
  + * to synchronized the Search wrapper class to ensure thread safety.
    *
    * @author <a href="mailto:taylor@apache.org">David Sean taylor</a>
    * @author <a href="mailto:caius1440@hotmail.com">Jeremy Ford</a>
  @@ -87,6 +91,10 @@
       private static final String DEFAULT_ANALYZER_CLASS_NAME = "org.apache.lucene.analysis.standard.StandardAnalyzer";
       private static final String CONFIG_ANALYZER_CLASS_NAME = "analyzer";
       private String analyzerClassName = null;
  +    
  +    private static final boolean DEFAULT_AUTO_OPTIMIZE = true;
  +    private static final String CONFIG_AUTO_OPTIMIZE = "auto_optimize";
  +    private boolean doOptimize = DEFAULT_AUTO_OPTIMIZE;
   
       /**
        * This is the early initialization method called by the
  @@ -97,7 +105,6 @@
        */
       public synchronized void init(ServletConfig conf) throws InitializationException
       {
  -
           // already initialized
           if (getInit())
           {
  @@ -108,7 +115,6 @@
   
           // initialization done
           setInit(true);
  -
       }
   
       /**
  @@ -187,6 +193,9 @@
           
           //Get analyze class name
           analyzerClassName = serviceConf.getString(CONFIG_ANALYZER_CLASS_NAME, DEFAULT_ANALYZER_CLASS_NAME);
  +        
  +        //Whether to optimize automatically after an add/remove/update.
  +        doOptimize = serviceConf.getBoolean(CONFIG_AUTO_OPTIMIZE, DEFAULT_AUTO_OPTIMIZE);
   
           try
           {
  @@ -529,7 +538,10 @@
   
           try
           {
  -            indexWriter.optimize();
  +        	if(doOptimize)
  +            {
  +                indexWriter.optimize();
  +            }
           }
           catch (IOException e)
           {
  @@ -653,9 +665,10 @@
   
               indexReader.close();
   
  -            IndexWriter indexWriter = new IndexWriter(rootDir, newAnalyzer(), false);
  -            indexWriter.optimize();
  -            indexWriter.close();
  +            if(doOptimize)
  +            {
  +                optimize();
  +            }
   
           }
           catch (Exception e)
  @@ -705,15 +718,36 @@
           try
           {
               // Add entries to index
  -            add(c);
  -            result = true;
  +        	if(result)
  +        	{
  +        		add(c);
  +        		result = true;
  +        	}
           }
           catch (Throwable e)
           {
               logger.error("Exception",  e);
           }
   
  -        return false;
  +        return result;
  +    }
  +    
  +    public boolean optimize()
  +    {
  +    	boolean result = false;
  +
  +    	try
  +		{
  +    		IndexWriter indexWriter = new IndexWriter(rootDir, newAnalyzer(), false);
  +            indexWriter.optimize();
  +            indexWriter.close();
  +            result = true;
  +        }
  +        catch (IOException e)
  +        {
  +             logger.error("Error while trying to optimize index.");
  +        }
  +        return result;
       }
   
       private Analyzer newAnalyzer() {
  
  
  
  1.4       +8 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/services/search/SearchService.java
  
  Index: SearchService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/search/SearchService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SearchService.java	23 Feb 2004 03:48:47 -0000	1.3
  +++ SearchService.java	15 Jul 2004 00:14:12 -0000	1.4
  @@ -85,4 +85,11 @@
        * @return 
        */
       public SearchResults search(String search);
  +    
  +    /**
  +     * Optimize search indexes (optional operation).
  +     *
  +     * @return
  +    */
  +    public boolean optimize() throws UnsupportedOperationException;
   }
  
  
  
  1.6       +9 -1      jakarta-jetspeed/src/java/org/apache/jetspeed/services/search/Search.java
  
  Index: Search.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/search/Search.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Search.java	23 Feb 2004 03:48:47 -0000	1.5
  +++ Search.java	15 Jul 2004 00:14:12 -0000	1.6
  @@ -135,5 +135,13 @@
           }
           return true;                        
       }
  +    
  +    /**
  +     * @return
  +     */
  +    public static boolean optimize()
  +    {
  +        return getService().optimize();
  +    }
   
   }
  
  
  

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


Mime
View raw message