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

jswordcvs at crosswire.org jswordcvs at crosswire.org
Sun Apr 24 18:22:25 MST 2005


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

Modified Files:
	Index.java Searcher.properties 
Added Files:
	SearchSyntax.properties SearchSyntax.java 
	SearchSyntaxFactory.java SearchType.java 
Log Message:
Re-implemented the search language to use lucene syntax with range and blur as extensions.

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

/**
 * A SearchSyntax allows for the decoration of strings in a way that is
 * appropriate for the 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 DM Smith [ dmsmith555 at hotmail dot com]
 * @version $Id: SearchSyntax.java,v 1.1 2005/04/25 01:22:23 dmsmith Exp $
 */
public interface SearchSyntax
{
    String decoratePhrase(String queryWords);

    String decorateAllWords(String queryWords);

    String decorateAnyWords(String queryWords);

    String decorateNotWords(String queryWords);

    String decorateStartWords(String queryWords);

    String decorateSpellWords(String queryWords);

    String decorateRange(String queryWords);
}

Index: Searcher.properties
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/Searcher.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Searcher.properties	29 Sep 2004 22:21:23 -0000	1.1
--- Searcher.properties	25 Apr 2005 01:22:23 -0000	1.2
***************
*** 1,2 ****
  
! default=org.crosswire.jsword.book.search.parse.IndexSearcher
--- 1,2 ----
  
! default=org.crosswire.jsword.book.search.lucene.IndexSearcher

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

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

/**
 * A Factory class for SearchSyntax.
 * 
 * <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: SearchSyntaxFactory.java,v 1.1 2005/04/25 01:22:23 dmsmith Exp $
 */
public class SearchSyntaxFactory
{
    /**
     * Prevent Instansiation
     */
    private SearchSyntaxFactory()
    {
    }

    /**
     * Create a new SearchSyntax.
     */
    public static SearchSyntax getSearchSyntax()
    {
        return instance;
    }

    /**
     * The singleton
     */
    private static SearchSyntax instance;

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

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

--- NEW FILE: SearchSyntax.properties ---
default=org.crosswire.jsword.book.search.lucene.ExtendedLuceneSyntax
Index: Index.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/search/Index.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** Index.java	1 Apr 2005 17:09:46 -0000	1.10
--- Index.java	25 Apr 2005 01:22:23 -0000	1.11
***************
*** 32,44 ****
  {
      /**
!      * 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
       * <b>MUST</b> be returned. Users of this index may use this functionality
       * to get empty KeyLists which they then use to aggregate other searches
       * done on this index.
!      * @param word The text to search for
       * @return The references to the word
       */
!     public Key findWord(String word) throws BookException;
  
      /**
--- 32,45 ----
  {
      /**
!      * Find the set of references that satisfy the query. Query is anything that
!      * the underlying index can handle.
!      * If the <code>query</code> being searched for is null then an empty Key
       * <b>MUST</b> be returned. Users of this index may use this functionality
       * to get empty KeyLists which they then use to aggregate other searches
       * done on this index.
!      * @param query The text to search for
       * @return The references to the word
       */
!     public Key find(String query) throws BookException;
  
      /**

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

import java.io.Serializable;

/**
 * An Enumeration of the possible types of Searches.
 * 
 * 
 * <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: SearchType.java,v 1.1 2005/04/25 01:22:23 dmsmith Exp $
 */
public abstract class SearchType implements Serializable
{
    /**
     * Find the words in the specified order.
     */
    public static final SearchType PHRASE = new SearchType("Phrase") //$NON-NLS-1$
    {
        /* (non-Javadoc)
         * @see org.crosswire.jsword.book.search.SearchType#decorate(java.lang.String)
         */
        public String decorate(String queryWords)
        {
            return searchSyntax.decoratePhrase(queryWords);
        }
        
        /**
         * Serialization ID
         */
        private static final long serialVersionUID = 4049921554181534256L;
    };

    /**
     * Find all the words regardless of position.
     */
    public static final SearchType ALL_WORDS = new SearchType("All") //$NON-NLS-1$
    {
        /* (non-Javadoc)
         * @see org.crosswire.jsword.book.search.SearchType#decorate(java.lang.String)
         */
        public String decorate(String queryWords)
        {
            return searchSyntax.decorateAllWords(queryWords);
        }

        /**
         * Serialization ID
         */
        private static final long serialVersionUID = 3256721771208980279L;
    };

    /**
     * Find any of these words
     */
    public static final SearchType ANY_WORDS = new SearchType("Any") //$NON-NLS-1$
    {
        /* (non-Javadoc)
         * @see org.crosswire.jsword.book.search.SearchType#decorate(java.lang.String)
         */
        public String decorate(String queryWords)
        {
            return searchSyntax.decorateAnyWords(queryWords);
        }

        /**
         * Serialization ID
         */
        private static final long serialVersionUID = 3257846580244853043L;
    };

    /**
     * Find verses not containing these words.
     * Note this may require being added after words being sought.
     */
    public static final SearchType NOT_WORDS = new SearchType("Not") //$NON-NLS-1$
    {
        /* (non-Javadoc)
         * @see org.crosswire.jsword.book.search.SearchType#decorate(java.lang.String)
         */
        public String decorate(String queryWords)
        {
            return searchSyntax.decorateNotWords(queryWords);
        }

        /**
         * Serialization ID
         */
        private static final long serialVersionUID = 4050480123318842929L;
    };

    /**
     * Find verses with words that start with the these beginnings.
     */
    public static final SearchType START_WORDS = new SearchType("Start") //$NON-NLS-1$
    {
        /* (non-Javadoc)
         * @see org.crosswire.jsword.book.search.SearchType#decorate(java.lang.String)
         */
        public String decorate(String queryWords)
        {
            return searchSyntax.decorateStartWords(queryWords);
        }

        /**
         * Serialization ID
         */
        private static final long serialVersionUID = 3544667378161168437L;
    };

    /**
     * Find verses with words spelled something like
     */
    public static final SearchType SPELL_WORDS = new SearchType("Spell") //$NON-NLS-1$
    {
        /* (non-Javadoc)
         * @see org.crosswire.jsword.book.search.SearchType#decorate(java.lang.String)
         */
        public String decorate(String queryWords)
        {
            return searchSyntax.decorateSpellWords(queryWords);
        }

        /**
         * Serialization ID
         */
        private static final long serialVersionUID = 3544387006957237044L;
    };

    /**
     * Find verses in this range
     */
    public static final SearchType RANGE = new SearchType("Range") //$NON-NLS-1$
    {
        /* (non-Javadoc)
         * @see org.crosswire.jsword.book.search.SearchType#decorate(java.lang.String)
         */
        public String decorate(String queryWords)
        {
            return searchSyntax.decorateRange(queryWords);
        }

        /**
         * Serialization ID
         */
        private static final long serialVersionUID = 3257288028421959989L;
    };

    /**
     * @param name The name of the BookType
     */
    protected SearchType(String name)
    {
        this.name = name;
    }

    /**
     * Decorate a string with the given type of decoration.
     */
    public abstract String decorate(String queryWords);

    /**
     * Lookup method to convert from a String
     */
    public static SearchType fromString(String name)
    {
        for (int i = 0; i < VALUES.length; i++)
        {
            SearchType o = VALUES[i];
            if (o.name.equalsIgnoreCase(name))
            {
                return o;
            }
        }
        throw new ClassCastException("Not a valid search type"); //$NON-NLS-1$
    }

    /**
     * Lookup method to convert from an integer
     */
    public static SearchType fromInteger(int i)
    {
        return VALUES[i];
    }

    /**
     * Prevent subclasses from overriding canonical identity based Object methods
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public final boolean equals(Object o)
    {
        return super.equals(o);
    }

    /**
     * Prevent subclasses from overriding canonical identity based Object methods
     * @see java.lang.Object#hashCode()
     */
    public final int hashCode()
    {
        return super.hashCode();
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    public String toString()
    {
        return name;
    }

    /**
     * The name of the BookType
     */
    private String name;

    protected static SearchSyntax searchSyntax = SearchSyntaxFactory.getSearchSyntax();

    // Support for serialization
    private static int nextObj;
    private final int obj = nextObj++;

    Object readResolve()
    {
        return VALUES[obj];
    }

    private static final SearchType[] VALUES =
    {
        PHRASE,
        ALL_WORDS,
        ANY_WORDS,
        NOT_WORDS,
        START_WORDS,
        SPELL_WORDS,
        RANGE
    };

    /**
     * Serialization ID
     */
    private static final long serialVersionUID = 3256721767014871089L;
}



More information about the jsword-svn mailing list