Revision: 14785
          http://gate.svn.sourceforge.net/gate/?rev=14785&view=rev
Author:   valyt
Date:     2011-12-16 12:07:32 +0000 (Fri, 16 Dec 2011)
Log Message:
-----------
Bugfix: we are looking for the MAX score, not MIN

Optimisation: made the federated runner more 'fair': sub-runners are rotated 
round-robin when looking for the next best score. This means that documents are 
consumed in turn from all sub runners when scores are equal (e.g. if no scoring 
is performed). Previously all documents from one sub runner were retrieved 
before moving to the next runner.

Optimisation: fail faster when running out of documents.

Modified Paths:
--------------
    mimir/trunk/mimir-core/src/gate/mimir/search/FederatedQueryRunner.java

Modified: mimir/trunk/mimir-core/src/gate/mimir/search/FederatedQueryRunner.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/FederatedQueryRunner.java      
2011-12-16 10:47:42 UTC (rev 14784)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/FederatedQueryRunner.java      
2011-12-16 12:07:32 UTC (rev 14785)
@@ -53,6 +53,12 @@
    */
   protected IntList rank2runnerIndex;
   
+  /**
+   * Which of the sub-runners has provided the previous document. This is an 
+   * instance field so that we can rotate the sub-runners (when the scores are 
+   * equal)  
+   */
+  private int bestSubRunnerIndex = -1;
   
   /**
    * For each result document rank, this list supplies the rank of the document
@@ -121,22 +127,43 @@
     if(rank < rank2runnerIndex.size()) {
       return;
     }
-    
     for(int nextRank = rank2runnerIndex.size(); nextRank <= rank; nextRank++) {
-      int subRunnerWithMin = 0;
-      for(int i = 1; i < subRunners.length; i++) {
-        if((nextSubRunnerRank[i] >= 0) &&
-            (subRunners[i].getDocumentScore(nextSubRunnerRank[i]) <
-            
subRunners[subRunnerWithMin].getDocumentScore(nextSubRunnerRank[subRunnerWithMin])))
 {
-          subRunnerWithMin = i;
+      boolean allOut = true;
+      // start with the runner next the previously chosen one
+      bestSubRunnerIndex = (bestSubRunnerIndex + 1) % subRunners.length;
+      double maxScore = Double.NEGATIVE_INFINITY;
+      if(nextSubRunnerRank[bestSubRunnerIndex] >= 0) {
+        maxScore = subRunners[bestSubRunnerIndex].getDocumentScore(
+            nextSubRunnerRank[bestSubRunnerIndex]);
+        allOut = false;
+      }
+      // now check all remaining runners, in round-robin fashion
+      final int from = bestSubRunnerIndex + 1;
+      final int to = bestSubRunnerIndex + subRunners.length;
+      for(int bigI = from; bigI < to; bigI++) {
+        int i = bigI % subRunners.length;
+        if(nextSubRunnerRank[i] >= 0) {
+          allOut = false;
+          if(subRunners[i].getDocumentScore(nextSubRunnerRank[i]) > maxScore) {
+            bestSubRunnerIndex = i;
+            maxScore = subRunners[i].getDocumentScore(nextSubRunnerRank[i]);   
       
+          }          
         }
       }
+      if(allOut) {
+        // we ran out of docs
+        throw new IndexOutOfBoundsException("Requested rank was " + rank + 
+          " but ran out of documents at " + nextRank + "!");
+      }
       // consume the next doc from subRunnerWithMin
-      rank2runnerIndex.add(subRunnerWithMin);
-      rank2subRank.add(nextSubRunnerRank[subRunnerWithMin]++);
-      if(nextSubRunnerRank[subRunnerWithMin] >= 
subRunners[subRunnerWithMin].getDocumentsCount()) {
+      rank2runnerIndex.add(bestSubRunnerIndex);
+      rank2subRank.add(nextSubRunnerRank[bestSubRunnerIndex]);
+      if(nextSubRunnerRank[bestSubRunnerIndex] < 
+          subRunners[bestSubRunnerIndex].getDocumentsCount() -1) {
+        nextSubRunnerRank[bestSubRunnerIndex]++;
+      } else {
         // this runner has run out of documents
-        nextSubRunnerRank[subRunnerWithMin] = -1;
+        nextSubRunnerRank[bestSubRunnerIndex] = -1;
       }
     }
   }

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


------------------------------------------------------------------------------
Learn Windows Azure Live!  Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for 
developers. It will provide a great way to learn Windows Azure and what it 
provides. You can attend the event by watching it streamed LIVE online.  
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to