Revision: 14715
          http://gate.svn.sourceforge.net/gate/?rev=14715&view=rev
Author:   valyt
Date:     2011-12-09 16:35:22 +0000 (Fri, 09 Dec 2011)
Log Message:
-----------
Implemented remote side of RemoteQueryRunner.

Modified Paths:
--------------
    
mimir/trunk/mimir-web/grails-app/controllers/gate/mimir/web/SearchController.groovy
    mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/FederatedIndex.groovy
    mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/Index.groovy
    mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/LocalIndex.groovy
    mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/RemoteIndex.groovy
    
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/FederatedIndexService.groovy
    
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/LocalIndexService.groovy

Modified: 
mimir/trunk/mimir-web/grails-app/controllers/gate/mimir/web/SearchController.groovy
===================================================================
--- 
mimir/trunk/mimir-web/grails-app/controllers/gate/mimir/web/SearchController.groovy
 2011-12-09 16:34:10 UTC (rev 14714)
+++ 
mimir/trunk/mimir-web/grails-app/controllers/gate/mimir/web/SearchController.groovy
 2011-12-09 16:35:22 UTC (rev 14715)
@@ -18,6 +18,7 @@
 import gate.mimir.web.Index;
 import gate.mimir.web.SearchService;
 import groovy.xml.StreamingMarkupBuilder;
+import gate.mimir.index.mg4j.zipcollection.DocumentData;
 import gate.mimir.search.query.Binding;
 
 import java.io.ObjectOutputStream;
@@ -541,309 +542,230 @@
    */
   def postQueryBin = {
     def p = params["request"] ?: params
-    
     //get the query string
     String queryString = p["queryString"]
-    try{
+    try {
       String runnerId = searchService.postQuery(request.theIndex, queryString)
       //save the query ID in the session, so we can close it on expiry
       getSessionQueryIDs().add(runnerId)
       new ObjectOutputStream (response.outputStream).withStream {stream -> 
         stream.writeObject(runnerId)
       }
-    }catch(Exception e){
+    } catch(Exception e) {
       log.error("Exception posting query", e)
       response.sendError(HttpServletResponse.SC_BAD_REQUEST, 
       "Problem posting query: \"" + e.getMessage() + "\"")
     }
   }
-  
-  
+
   /**
-   * Binary version of hits call
+   * Gets the number of result documents found so far. After the search 
+   * completes, the result returned by this call is identical to that of 
+   * {@link #documentsCountBin}. The result is returned as a binary 
+   * representation of an int value.
    */
-  def hitsBin = {
+  def documentsCurrentCountBin = {
     def p = params["request"] ?: params
     //get the query ID
     String queryId = p["queryId"]
     QueryRunner runner = searchService.getQueryRunner(queryId);
-    if(runner){
-      //get the parameters
-      def startIndexParam = p["startIndex"]
-      if(startIndexParam){
-        def hitCountParam = p["count"]
-        if(hitCountParam){
-          try{
-            int startIndex = startIndexParam.toInteger()
-            int hitCount = hitCountParam.toInteger()
-            //we have all required parameters
-            List<Binding> hits = new 
ArrayList<Binding>(runner.getHits(startIndex, hitCount))
-            new ObjectOutputStream (response.outputStream).withStream {stream 
-> 
-              stream.writeObject(hits)
-            }
-          }catch(Exception e){
-            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 
-            "Error while obtaining the hits: \"" + e.getMessage() + "\"!")
-          }
-        }else{
-          response.sendError(HttpServletResponse.SC_BAD_REQUEST, 
-              "No value provided for parameter maxHits!")
+    if(runner) {
+      try {
+        // we have all required parameters
+        int docCount = runner.getDocumentsCurrentCount()
+        new ObjectOutputStream (response.outputStream).withStream {stream ->
+          stream.writeInt(docCount)
         }
-      }else{
-        response.sendError(HttpServletResponse.SC_BAD_REQUEST, 
-            "No value provided for parameter firstHit!")
+      } catch(Exception e) {
+        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+            "Error while obtaining the documents count: \"" + e.getMessage() + 
"\"!")
       }
-    } else{
-      response.sendError(HttpServletResponse.SC_NOT_FOUND, 
-          "Query ID ${queryId} not known!")
-    }
-  }
-  
-  /**
-  * Binary version of hits call
-  */
-  def hitsForDocumentBin = {
-    def p = params["request"] ?: params
-    //get the query ID
-    String queryId = p["queryId"]
-    QueryRunner runner = searchService.getQueryRunner(queryId);
-    if(runner){
-      //get the parameters
-      def documentIdParam = p["documentId"]
-      if(documentIdParam){
-        try{
-          int documentId = documentIdParam.toInteger()
-          //we have all required parameters
-          List<Binding> hits = new 
ArrayList<Binding>(runner.getHitsForDocument(documentId))
-          new ObjectOutputStream (response.outputStream).withStream {stream ->
-            stream.writeObject(hits)
-          }
-        }catch(Exception e){
-          response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
-          "Error while obtaining the hits: \"" + e.getMessage() + "\"!")
-        }
-        
-      }else{
-        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
-            "No value provided for parameter documentId!")
-      }
-    } else{
+    } else {
       response.sendError(HttpServletResponse.SC_NOT_FOUND,
           "Query ID ${queryId} not known!")
-    }
+      }
   }
-  
+ 
   /**
-   * Gets the number of available hits as a binary representation of an int 
+   * Gets the number of result documents found.  Returns <code>-1</code> if the
+   * search has not yet completed, the total number of result document 
+   * otherwise. The result is returned as a binary representation of an int 
    * value.
    */
-  def hitCountBin = {
+  def documentsCountBin = {
     def p = params["request"] ?: params
     //get the query ID
     String queryId = p["queryId"]
     QueryRunner runner = searchService.getQueryRunner(queryId);
-    if(runner){
-      try{
-        //we have all required parameters
-        int hitCount = runner.getHitsCount()
-        new ObjectOutputStream (response.outputStream).withStream {stream -> 
-          stream.writeInt(hitCount)
-        }
-      }catch(Exception e){
-        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 
-            "Error while obtaining the hits count: \"" + e.getMessage() + 
"\"!")
-      }
-    } else{
-      response.sendError(HttpServletResponse.SC_NOT_FOUND, 
-          "Query ID ${queryId} not known!")
-    }
-  }
-  
-  /**
-   * Gets the number of distinct documents in the current hit list as a binary
-   * representation of an int value.
-   */
-  def docCountBin = {
-    def p = params["request"] ?: params
-    //get the query ID
-    String queryId = p["queryId"]
-    QueryRunner runner = searchService.getQueryRunner(queryId);
-    if(runner){
-      try{
-        //we have all required parameters
+    if(runner) {
+      try {
+        // we have all required parameters
         int docCount = runner.getDocumentsCount()
-        new ObjectOutputStream (response.outputStream).withStream {stream -> 
+        new ObjectOutputStream (response.outputStream).withStream {stream ->
           stream.writeInt(docCount)
         }
-      }catch(Exception e){
-        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 
+      } catch(Exception e) {
+        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
             "Error while obtaining the documents count: \"" + e.getMessage() + 
"\"!")
       }
-    } else{
-      response.sendError(HttpServletResponse.SC_NOT_FOUND, 
+    } else {
+      response.sendError(HttpServletResponse.SC_NOT_FOUND,
           "Query ID ${queryId} not known!")
     }
   }
   
   /**
-   * Gets the document statistics for a set of documents. The returned value is
-   * the binary representation of a two-rows int array where:
-   * <ul>
-   *   <li>result[0][i] is the ID for the i<sup>th</sup> document</li>
-   *   <li>result[1][i] is the hits count for the i<sup>th</sup> document</li>
-   * </ul>
+   * Gets the ID of a document as a serialised String value.
    */
-  def docStatsBin = {
+  def documentIdBin = {
     def p = params["request"] ?: params
     //get the query ID
     String queryId = p["queryId"]
     QueryRunner runner = searchService.getQueryRunner(queryId);
     if(runner){
-      //get the parameters
-      def startIndexParam = p["startIndex"]
-      if(startIndexParam){
-        def docCountParam = p["count"]
-        if(docCountParam){
-          try{
-            //we have all required parameters
-            int startIndex = startIndexParam.toInteger()
-            int docCount = docCountParam.toInteger()
-            int[][] docStats = new int[docCount][2];
-            for(int i = 0; i < docCount; i++){
-              docStats[i][0] = runner.getDocumentID(i + startIndex)
-              docStats[i][1] = runner.getDocumentHitsCount(i + startIndex)
-            }
-            new ObjectOutputStream (response.outputStream).withStream {stream 
-> 
-              stream.writeObject(docStats)
-            }
-          }catch(Exception e){
-            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 
-                "Error while obtaining the document statistics: \"" + 
-                e.getMessage() + "\"!")
+      //get the parameters: int documentRank
+      def documentRankParam = p["documentRank"]
+      if (documentRankParam) {
+        try {
+          //we have all required parameters
+          int documentRank = documentRankParam.toInteger()
+          int docId = runner.getDocumentID(documentRank)
+          new ObjectOutputStream (response.outputStream).withStream {stream ->
+            stream.writeObject(Integer.toString(docId))
           }
-        }else{
-          response.sendError(HttpServletResponse.SC_BAD_REQUEST, 
-          "No value provided for parameter maxHits!")
+        } catch(Exception e){
+          response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+              "Error while obtaining the document ID: \"" +
+              e.getMessage() + "\"!")
         }
-      }else{
-        response.sendError(HttpServletResponse.SC_BAD_REQUEST, 
-        "No value provided for parameter firstHit!")
+      } else {
+        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+            "No value provided for parameter documentRank!")
       }
-    } else{
-      response.sendError(HttpServletResponse.SC_NOT_FOUND, 
-      "Query ID ${queryId} not known!")
-    }
-  }
-  
-  
-  /**
-   * Sets the maximum number of hits desired in one search stage.
-   */
-  def setStageMaxHitsBin = {
-    def p = params["request"] ?: params
-    //get the query ID
-    String queryId = p["queryId"]
-    QueryRunner runner = searchService.getQueryRunner(queryId);
-    if(runner){
-      String maxHits = p["maxHits"]
-      if(maxHits){
-        //we have all required parameters
-        try{
-          runner.setStageMaxHits(maxHits as int)
-          render(text:"OK", contentType:"text/plain", encoding:"UTF-8")
-        }catch(Exception e){
-          response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 
-              "Error while configuring the query runner: \"" + 
-              e.getMessage() + "\"!")
-        }        
-      }
-    } else{
-      response.sendError(HttpServletResponse.SC_NOT_FOUND, 
+    } else {
+      response.sendError(HttpServletResponse.SC_NOT_FOUND,
           "Query ID ${queryId} not known!")
     }
   }
   
-  
   /**
-   * Sets the maximum number of hits desired in one search stage.
+   * Retrieves the hits within a given result document.
    */
-  def setStageTimeoutBin = {
+  def documentHitsBin = {
     def p = params["request"] ?: params
     //get the query ID
     String queryId = p["queryId"]
     QueryRunner runner = searchService.getQueryRunner(queryId);
     if(runner){
-      String timeout = p["timeout"]
-      if(timeout){
-        //we have all required parameters
+      //get the parameters
+      def documentRankParam = p["documentRank"]
+      if(documentRankParam){
         try{
-          runner.setStageTimeout(timeout as int)
-          render(text:"OK", contentType:"text/plain", encoding:"UTF-8")
+          int documentRank = documentRankParam.toInteger()
+          //we have all required parameters
+          List<Binding> hits = runner.getDocumentHits(documentRank)
+          new ObjectOutputStream (response.outputStream).withStream {stream ->
+            stream.writeObject(hits)
+          }
         }catch(Exception e){
-          response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 
-              "Error while configuring the query runner: \"" + 
-              e.getMessage() + "\"!")
-        }        
+          response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+          "Error while obtaining the hits: \"" + e.getMessage() + "\"!")
+        }
+        
+      }else{
+        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+            "No value provided for parameter documentRank!")
       }
     } else{
-      response.sendError(HttpServletResponse.SC_NOT_FOUND, 
+      response.sendError(HttpServletResponse.SC_NOT_FOUND,
           "Query ID ${queryId} not known!")
     }
   }
   
   /**
-   * Gets the active flag, as a serialise boolean value.
-   */
-  def isActiveBin = {
+  * Retrieves all the document scores
+  */
+  def documentsScoresBin = {
     def p = params["request"] ?: params
     //get the query ID
     String queryId = p["queryId"]
     QueryRunner runner = searchService.getQueryRunner(queryId);
     if(runner){
       try{
-        //we have all required parameters
-        boolean active = runner.isActive()
-        new ObjectOutputStream (response.outputStream).withStream {stream -> 
-          stream.writeBoolean(active)
+       int docCount = runner.getDocumentsCount()
+        double[] scores = new double[docCount]
+        for(int i = 0; i < docCount; i++) {
+          docCount[i] = runner.getDocumentScore(i)
         }
+        new ObjectOutputStream (response.outputStream).withStream {stream ->
+         stream.writeObject(scores)
+        }
       }catch(Exception e){
-        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 
-            "Error while obtaining the query state: \"" + 
-            e.getMessage() + "\"!")
+        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+        "Error while obtaining the scores: \"" + e.getMessage() + "\"!")
       }
     } else{
-      response.sendError(HttpServletResponse.SC_NOT_FOUND, 
+      response.sendError(HttpServletResponse.SC_NOT_FOUND,
           "Query ID ${queryId} not known!")
     }
   }
   
+  //
+  //  protected static final String ACTION_DOC_DATA_BIN = "documentDataBin";
   /**
-   * Gets the complete flag, as a serialise boolean value.
+   * Gets the document data (title, URI, text) for a given document. The 
+   * requested document should be specified by providing paramter values for
+   * either documentId or both queryId and documentRank. The result is a 
+   * serialised {@link DocumentData} value.
    */
-  def isCompleteBin = {
+  def documentDataBin = {
     def p = params["request"] ?: params
-    //get the query ID
-    String queryId = p["queryId"]
-    QueryRunner runner = searchService.getQueryRunner(queryId);
-    if(runner){
-      try{
-        //we have all required parameters
-        boolean complete = runner.isComplete()
-        new ObjectOutputStream (response.outputStream).withStream {stream -> 
-          stream.writeBoolean(complete)
+    Index index = request.theIndex
+    // get the document ID
+    int documentId = -1;
+    String documentIdParam = p["documentId"]
+    if(documentIdParam) {
+      documentId = documentIdParam.toInteger()
+    } else {
+      // we didn't get the explicit ID; try queryId and rank instead
+      String queryId = p["queryId"]
+      if(queryId) {
+        QueryRunner runner = searchService.getQueryRunner(queryId);
+        if(runner){
+          String documentRankParam = p["documentRank"]
+          if (documentRankParam) {
+            int documentRank = documentRankParam.toInteger()
+            int docId = runner.getDocumentID(documentRank)
+          } else {
+            response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+              "Neither documentId nor documentRank parameters were provided!")
+          }
+        } else {
+          response.sendError(HttpServletResponse.SC_NOT_FOUND,
+            "Query ID ${queryId} not known!")
         }
-      }catch(Exception e){
-        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 
-            "Error while obtaining the query state: \"" + 
+      } else {
+        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+            "Neither documentId nor queryId parameters were provided!")
+      }
+    }
+    // by this point we need to have the documentID
+    if(documentId >= 0) {
+      try {
+        new ObjectOutputStream (response.outputStream).withStream {stream ->
+          stream.writeObject(index.getDocumentData(documentId))
+        }
+      } catch(Exception e) {
+        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+            "Error while obtaining the document ID: \"" +
             e.getMessage() + "\"!")
-      }        
-    } else{
-      response.sendError(HttpServletResponse.SC_NOT_FOUND, 
-          "Query ID ${queryId} not known!")
+      }
+    } else {
+      response.sendError(HttpServletResponse.SC_BAD_REQUEST,
+        "Could not find a valid documentId with the provided parameters!")
     }
   }
   
-  
   /**
    * Calls the render document method on the corresponding query runner, piping
    * the output directly to the response stream.
@@ -856,14 +778,14 @@
     QueryRunner runner = searchService.getQueryRunner(queryId);
     if(runner){
       //get the parameters
-      def documentIdParam = p["documentId"]
-      if(documentIdParam){
+      def documentRankParam = p["documentRank"]
+      if(documentRankParam){
         try{
           //we have all the required parameters
-          int documentId = documentIdParam.toInteger()
+          int documentRank = documentRankParam.toInteger()
           response.characterEncoding = "UTF-8"
           response.writer.withWriter{ writer ->
-            runner.renderDocument(documentId, writer)
+            runner.renderDocument(documentRank, writer)
           }
         }catch(Exception e){
           response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 
@@ -880,176 +802,7 @@
     }
   }
   
-  
   /**
-   * Gets [a segment of] the document text. The returned value is a 
-   * Java-serialised array of String arrays. Each element in the main array 
-   * corresponds to a token, and consists of an array of two strings: the 
token 
-   * string and the token non-string (i.e. all the whitespace that follows the 
-   * token).  
-   */
-  def docTextBin = {
-    def p = params["request"] ?: params
-    //get the query ID
-    String queryId = p["queryId"]
-    QueryRunner runner = searchService.getQueryRunner(queryId);
-    if(runner){
-      //get the parameters: int documentID, int termPosition, int length
-      def documentIdParam = p["documentId"]
-      if(documentIdParam){
-        def termPositionParam = p["termPosition"]
-        if(termPositionParam){
-          def lengthParam = p["length"]
-          if(lengthParam){
-            try{
-              //we have all required parameters
-              int documentId = documentIdParam.toInteger()
-              int termPosition = termPositionParam.toInteger()
-              int length = lengthParam.toInteger()
-              String[][] docText = runner.getDocumentText(documentId, 
termPosition, length)
-              new ObjectOutputStream (response.outputStream).withStream 
{stream -> 
-                stream.writeObject(docText)
-              }
-            }catch(Exception e){
-              response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 
-                  "Error while obtaining the document text: \"" + 
-                  e.getMessage() + "\"!")
-            }              
-          } else {
-            response.sendError(HttpServletResponse.SC_BAD_REQUEST, 
-            "No value provided for parameter length!")
-          }
-        } else {
-          response.sendError(HttpServletResponse.SC_BAD_REQUEST, 
-          "No value provided for parameter termPosition!")
-        }
-      } else {
-        response.sendError(HttpServletResponse.SC_BAD_REQUEST, 
-        "No value provided for parameter documentID!")
-      }
-    } else {
-      response.sendError(HttpServletResponse.SC_NOT_FOUND, 
-          "Query ID ${queryId} not known!")
-    }
-  }
-  
-  
-  /**
-   * Gets the URI of a document as a serialises String value.
-   */
-  def docURIBin = {
-    def p = params["request"] ?: params
-    //get the query ID
-    String queryId = p["queryId"]
-    QueryRunner runner = searchService.getQueryRunner(queryId);
-    if(runner){
-      //get the parameters: int documentID
-      def documentIdParam = p["documentId"]
-      if(documentIdParam){
-        try{
-          //we have all required parameters
-          int documentId = documentIdParam.toInteger()
-          String docUri = runner.getDocumentURI(documentId)
-          new ObjectOutputStream (response.outputStream).withStream {stream -> 
-            stream.writeObject(docUri)
-          }
-        }catch(Exception e){
-          response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 
-              "Error while obtaining the document URI: \"" + 
-              e.getMessage() + "\"!")
-        }          
-      } else {
-        response.sendError(HttpServletResponse.SC_BAD_REQUEST, 
-            "No value provided for parameter documentId!")
-      }
-    } else {
-      response.sendError(HttpServletResponse.SC_NOT_FOUND, 
-          "Query ID ${queryId} not known!")
-    }
-  }
-  
-  /**
-   * Gets the title of a document as a serialised String value.
-   */
-  def docTitleBin = {
-    def p = params["request"] ?: params
-    //get the query ID
-    String queryId = p["queryId"]
-    QueryRunner runner = searchService.getQueryRunner(queryId);
-    if(runner){
-      //get the parameters: int documentID
-      def documentIdParam = p["documentId"]
-      if(documentIdParam){
-        try{
-          //we have all required parameters
-          int documentId = documentIdParam.toInteger()
-          String docTitle = runner.getDocumentTitle(documentId)
-          new ObjectOutputStream (response.outputStream).withStream {stream -> 
-            stream.writeObject(docTitle)
-          }
-        }catch(Exception e){
-          response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, 
-              "Error while obtaining the document title: \"" + 
-              e.getMessage() + "\"!")
-        }          
-      } else {
-        response.sendError(HttpServletResponse.SC_BAD_REQUEST, 
-            "No value provided for parameter documentId!")
-      }
-    } else {
-      response.sendError(HttpServletResponse.SC_NOT_FOUND, 
-          "Query ID ${queryId} not known!")
-    }
-  }
-  
-  /**
-   * Gets a set of arbitrary document metadata fields
-   */
-  def docMetadataFieldsBin = {
-    def p = params["request"] ?: params
-    //get the query ID
-    String queryId = p["queryId"]
-    QueryRunner runner = searchService.getQueryRunner(queryId);
-    if(runner){
-      //get the parameters: int documentID
-      def documentIdParam = p["documentId"]
-      if(documentIdParam){
-        def fieldNamesStr = p["fieldNames"]
-        if(fieldNamesStr) {
-          try{
-            //we have all required parameters
-            int documentId = documentIdParam.toInteger()
-            Set<String> fieldNames = new HashSet<String>()
-            // split on each comma (not preceded by a backslash)
-            fieldNamesStr.split(/\s*(?<!\\),\s*/).collect{
-              // un-escape commas
-              it.replace('\\,', ',')
-            }.each{fieldNames.add(it)}
-            Map<String, Serializable> medatada = 
-                runner.getDocumentMetadataFields(documentId, fieldNames)
-            new ObjectOutputStream (response.outputStream).withStream {stream 
->
-              stream.writeObject(medatada)
-            }
-          }catch(Exception e){
-            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
-                "Error while obtaining the document title: \"" +
-                e.getMessage() + "\"!")
-          }
-        } else {
-        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
-          "No value provided for parameter fieldNames!")
-        }
-      } else {
-        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
-            "No value provided for parameter documentId!")
-      }
-    } else {
-      response.sendError(HttpServletResponse.SC_NOT_FOUND,
-          "Query ID ${queryId} not known!")
-    }
-  }
-  
-  /**
    * Gets the annotations config for a given index, as a serialised String[][] 
    * value.
    */
@@ -1082,8 +835,6 @@
   }
 }
 
-
-
 /**
  * An extension of HashSet, that listens to session binding events and releases
  * all queries upon unbinding. 

Modified: 
mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/FederatedIndex.groovy
===================================================================
--- 
mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/FederatedIndex.groovy    
    2011-12-09 16:34:10 UTC (rev 14714)
+++ 
mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/FederatedIndex.groovy    
    2011-12-09 16:35:22 UTC (rev 14715)
@@ -14,6 +14,7 @@
 
 import org.hibernate.proxy.HibernateProxy;
 
+import gate.mimir.index.mg4j.zipcollection.DocumentData;
 import gate.mimir.search.QueryRunner
 import gate.mimir.search.FederatedQueryRunner
 
@@ -79,6 +80,15 @@
   }
   
   /**
+   * Gets the {@link DocumentData} value for a given document ID.
+   * @param documentID
+   * @return
+   */
+  DocumentData getDocumentData(int documentID) {
+    return federatedIndexService.getDocumentData(this, documentID)
+  }
+  
+  /**
    * Returns the annotations config for this index.
    */
   String[][] annotationsConfig() {

Modified: mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/Index.groovy
===================================================================
--- mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/Index.groovy 
2011-12-09 16:34:10 UTC (rev 14714)
+++ mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/Index.groovy 
2011-12-09 16:35:22 UTC (rev 14715)
@@ -13,6 +13,7 @@
 package gate.mimir.web;
 
 import gate.mimir.search.QueryRunner
+import gate.mimir.index.mg4j.zipcollection.DocumentData
 
 /**
  * Top level class representing a single index (local or remote) in mimir.
@@ -101,6 +102,15 @@
   }
 
   /**
+   * Gets the {@link DocumentData} value for a given document ID.
+   * @param documentID
+   * @return
+   */
+  DocumentData getDocumentData(int documentID) {
+    throw new UnsupportedOperationException()
+  }
+  
+  /**
    * Mark the given document IDs in this index as having been deleted,
    * preventing them from being subsequently returned by any queries.
    */

Modified: 
mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/LocalIndex.groovy
===================================================================
--- mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/LocalIndex.groovy    
2011-12-09 16:34:10 UTC (rev 14714)
+++ mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/LocalIndex.groovy    
2011-12-09 16:35:22 UTC (rev 14715)
@@ -13,6 +13,7 @@
 package gate.mimir.web;
 
 
+import gate.mimir.index.mg4j.zipcollection.DocumentData
 import gate.mimir.search.QueryRunner
 import gate.Document
 import gate.Gate
@@ -90,6 +91,15 @@
   QueryRunner startQuery(String queryString) {
     return localIndexService.getQueryRunner(this, queryString)
   }
+  
+  /**
+  * Gets the {@link DocumentData} value for a given document ID.
+  * @param documentID
+  * @return
+  */
+  DocumentData getDocumentData(int documentID) {
+    return localIndexService.getDocumentData(this, documentID)
+  }
 
   void deleteDocuments(Collection<Integer> documentIds) {
     localIndexService.deleteDocuments(this, documentIds)

Modified: 
mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/RemoteIndex.groovy
===================================================================
--- mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/RemoteIndex.groovy   
2011-12-09 16:34:10 UTC (rev 14714)
+++ mimir/trunk/mimir-web/grails-app/domain/gate/mimir/web/RemoteIndex.groovy   
2011-12-09 16:35:22 UTC (rev 14715)
@@ -14,6 +14,7 @@
  */
 package gate.mimir.web;
 
+import gate.mimir.index.mg4j.zipcollection.DocumentData;
 import gate.mimir.search.QueryRunner;
 import gate.mimir.search.RemoteQueryRunner;
 import gate.mimir.tool.WebUtils;
@@ -79,6 +80,18 @@
   }
 
   /**
+   * Gets the {@link DocumentData} value for a given document ID.
+   * @param documentID
+   * @return
+   */
+  DocumentData getDocumentData(int documentID) {
+    String urlStr = (remoteUrl.endsWith("/") ? remoteUrl : (remoteUrl + "/")) +
+        "/search/documentDataBin";
+    return (DocumentData)webUtilsManager.currentWebUtils(this).getObject(
+          urlStr,  "documentId", Integer.toString(documentID));
+  }
+ 
+  /**
    * Obtains the annotations config from the remote controller.
    */
   String[][] annotationsConfig() {

Modified: 
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/FederatedIndexService.groovy
===================================================================
--- 
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/FederatedIndexService.groovy
       2011-12-09 16:34:10 UTC (rev 14714)
+++ 
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/FederatedIndexService.groovy
       2011-12-09 16:35:22 UTC (rev 14715)
@@ -14,6 +14,7 @@
  */
 package gate.mimir.web
 
+import gate.mimir.index.mg4j.zipcollection.DocumentData;
 import gate.mimir.web.FederatedIndex;
 import gate.mimir.web.Index;
 
@@ -106,7 +107,13 @@
 
   public void undeleteDocuments(FederatedIndex index, Collection<Integer> 
documentIds) {
     deleteOrUndelete("undelete", index, documentIds)
-  } 
+  }
+  
+  public DocumentData getDocumentData(FederatedIndex fedIndex, int documentId) 
{
+    Index subIndex = fedIndex.indexes[documentId % fedIndex.indexes.size()]
+    int idWithinSubIndex = documentId.intdiv(fedIndex.indexes.size())
+    return subIndex.getDocumentData(idWithinSubIndex)
+  }
 }
 
 class FederatedIndexProxy implements Runnable{

Modified: 
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/LocalIndexService.groovy
===================================================================
--- 
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/LocalIndexService.groovy
   2011-12-09 16:34:10 UTC (rev 14714)
+++ 
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/LocalIndexService.groovy
   2011-12-09 16:35:22 UTC (rev 14715)
@@ -27,6 +27,7 @@
 import gate.mimir.IndexConfig
 import gate.mimir.index.IndexException;
 import gate.mimir.index.Indexer
+import gate.mimir.index.mg4j.zipcollection.DocumentData;
 import gate.mimir.SemanticAnnotationHelper;
 import gate.mimir.IndexConfig.SemanticIndexerConfig;
 import gate.mimir.util.*
@@ -142,6 +143,10 @@
     return getQueryEngine(index).getQueryRunner(query)
   }
   
+  public synchronized DocumentData getDocumentData(LocalIndex index, int 
documentId) {
+    return getQueryEngine(index).getDocumentData(documentId)
+  }
+  
   public synchronized void deleteDocuments(LocalIndex index, 
Collection<Integer> documentIds) {
     getQueryEngine(index).deleteDocuments(documentIds)
   }

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


------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to