[jsword-svn] r967 - in trunk/jsword/src/main/java/org/crosswire/jsword/book/query: . basic

dmsmith at crosswire.org dmsmith at crosswire.org
Sun Jan 22 19:26:41 MST 2006


Author: dmsmith
Date: 2006-01-22 19:26:26 -0700 (Sun, 22 Jan 2006)
New Revision: 967

Modified:
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/BinaryQuery.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/Query.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/QueryBuilder.properties
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/QueryBuilderFactory.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/QueryDecorator.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AbstractBinaryQuery.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AbstractQuery.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AndNotQuery.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AndQuery.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/BaseQuery.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/BlurQuery.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/Msg.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/NullQuery.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/OrQuery.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/RangeQuery.java
Log:
Optimize search for empty query results.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/BinaryQuery.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/BinaryQuery.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/BinaryQuery.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -32,13 +32,13 @@
 {
 
     /**
-     * @return Returns the leftToken.
+     * @return Returns the leftQuery.
      */
-    Query getLeftToken();
+    Query getLeftQuery();
 
     /**
-     * @return Returns the rightToken.
+     * @return Returns the rightQuery.
      */
-    Query getRightToken();
+    Query getRightQuery();
 
 }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/Query.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/Query.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/Query.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -26,7 +26,7 @@
 import org.crosswire.jsword.passage.Key;
 
 /**
- * The search.Searcher uses a List of Tokens to calculate a search.
+ * The search.Searcher uses a Query to calculate a search result.
  * 
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/QueryBuilder.properties
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/QueryBuilder.properties	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/QueryBuilder.properties	2006-01-23 02:26:26 UTC (rev 967)
@@ -1,2 +1 @@
-
 default=org.crosswire.jsword.book.search.lucene.LuceneQueryBuilder

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/QueryBuilderFactory.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/QueryBuilderFactory.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/QueryBuilderFactory.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -25,7 +25,7 @@
 import org.crosswire.common.util.Logger;
 
 /**
- * A Factory class for QueryDecorator.
+ * A Factory class for QueryBuilder.
  * 
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/QueryDecorator.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/QueryDecorator.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/QueryDecorator.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -23,7 +23,7 @@
 
 /**
  * A QueryDecorator allows for the decoration of strings in a way that is
- * appropriate for the Searcher.
+ * appropriate for a Query.
  * 
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AbstractBinaryQuery.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AbstractBinaryQuery.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AbstractBinaryQuery.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -24,40 +24,42 @@
 import org.crosswire.jsword.book.query.Query;
 
 /**
- * A binary token has a left token and right token.
+ * A binary query has a left query and right query.
  * 
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.
- * @author DM Smith [ dmsmith555 at yahoo dot com]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public abstract class AbstractBinaryQuery implements Query
 {
-
     /**
+     * Create a query consisting of two queries.
      * 
+     * @param theLeftQuery
+     * @param theRightQuery
      */
-    public AbstractBinaryQuery(Query theLeftToken, Query theRightToken)
+    public AbstractBinaryQuery(Query theLeftQuery, Query theRightQuery)
     {
-        leftToken = theLeftToken;
-        rightToken = theRightToken;
+        leftQuery = theLeftQuery;
+        rightQuery = theRightQuery;
     }
 
     /**
-     * @return Returns the leftToken.
+     * @return Returns the leftQuery.
      */
-    public Query getLeftToken()
+    public Query getLeftQuery()
     {
-        return leftToken;
+        return leftQuery;
     }
 
     /**
-     * @return Returns the rightToken.
+     * @return Returns the rightQuery.
      */
-    public Query getRightToken()
+    public Query getRightQuery()
     {
-        return rightToken;
+        return rightQuery;
     }
 
-    private Query leftToken;
-    private Query rightToken;
+    private Query leftQuery;
+    private Query rightQuery;
 }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AbstractQuery.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AbstractQuery.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AbstractQuery.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -24,17 +24,19 @@
 import org.crosswire.jsword.book.query.Query;
 
 /**
- * A base token is the smallest unit of search that the index can perform.
+ * A base query is the smallest unit of search that the index can perform.
  * 
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.
- * @author DM Smith [ dmsmith555 at yahoo dot com]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public abstract class AbstractQuery implements Query
 {
 
     /**
+     * Construct a query from a string.
      * 
+     * @param theQuery
      */
     public AbstractQuery(String theQuery)
     {

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AndNotQuery.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AndNotQuery.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AndNotQuery.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -27,22 +27,25 @@
 import org.crosswire.jsword.passage.Key;
 
 /**
- * An "And Not" token specifies that a result needs to be in the left
- * but not in the right token.
+ * An "And Not" query specifies that a result needs to be in the left
+ * but not in the right query result.
  * 
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.
- * @author DM Smith [ dmsmith555 at yahoo dot com]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class AndNotQuery extends AbstractBinaryQuery
 {
 
     /**
+     * Create a query where the right query result is subtracted from the left query result.
      * 
+     * @param theLeftQuery
+     * @param theRightQuery
      */
-    public AndNotQuery(Query theLeftToken, Query theRightToken)
+    public AndNotQuery(Query theLeftQuery, Query theRightQuery)
     {
-        super(theLeftToken, theRightToken);
+        super(theLeftQuery, theRightQuery);
     }
 
     /* (non-Javadoc)
@@ -50,9 +53,22 @@
      */
     public Key find(Index index) throws BookException
     {
-        Key left = getLeftToken().find(index);
-        Key right = getRightToken().find(index);
+        Key left = getLeftQuery().find(index);
+
+        if (left.isEmpty())
+        {
+            return left;
+        }
+
+        Key right = getRightQuery().find(index);
+
+        if (right.isEmpty())
+        {
+            return left;
+        }
+
         left.removeAll(right);
+
         return left;
     }
 

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AndQuery.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AndQuery.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/AndQuery.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -27,30 +27,46 @@
 import org.crosswire.jsword.passage.Key;
 
 /**
- * An and token specifies that a result needs to be in both the left and the right token.
+ * An AND query specifies that a result needs to be in both the left and the right query results.
  * 
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.
- * @author DM Smith [ dmsmith555 at yahoo dot com]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class AndQuery extends AbstractBinaryQuery
 {
 
     /**
+     * Create a query where the result is the intersection of two queries.
      * 
+     * @param theLeftQuery
+     * @param theRightQuery
      */
-    public AndQuery(Query theLeftToken, Query theRightToken)
+    public AndQuery(Query theLeftQuery, Query theRightQuery)
     {
-        super(theLeftToken, theRightToken);
+        super(theLeftQuery, theRightQuery);
     }
     /* (non-Javadoc)
      * @see org.crosswire.jsword.book.search.parse.Query#find(org.crosswire.jsword.book.search.Index)
      */
     public Key find(Index index) throws BookException
     {
-        Key left = getLeftToken().find(index);
-        Key right = getRightToken().find(index);
+        Key left = getLeftQuery().find(index);
+
+        if (left.isEmpty())
+        {
+            return left;
+        }
+
+        Key right = getRightQuery().find(index);
+
+        if (right.isEmpty())
+        {
+            return right;
+        }
+
         left.retainAll(right);
+
         return left;
     }
 }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/BaseQuery.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/BaseQuery.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/BaseQuery.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -30,13 +30,15 @@
  * 
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.
- * @author DM Smith [ dmsmith555 at yahoo dot com]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class BaseQuery extends AbstractQuery
 {
 
     /**
+     * Construct a query from a string.
      * 
+     * @param theQuery
      */
     public BaseQuery(String theQuery)
     {

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/BlurQuery.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/BlurQuery.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/BlurQuery.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -28,21 +28,25 @@
 import org.crosswire.jsword.passage.RestrictionType;
 
 /**
- * A blur token specifies much to blur the results of the right token.
+ * A blur query specifies how much to blur the results of the right query
+ * before ANDing it to the left.
  * 
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.
- * @author DM Smith [ dmsmith555 at yahoo dot com]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class BlurQuery extends AbstractBinaryQuery
 {
-
     /**
+     * Create a query that specifies how much to blur the results of the right query
+     * before ANDing it to the left.
      * 
+     * @param theLeftQuery
+     * @param theRightQuery
      */
-    public BlurQuery(Query theLeftToken, Query theRightToken, int theFactor)
+    public BlurQuery(Query theLeftQuery, Query theRightQuery, int theFactor)
     {
-        super(theLeftToken, theRightToken);
+        super(theLeftQuery, theRightQuery);
         factor = theFactor;
     }
 
@@ -51,10 +55,24 @@
      */
     public Key find(Index index) throws BookException
     {
-        Key left = getLeftToken().find(index);
-        Key right = getRightToken().find(index);
+        Key left = getLeftQuery().find(index);
+
+        if (left.isEmpty())
+        {
+            return left;
+        }
+
+        Key right = getRightQuery().find(index);
+
+        if (right.isEmpty())
+        {
+            return right;
+        }
+
         right.blur(factor, RestrictionType.getDefaultBlurRestriction());
+
         left.retainAll(right);
+
         return left;
     }
 

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/Msg.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/Msg.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/Msg.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -28,7 +28,7 @@
  * 
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.
- * @author Joe Walker [joe at eireneh dot com]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 final class Msg extends MsgBase
 {

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/NullQuery.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/NullQuery.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/NullQuery.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -31,7 +31,7 @@
  * 
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.
- * @author DM Smith [ dmsmith555 at yahoo dot com]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
  */
 public class NullQuery implements Query
 {

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/OrQuery.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/OrQuery.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/OrQuery.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -27,7 +27,7 @@
 import org.crosswire.jsword.passage.Key;
 
 /**
- * An or token specifies that a result needs to be in either the left and the right token.
+ * An OR query specifies that a result is the union of the left and the right query results.
  * 
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.
@@ -39,9 +39,9 @@
     /**
      * 
      */
-    public OrQuery(Query theLeftToken, Query theRightToken)
+    public OrQuery(Query theLeftQuery, Query theRightQuery)
     {
-        super(theLeftToken, theRightToken);
+        super(theLeftQuery, theRightQuery);
     }
 
     /* (non-Javadoc)
@@ -49,9 +49,21 @@
      */
     public Key find(Index index) throws BookException
     {
-        Key left = getLeftToken().find(index);
-        Key right = getRightToken().find(index);
+        Key left = getLeftQuery().find(index);
+        Key right = getRightQuery().find(index);
+
+        if (left.isEmpty())
+        {
+            return right;
+        }
+
+        if (right.isEmpty())
+        {
+            return left;
+        }
+
         left.addAll(right);
+
         return left;
     }
 }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/RangeQuery.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/RangeQuery.java	2006-01-23 01:35:36 UTC (rev 966)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/query/basic/RangeQuery.java	2006-01-23 02:26:26 UTC (rev 967)
@@ -38,7 +38,9 @@
 {
 
     /**
+     * Construct a query from the range specification.
      * 
+     * @param theRange
      */
     public RangeQuery(String theRange)
     {



More information about the jsword-svn mailing list