[jsword-svn] jsword/java/jsword/org/crosswire/jsword/book/search s

jswordcvs at crosswire.org jswordcvs at crosswire.org
Sat Oct 9 14:45:06 MST 2004


Update of /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search
In directory www.crosswire.org:/tmp/cvs-serv30045/java/jsword/org/crosswire/jsword/book/search

Modified Files:
	Index.java Msg.java IndexManager.java Searcher.java 
	Msg.properties SearcherFactory.java 
Added Files:
	IndexManagerFactory.java IndexManager.properties 
Removed Files:
	Matcher.java IndexFactory.java Matcher.properties 
	MatcherFactory.java Index.properties 
Log Message:
indexing updates

--- Matcher.java DELETED ---

--- NEW FILE: IndexManagerFactory.java ---
package org.crosswire.jsword.book.search;

import org.crosswire.common.util.ClassUtil;
import org.crosswire.common.util.Logger;

/**
 * A Factory class for IndexManagers.
 * 
 * <p><table border='1' cellPadding='3' cellSpacing='0'>
 * <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
 *
 * Distribution Licence:<br />
 * JSword is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General Public License,
 * version 2 as published by the Free Software Foundation.<br />
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.<br />
 * The License is available on the internet
 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, or by writing to:
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA<br />
 * The copyright to this program is held by it's authors.
 * </font></td></tr></table>
 * @see gnu.gpl.Licence
 * @author Joe Walker [joe at eireneh dot com]
 * @version $Id: IndexManagerFactory.java,v 1.1 2004/10/09 21:45:04 joe Exp $
 */
public class IndexManagerFactory
{
    /**
     * Prevent Instansiation
     */
    private IndexManagerFactory()
    {
    }

    /**
     * Create a new IndexManager.
     */
    public static IndexManager getIndexManager()
    {
        return instance;
    }

    /**
     * The singleton
     */
    private static IndexManager instance = null;

    /**
     * The log stream
     */
    private static final Logger log = Logger.getLogger(IndexManagerFactory.class);

    /**
     * Setup the instance
     */
    static
    {
        try
        {
            Class impl = ClassUtil.getImplementor(IndexManager.class);
            instance = (IndexManager) impl.newInstance();
        }
        catch (Exception ex)
        {
            log.error("createIndexManager failed", ex); //$NON-NLS-1$
        }
    }
}

Index: SearcherFactory.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/SearcherFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** SearcherFactory.java	29 Sep 2004 22:21:23 -0000	1.1
--- SearcherFactory.java	9 Oct 2004 21:45:04 -0000	1.2
***************
*** 3,6 ****
--- 3,7 ----
  import org.crosswire.common.util.ClassUtil;
  import org.crosswire.common.util.Logger;
+ import org.crosswire.jsword.book.Book;
  
  /**
***************
*** 40,47 ****
       * Create a new Searcher.
       */
!     public static Searcher createSearcher(Index index) throws InstantiationException
      {
          try
          {
              Class impl = ClassUtil.getImplementor(Searcher.class);
              Searcher parser = (Searcher) impl.newInstance();
--- 41,51 ----
       * Create a new Searcher.
       */
!     public static Searcher createSearcher(Book book) throws InstantiationException
      {
          try
          {
+             IndexManager imanager = IndexManagerFactory.getIndexManager();
+             Index index = imanager.getIndex(book);
+ 
              Class impl = ClassUtil.getImplementor(Searcher.class);
              Searcher parser = (Searcher) impl.newInstance();

Index: Msg.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/Msg.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** Msg.java	29 Sep 2004 22:21:23 -0000	1.9
--- Msg.java	9 Oct 2004 21:45:04 -0000	1.10
***************
*** 29,34 ****
  class Msg extends MsgBase
  {
!     static final Msg TYPE_INDEXGEN = new Msg("IndexManager.TypeIndexGen"); //$NON-NLS-1$
!     static final Msg INDEXING = new Msg("IndexManager.Indexing"); //$NON-NLS-1$
  
      /**
--- 29,33 ----
  class Msg extends MsgBase
  {
!     static final Msg Example = new Msg("Example.Example"); //$NON-NLS-1$
  
      /**

Index: Searcher.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/Searcher.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Searcher.java	29 Sep 2004 22:21:23 -0000	1.5
--- Searcher.java	9 Oct 2004 21:45:04 -0000	1.6
***************
*** 39,46 ****
       * Take a search string and decipher it into a Passage.
       * @param search The string to be searched for
-      * @param restriction What verses are we interested in looking in?
-      * @see org.crosswire.jsword.book.Search#UNRESTRICTED
       * @return The matching verses
       */
!     public Key search(String search, Key restriction) throws BookException;
  }
--- 39,44 ----
       * Take a search string and decipher it into a Passage.
       * @param search The string to be searched for
       * @return The matching verses
       */
!     public Key search(String search) throws BookException;
  }

--- MatcherFactory.java DELETED ---

Index: IndexManager.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/IndexManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** IndexManager.java	29 Sep 2004 22:21:23 -0000	1.1
--- IndexManager.java	9 Oct 2004 21:45:04 -0000	1.2
***************
*** 1,11 ****
  package org.crosswire.jsword.book.search;
  
! import java.util.HashSet;
! import java.util.Iterator;
! import java.util.Set;
! 
! import org.crosswire.common.progress.Job;
! import org.crosswire.common.progress.JobManager;
! import org.crosswire.common.util.Reporter;
  
  /**
--- 1,6 ----
  package org.crosswire.jsword.book.search;
  
! import org.crosswire.jsword.book.Book;
! import org.crosswire.jsword.book.BookException;
  
  /**
***************
*** 33,114 ****
   * @version $Id$
   */
! public class IndexManager
  {
      /**
!      * 
!      */
!     public static IndexManager instance()
!     {
!         return instance;
!     }
! 
!     /**
!      * 
!      */
!     public void createIndex(Index index)
!     {
!         Reporter.informUser(this, Msg.TYPE_INDEXGEN);
! 
!         todo.add(index);
! 
!         Thread work = new Thread(runner);
!         work.start();
!     }
! 
!     /**
!      * The index creation thread
!      */
!     private class IndexerRunnable implements Runnable
!     {
!         /* (non-Javadoc)
!          * @see java.lang.Runnable#run()
!          */
!         public void run()
!         {
!             running = true;
! 
!             Iterator it = todo.iterator();
!             while (it.hasNext())
!             {
!                 Index index = (Index) it.next();
!                 Job job = JobManager.createJob(Msg.INDEXING.toString(), Thread.currentThread(), false);
! 
!                 try
!                 {
!                     index.generateSearchIndex(job);
!                 }
!                 catch (Exception ex)
!                 {
!                     Reporter.informUser(IndexManager.class, ex);
!                     job.ignoreTimings();
!                 }
!                 finally
!                 {
!                     job.done();
!                 }                
!             }
! 
!             running = false;
!         }
!     }
! 
!     /**
!      * 
       */
!     private static IndexManager instance = new IndexManager();
  
      /**
!      * The thread worker that creates the indexes.
       */
!     private Runnable runner = new IndexerRunnable();
  
      /**
!      * The books to be indexed
       */
!     protected Set todo = new HashSet();
  
      /**
!      * Is there an index generation in progress?
       */
!     protected boolean running = false;
  }
--- 28,53 ----
   * @version $Id$
   */
! public interface IndexManager
  {
      /**
!      * Detects if index data has been stored for this Bible already
       */
!     public boolean isIndexed(Book book);
  
      /**
!      * Create a new Searcher.
       */
!     public Index getIndex(Book book) throws BookException;
  
      /**
!      * Read from the given source version to generate ourselves. On completion
!      * of this method the index should be usable.
       */
!     public void scheduleIndexCreation(Book book);
  
      /**
!      * Tidy up after yourself and remove all the files that make up any indexes
!      * you created.
       */
!     public void deleteIndex(Book book) throws BookException;
  }

--- NEW FILE: IndexManager.properties ---

default=org.crosswire.jsword.book.search.lucene.LuceneIndexManager

Index: Msg.properties
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/Msg.properties,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Msg.properties	29 Sep 2004 22:21:23 -0000	1.2
--- Msg.properties	9 Oct 2004 21:45:04 -0000	1.3
***************
*** 6,9 ****
  # It should have no spaces or other punctuation (e.g. _, -, ', ...)
  
! IndexManager.TypeIndexGen=Generating index for this work. Search results will be more accurate when index is complete.
! IndexManager.Indexing=Indexing Bible Data
--- 6,8 ----
  # It should have no spaces or other punctuation (e.g. _, -, ', ...)
  
! Example.Example=Example

Index: Index.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/Index.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Index.java	29 Sep 2004 22:21:23 -0000	1.8
--- Index.java	9 Oct 2004 21:45:04 -0000	1.9
***************
*** 1,8 ****
  package org.crosswire.jsword.book.search;
  
- import java.io.IOException;
- 
- import org.crosswire.common.progress.Job;
- import org.crosswire.jsword.book.Book;
  import org.crosswire.jsword.book.BookException;
  import org.crosswire.jsword.passage.Key;
--- 1,4 ----
***************
*** 36,47 ****
  {
      /**
-      * An initializer type method so we can configure the Search engine at
-      * runtime. This method is run first of all, before anything else and should
-      * do everything it can to ensure that future method calls will be error
-      * free without consuming significant system resources.
-      */
-     public void init(Book book) throws BookException;
- 
-     /**
       * For a given word find a list of references to it.
       * If the <code>word</code> being searched for is null then an empty Key
--- 32,35 ----
***************
*** 60,85 ****
       * @return A new Key representing the given string, if possible
       * @throws NoSuchKeyException If the string can not be turned into a Key
       */
      public Key getKey(String name) throws NoSuchKeyException;
- 
-     /**
-      * Tidy up after yourself and remove all the files that make up any indexes
-      * you created.
-      */
-     public void delete() throws BookException;
- 
-     /**
-      * Detects if index data has been stored for this Bible already
-      */
-     public boolean isIndexed();
- 
-     /**
-      * Read from the given source version to generate ourselves. On completion
-      * of this method the index should be usable. If this is not the natural
-      * way this emthod finishes then it should be possible to call loadIndexes()
-      * @param ajob The place to report progress
-      * @throws IOException if the load fails to read from disk
-      * @throws BookException if there is a problem reading from the Bible
-      */
-     public void generateSearchIndex(Job ajob) throws IOException, BookException, NoSuchKeyException;
  }
--- 48,53 ----
       * @return A new Key representing the given string, if possible
       * @throws NoSuchKeyException If the string can not be turned into a Key
+      * @see org.crosswire.jsword.passage.KeyFactory#getKey(String)
       */
      public Key getKey(String name) throws NoSuchKeyException;
  }

--- Matcher.properties DELETED ---

--- Index.properties DELETED ---

--- IndexFactory.java DELETED ---



More information about the jsword-svn mailing list