Revision: 16342
          http://gate.svn.sourceforge.net/gate/?rev=16342&view=rev
Author:   valyt
Date:     2012-11-27 16:40:21 +0000 (Tue, 27 Nov 2012)
Log Message:
-----------
If counts are available, then they provided array will be non-null. No need for 
an extra isCountsEnabled() method.

Extracted the implementation of the OR TermsQuery operator into a static method 
which can be reused by the FederatedIndex.postTermsQuery() implementation.

Modified Paths:
--------------
    
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractWrapperTermsQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/AndTermsQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/OrTermsQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsQuery.java

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractWrapperTermsQuery.java
===================================================================
--- 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractWrapperTermsQuery.java
   2012-11-27 16:22:45 UTC (rev 16341)
+++ 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractWrapperTermsQuery.java
   2012-11-27 16:40:21 UTC (rev 16342)
@@ -35,14 +35,6 @@
     super(limit);
     this.wrappedQuery = wrappedQuery;
   }
-
-  /* (non-Javadoc)
-   * @see gate.mimir.search.terms.TermsQuery#isCountsEnabled()
-   */
-  @Override
-  public boolean isCountsEnabled() {
-    return wrappedQuery != null && wrappedQuery.isCountsEnabled();
-  }
   
   /**
    * The wrapped wrappedQuery

Modified: mimir/trunk/mimir-core/src/gate/mimir/search/terms/AndTermsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/AndTermsQuery.java       
2012-11-27 16:22:45 UTC (rev 16341)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/AndTermsQuery.java       
2012-11-27 16:40:21 UTC (rev 16342)
@@ -42,12 +42,6 @@
   protected TermsQuery[] subQueries;
   
   /**
-   * A boolean flag that is set to true if all sub-queries support counts, 
which
-   * allows this query to also provide them.
-   */
-  protected boolean countsAvailable;
-  
-  /**
    * Constructs a new AND term query.
    * 
    * @param stringsEnabled should terms strings be returned.
@@ -60,13 +54,6 @@
   public AndTermsQuery(int limit, TermsQuery... subQueries) {
     super(limit);
     this.subQueries = subQueries;
-    countsAvailable = true;
-    for(TermsQuery aQuery : subQueries) {
-      if(!aQuery.isCountsEnabled()) {
-        countsAvailable = false;
-        break;
-      }
-    }
   }
 
   /* (non-Javadoc)
@@ -76,14 +63,17 @@
   public TermsResultSet execute(QueryEngine engine) throws IOException {
     final TermsResultSet[] resSets = new TermsResultSet[subQueries.length];
     boolean lengthsAvailable = false;
+    boolean countsAvailable = true;
     for(int i = 0; i < subQueries.length; i++) {
       resSets[i] = subQueries[i].execute(engine);
       if(resSets[i].termStrings.length == 0) return TermsResultSet.EMPTY;
       // this implementation requires that all sub-queries return terms in a 
       // consistent order, so we sort them lexicographically by termString
       sortTermsResultSetByTermString(resSets[i]);
-      // at least one sub-query must provide lengths
+      // at least one sub-query must provide lengths, for us to be able to
       if(resSets[i].termLengths != null) lengthsAvailable = true;
+      // all sub-queries must provide counts, for us to be able to
+      if(resSets[i].termCounts == null) countsAvailable = false;
     }
     // optimisation: sort sub-runners by increasing sizes
     Arrays.quickSort(0, resSets.length, new IntComparator() {
@@ -180,12 +170,4 @@
         lengthsAvailable? termLengths.toIntArray() : null,
         countsAvailable ? termCounts.toIntArray() : null);
   }
-
-  /* (non-Javadoc)
-   * @see gate.mimir.search.terms.TermsQuery#isCountsEnabled()
-   */
-  @Override
-  public boolean isCountsEnabled() {
-    return countsAvailable;
-  }
 }

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java
===================================================================
--- 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java    
    2012-11-27 16:22:45 UTC (rev 16341)
+++ 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java    
    2012-11-27 16:40:21 UTC (rev 16342)
@@ -81,16 +81,5 @@
       return TermsResultSet.EMPTY;
     }
   }
-
-  /**
-   * This type of terms query does not use the index, all the results are 
-   * obtained from the semantic annotation helpers. Because of this, counts are
-   * not available: this method always returns <code>false</code>.
-   */
-  @Override
-  public boolean isCountsEnabled() {
-    return false;
-  }
   
-  
 }

Modified: mimir/trunk/mimir-core/src/gate/mimir/search/terms/OrTermsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/OrTermsQuery.java        
2012-11-27 16:22:45 UTC (rev 16341)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/OrTermsQuery.java        
2012-11-27 16:40:21 UTC (rev 16342)
@@ -38,9 +38,6 @@
    */
   protected TermsQuery[] subQueries;
 
-  protected boolean countsAvailable;
-  
-  
   /**
    * Constructs a new OR terms query.
    * @param stringsEnabled should terms strings be returned.
@@ -53,13 +50,6 @@
   public OrTermsQuery(int limit, TermsQuery... subQueries) {
     super(limit);
     this.subQueries = subQueries;
-    countsAvailable = true;
-    for(TermsQuery aQuery : subQueries) {
-      if(!aQuery.isCountsEnabled()) {
-        countsAvailable = false;
-        break;
-      }
-    }    
   }
   
   /* (non-Javadoc)
@@ -68,13 +58,27 @@
   @Override
   public TermsResultSet execute(QueryEngine engine) throws IOException {
     TermsResultSet[] resSets = new TermsResultSet[subQueries.length];
+    for(int i = 0; i < subQueries.length; i++) {
+      resSets[i] = subQueries[i].execute(engine);
+    }
+    return orResultsSets(resSets);
+  }
+  
+  /**
+   * Given a set of {@link TermsResultSet} values, this method combines them
+   * into a single {@link TermsResultSet} representing the disjunction of all
+   * the provided results sets. 
+   * @param resSets 
+   * @return
+   */
+  public static TermsResultSet orResultsSets(TermsResultSet... resSets) {
     String[] currentTerm = new String[resSets.length];
     ObjectHeapSemiIndirectPriorityQueue<String> queue = 
         new ObjectHeapSemiIndirectPriorityQueue<String>(currentTerm);
     int[] termIndex = new int[resSets.length];
     boolean lengthsAvailable = true;
-    for(int i = 0; i < subQueries.length; i++) {
-      resSets[i] = subQueries[i].execute(engine);
+    boolean countsAvailable = true;
+    for(int i = 0; i < resSets.length; i++) {
       // this implementation requires that all sub-queries return terms in a 
       // consistent order, so we sort them lexicographically by termString
       sortTermsResultSetByTermString(resSets[i]);
@@ -86,6 +90,7 @@
       // we need *all* sub-queries to provide lengths, because we don't know
       // which one will provide any of the results.
       if(resSets[i].termLengths == null) lengthsAvailable = false;
+      if(resSets[i].termCounts == null) countsAvailable = false;
     }
     
     // prepare local data
@@ -128,12 +133,4 @@
         lengthsAvailable ? termLengths.toIntArray() : null,
         countsAvailable ? termCounts.toIntArray() : null);
   }
-  
-  /* (non-Javadoc)
-   * @see gate.mimir.search.terms.TermsQuery#isCountsEnabled()
-   */
-  @Override
-  public boolean isCountsEnabled() {
-    return countsAvailable;
-  }
 }

Modified: mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsQuery.java  
2012-11-27 16:22:45 UTC (rev 16341)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsQuery.java  
2012-11-27 16:40:21 UTC (rev 16342)
@@ -39,10 +39,4 @@
    */
   public TermsResultSet execute(QueryEngine engine) throws IOException;
   
-  /**
-   * Does this terms query return term counts?
-   * @return
-   */
-  public boolean isCountsEnabled();
-  
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to