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

jswordcvs at crosswire.org jswordcvs at crosswire.org
Wed Sep 29 15:21:25 MST 2004


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

Modified Files:
	Index.java Msg.java Msg.properties 
Added Files:
	Matcher.java Thesaurus.properties IndexFactory.java 
	Matcher.properties IndexManager.java ThesaurusFactory.java 
	Searcher.java Grammar.java MatcherFactory.java 
	Searcher.properties SearcherFactory.java Thesaurus.java 
	Index.properties 
Removed Files:
	Parser.java ParserFactory.java SearchEngineFactory.java 
	AbstractSearchEngine.java SearchEngine.java Parser.properties 
	SearchEngine.properties 
Log Message:
Fixes for [JS-7] and [JS-6]
Lots of search work and re-factoring

--- NEW FILE: Searcher.properties ---

default=org.crosswire.jsword.book.search.parse.IndexSearcher

--- NEW FILE: Thesaurus.properties ---

default=org.crosswire.jsword.book.search.basic.NullThesaurus

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

import org.crosswire.jsword.book.BookException;
import org.crosswire.jsword.passage.Key;

/**
 * The central interface to all searching.
 * 
 * <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: Searcher.java,v 1.5 2004/09/29 22:21:23 joe Exp $
 */
public interface Searcher
{
    /**
     * Setup the index that this parser can use to do word level searches
     * @param index The Index to query for words
     */
    public void init(Index index);

    /**
     * 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;
}

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

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

/**
 * Factory method for creating a new Matcher.
 * 
 * <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: MatcherFactory.java,v 1.1 2004/09/29 22:21:23 joe Exp $
 */
public class MatcherFactory
{
    /**
     * Prevent Instansiation
     */
    private MatcherFactory()
    {
    }

    /**
     * Create a new Matcher.
     */
    public static Matcher createMatcher(Index index, Thesaurus thesaurus) throws InstantiationException
    {
        try
        {
            Class impl = ClassUtil.getImplementor(Matcher.class);
            Matcher matcher = (Matcher) impl.newInstance();
            matcher.init(index, thesaurus);

            return matcher;
        }
        catch (Exception ex)
        {
            log.error("createMatcher failed", ex); //$NON-NLS-1$
            throw new InstantiationException();
        }
    }

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

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

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

/**
 * Factory method for creating a new Thesaurus.
 * 
 * <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: ThesaurusFactory.java,v 1.1 2004/09/29 22:21:23 joe Exp $
 */
public class ThesaurusFactory
{
    /**
     * Prevent Instansiation
     */
    private ThesaurusFactory()
    {
    }

    /**
     * Create a new Thesaurus.
     */
    public static Thesaurus createThesaurus() throws InstantiationException
    {
        try
        {
            Class impl = ClassUtil.getImplementor(Thesaurus.class);
            Thesaurus thesaurus = (Thesaurus) impl.newInstance();

            return thesaurus;
        }
        catch (Exception ex)
        {
            log.error("createThesaurus failed", ex); //$NON-NLS-1$
            throw new InstantiationException();
        }
    }

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

--- SearchEngineFactory.java DELETED ---

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

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

/**
 * Factory method for creating a new Searcher.
 * 
 * <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: SearcherFactory.java,v 1.1 2004/09/29 22:21:23 joe Exp $
 */
public class SearcherFactory
{
    /**
     * Prevent Instansiation
     */
    private SearcherFactory()
    {
    }

    /**
     * Create a new Searcher.
     */
    public static Searcher createSearcher(Index index) throws InstantiationException
    {
        try
        {
            Class impl = ClassUtil.getImplementor(Searcher.class);
            Searcher parser = (Searcher) impl.newInstance();
            parser.init(index);

            return parser;
        }
        catch (Exception ex)
        {
            log.error("createSearcher failed", ex); //$NON-NLS-1$
            throw new InstantiationException();
        }
    }

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

--- SearchEngine.properties DELETED ---

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

import org.crosswire.common.util.StringUtil;

/**
 * A class representing various grammatical constructs (in English).
 *
 * <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: Grammar.java,v 1.1 2004/09/29 22:21:23 joe Exp $
 */
public class Grammar
{
    /**
     * Prevent Instansiation
     */
    private Grammar()
    {
    }

    /**
     * Strip of any parts of speech to leave a root word.
     * This class may not be the best place for this code, however I'm not
     * sure if we have a better place for it at the mo. Maybe it should be
     * in passage.PassageUtil?
     * @param word The word to strip
     * @return The root word
     */
    public static String getRoot(String word)
    {
        for (int i = 0; i < ENDINGS.length; i++)
        {
            if (word.endsWith(ENDINGS[i]))
            {
                // Make the assumption that we never have 2 ending on a word
                return word.substring(0, word.length() - ENDINGS[i].length());
            }
        }

        return word;
    }

    /**
     * Is this word one of those small words that can slaughter a DB
     * query. An empty string IS a small word.
     * @param word The word to test
     */
    public static boolean isSmallWord(String word)
    {
        word = word.trim();
        if (word.equals("")) //$NON-NLS-1$
        {
            return true;
        }

        for (int i = 0; i < WORD_FREQ.length; i++)
        {
            if (word.equalsIgnoreCase(WORD_FREQ[i]))
            {
                return true;
            }
        }

        return false;
    }

    /**
     * Is this word one of those small words that can slaughter a DB query
     */
    public static String[] stripSmallWords(String[] words)
    {
        // How many long words are there?
        int long_words = 0;
        for (int i = 0; i < words.length; i++)
        {
            if (!isSmallWord(words[i]))
            {
                long_words++;
            }
        }

        // Create the array with just the long words
        int count = 0;
        String[] retcode = new String[long_words];
        for (int i = 0; i < words.length; i++)
        {
            if (!isSmallWord(words[i]))
            {
                retcode[count++] = words[i];
            }
        }

        return retcode;
    }

    /**
     * Like PassageUtil.tokenize that leaves out the small words
     * @param original The sentance to split up
     * @param delims The word separators
     * @return The long words in the string
     */
    public static String[] tokenizeWithoutSmallWords(String original, String delims)
    {
        String[] words = StringUtil.split(original, delims);
        int small_words = 0;

        for (int i = 0; i < words.length; i++)
        {
            if (Grammar.isSmallWord(words[i]))
            {
                small_words++;
                words[i] = null;
            }
        }

        String [] retcode = new String[words.length - small_words];
        int count = 0;
        for (int i = 0; i < words.length; i++)
        {
            if (words[i] != null)
            {
                retcode[count++] = words[i];
            }
        }

        return retcode;
    }

    /**
     * The Endings a word can have.
     * These are matched in order so there is no point in having "s"
     * before "es" because the second will not be tried.
     */
    private static final String[] ENDINGS =
    {
        "es", //$NON-NLS-1$
        "'s", //$NON-NLS-1$
        "s", //$NON-NLS-1$
        "ing", //$NON-NLS-1$
        "ed", //$NON-NLS-1$
        "er", //$NON-NLS-1$
        "ly", //$NON-NLS-1$
    };

    /**
     * The one hundred most used words, and the instance count
     */
    private static final String[] WORD_FREQ =
    {
        // word     instance count (in AV & NIV)
        "the",      // 119135 //$NON-NLS-1$
        "and",      // 81244 //$NON-NLS-1$
        "of",       // 59417 //$NON-NLS-1$
        "to",       // 43624 //$NON-NLS-1$
        "in",       // 24233 //$NON-NLS-1$
        "he",       // 20088 //$NON-NLS-1$
        "that",     // 18672 //$NON-NLS-1$
        "i",        // 17605 //$NON-NLS-1$
        "a",        // 17439 //$NON-NLS-1$
        "for",      // 16780 //$NON-NLS-1$
        "you",      // 16324 //$NON-NLS-1$
        "his",      // 15438 //$NON-NLS-1$
//      "lord",     // 15319
        "is",       // 14304 //$NON-NLS-1$
        "will",     // 13981 //$NON-NLS-1$
        "they",     // 13942 //$NON-NLS-1$
        "not",      // 12507 //$NON-NLS-1$
        "with",     // 12125 //$NON-NLS-1$
        "him",      // 12058 //$NON-NLS-1$
        "it",       // 11834 //$NON-NLS-1$
        "be",       // 11638 //$NON-NLS-1$
        "them",     // 11608 //$NON-NLS-1$
        "shall",    // 10833 //$NON-NLS-1$
        "all",      // 10333 //$NON-NLS-1$
        "my",       // 9547 //$NON-NLS-1$
        "from",     // 9323 //$NON-NLS-1$
        "was",      // 8530 //$NON-NLS-1$
        "your",     // 8400 //$NON-NLS-1$
//      "god",      // 8381
        "have",     // 8322 //$NON-NLS-1$
        "me",       // 8102 //$NON-NLS-1$
        "but",      // 7991 //$NON-NLS-1$
        "their",    // 7638 //$NON-NLS-1$
        "as",       // 7521 //$NON-NLS-1$
        "who",      // 7425 //$NON-NLS-1$
        "said",     // 7198 //$NON-NLS-1$
        "are",      // 6981 //$NON-NLS-1$
        "on",       // 6914 //$NON-NLS-1$
        "this",     // 6558 //$NON-NLS-1$
        "when",     // 5667 //$NON-NLS-1$
        "thou",     // 5470 //$NON-NLS-1$
        "thy",      // 5469 //$NON-NLS-1$
        "by",       // 5434 //$NON-NLS-1$
        "were",     // 5192 //$NON-NLS-1$
        "had",      // 5109 //$NON-NLS-1$
        "then",     // 5105 //$NON-NLS-1$
        "out",      // 4778 //$NON-NLS-1$
//      "man",      // 4702
//      "son",      // 4701
        "so",       // 4689 //$NON-NLS-1$
//      "king",     // 4568
//      "israel",   // 4407
        "there",    // 4393 //$NON-NLS-1$
//      "people",   // 4355
        "which",    // 4253 //$NON-NLS-1$
        "do",       // 4032 //$NON-NLS-1$
        "one",      // 3998 //$NON-NLS-1$
        "ye",       // 3970 //$NON-NLS-1$
        "up",       // 3798 //$NON-NLS-1$
        "thee",     // 3780 //$NON-NLS-1$
        "at",       // 3767 //$NON-NLS-1$
        "we",       // 3725 //$NON-NLS-1$
        "her",      // 3583 //$NON-NLS-1$
        "what",     // 3545 //$NON-NLS-1$
        "men",      // 3482 //$NON-NLS-1$
        "come",     // 3404 //$NON-NLS-1$
        "if",       // 3380 //$NON-NLS-1$
        "into",     // 3284 //$NON-NLS-1$
        "came",     // 3283 //$NON-NLS-1$
//      "land",     // 3182
//      "day",      // 3168
        "upon",     // 3164 //$NON-NLS-1$
        "before",   // 3133 //$NON-NLS-1$
        "or",       // 3097 //$NON-NLS-1$
//      "house",    // 2997
        "us",       // 2886 //$NON-NLS-1$
        "because",  // 2879 //$NON-NLS-1$
        "go",       // 2869 //$NON-NLS-1$
//      "against",  // 2851
        "an",       // 2828 //$NON-NLS-1$
//      "no",       // 2711
        "went",     // 2597 //$NON-NLS-1$
        "also",     // 2586 //$NON-NLS-1$
        "now",      // 2571 //$NON-NLS-1$
        "let",      // 2548 //$NON-NLS-1$
//      "made",     // 2478
        "hath",     // 2450 //$NON-NLS-1$
        "may",      // 2418 //$NON-NLS-1$
        "has",      // 2406 //$NON-NLS-1$
        "our",      // 2361 //$NON-NLS-1$
        "these",    // 2356 //$NON-NLS-1$
//      "down",     // 2314
//      "hand",     // 2314
//      "jesus",    // 2255
//      "children", // 2231
//      "like",     // 2180
//      "over",     // 2091
        "o",        // 2090 //$NON-NLS-1$
//      "david",    // 2089
//      "father",   // 2065
        "am", //$NON-NLS-1$
    };
}

--- SearchEngine.java DELETED ---

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

import org.crosswire.common.util.ClassUtil;
import org.crosswire.common.util.Logger;
import org.crosswire.jsword.book.Book;

/**
 * Factory method for creating a new Searcher.
 * 
 * <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: IndexFactory.java,v 1.1 2004/09/29 22:21:23 joe Exp $
 */
public class IndexFactory
{
    /**
     * Prevent Instansiation
     */
    private IndexFactory()
    {
    }

    /**
     * Create a new Searcher.
     */
    public static Index getIndexForBook(Book book) throws InstantiationException
    {
        try
        {
            Class impl = ClassUtil.getImplementor(Index.class);
            Index index = (Index) impl.newInstance();
            index.init(book);

            return index;
        }
        catch (Exception ex)
        {
            log.error("createParser failed", ex); //$NON-NLS-1$
            throw new InstantiationException();
        }
    }

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

Index: Index.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/Index.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** Index.java	16 Aug 2004 22:08:43 -0000	1.7
--- Index.java	29 Sep 2004 22:21:23 -0000	1.8
***************
*** 1,6 ****
  package org.crosswire.jsword.book.search;
  
! import java.util.Collection;
  
  import org.crosswire.jsword.book.BookException;
  import org.crosswire.jsword.passage.Key;
--- 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;
***************
*** 34,45 ****
  {
      /**
!      * Return an array of words that are used by this Bible that start with the
!      * given string. For example calling:
!      * <code>getStartsWith("love")</code> will return something like:
!      * { "love", "loves", "lover", "lovely", ... }
!      * @param word The word to base your word array on
!      * @return An array of words starting with the base
       */
!     public Collection getStartsWith(String word) throws BookException;
  
      /**
--- 36,45 ----
  {
      /**
!      * 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;
  
      /**
***************
*** 62,64 ****
--- 62,85 ----
       */
      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;
  }

--- NEW FILE: IndexManager.java ---
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;

/**
 * .
 * 
 * <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: IndexManager.java,v 1.1 2004/09/29 22:21:23 joe Exp $
 */
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;
}

Index: Msg.properties
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/Msg.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Msg.properties	14 Jun 2004 05:27:22 -0000	1.1
--- Msg.properties	29 Sep 2004 22:21:23 -0000	1.2
***************
*** 6,10 ****
  # It should have no spaces or other punctuation (e.g. _, -, ', ...)
  
! SearchEngineFactory.SearchInit=Failed to initialise search engine.
! AbstractSearchEngine.TypeIndexGen=Generating index for this work. Search results will be more accurate when index is complete.
! AbstractSearchEngine.Indexing=Indexing Bible Data
--- 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

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

import org.crosswire.jsword.book.BookException;
import org.crosswire.jsword.passage.Key;

/**
 * .
 * 
 * <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: Matcher.java,v 1.1 2004/09/29 22:21:23 joe Exp $
 */
public interface Matcher
{
    /**
     * Setup the index that this parser can use to do word level searches
     * @param index The Index to query for words
     */
    public void init(Index index, Thesaurus thesaurus);

    /**
     * Generate a bestmatch search
     * @param sought The phrase to match
     * @param restriction What verses are we interested in looking in?
     * @see org.crosswire.jsword.book.Search#UNRESTRICTED
     * @return The matching verses
     */
    public Key bestMatch(String sought, Key restriction) throws BookException;
}

--- NEW FILE: Index.properties ---

default=org.crosswire.jsword.book.search.lucene.LuceneIndex
#default=org.crosswire.jsword.book.search.ser.SerIndex

lucene=org.crosswire.jsword.book.search.lucene.LuceneIndex
ser=org.crosswire.jsword.book.search.ser.SerIndex

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

import java.util.Collection;

import org.crosswire.jsword.book.BookException;

/**
 * A source of synonym data for a given word.
 * 
 * <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: Thesaurus.java,v 1.1 2004/09/29 22:21:23 joe Exp $
 */
public interface Thesaurus
{
    /**
     * Return an array of words that are used by this Bible that start with the
     * given string. For example calling:
     * <code>getStartsWith("love")</code> will return something like:
     * { "love", "loves", "lover", "lovely", ... }
     * @param word The word to base your word array on
     * @return An array of words starting with the base
     */
    public Collection getSynonyms(String word) throws BookException;
}

Index: Msg.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/Msg.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Msg.java	16 Aug 2004 22:08:43 -0000	1.8
--- Msg.java	29 Sep 2004 22:21:23 -0000	1.9
***************
*** 29,35 ****
  class Msg extends MsgBase
  {
!     static final Msg SEARCH_INIT = new Msg("SearchEngineFactory.SearchInit"); //$NON-NLS-1$
!     static final Msg TYPE_INDEXGEN = new Msg("AbstractSearchEngine.TypeIndexGen"); //$NON-NLS-1$
!     static final Msg INDEXING = new Msg("AbstractSearchEngine.Indexing"); //$NON-NLS-1$
  
      /**
--- 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$
  
      /**

--- NEW FILE: Matcher.properties ---

default=org.crosswire.jsword.book.search.index.IndexMatcher

--- Parser.java DELETED ---

--- Parser.properties DELETED ---

--- AbstractSearchEngine.java DELETED ---

--- ParserFactory.java DELETED ---



More information about the jsword-svn mailing list