Revision: 14545
          http://gate.svn.sourceforge.net/gate/?rev=14545&view=rev
Author:   valyt
Date:     2011-11-15 10:40:35 +0000 (Tue, 15 Nov 2011)
Log Message:
-----------
Support for obtaining the hits relating to a given document (i.e. the much 
requested 'document mode').

Modified Paths:
--------------
    mimir/trunk/mimir-client/src/gate/mimir/search/RemoteQueryRunner.java
    mimir/trunk/mimir-core/src/gate/mimir/search/FederatedQueryRunner.java
    mimir/trunk/mimir-core/src/gate/mimir/search/QueryRunner.java
    mimir/trunk/mimir-core/src/gate/mimir/search/QueryRunnerImpl.java
    
mimir/trunk/mimir-web/grails-app/controllers/gate/mimir/web/SearchController.groovy

Modified: mimir/trunk/mimir-client/src/gate/mimir/search/RemoteQueryRunner.java
===================================================================
--- mimir/trunk/mimir-client/src/gate/mimir/search/RemoteQueryRunner.java       
2011-11-15 09:47:13 UTC (rev 14544)
+++ mimir/trunk/mimir-client/src/gate/mimir/search/RemoteQueryRunner.java       
2011-11-15 10:40:35 UTC (rev 14545)
@@ -187,6 +187,8 @@
   protected static final String ACTION_HIT_COUNT_BIN = "hitCountBin";
 
   protected static final String ACTION_HITS_BIN = "hitsBin";
+  
+  protected static final String ACTION_HITS_FOR_DOC_BIN = "hitsForDocumentBin";
 
   protected static final String ACTION_IS_ACTIVE_BIN = "isActiveBin";
 
@@ -293,7 +295,25 @@
               "an unknown object type!", e);
     }
   }
+  
+  
 
+  @Override
+  public List<Binding> getHitsForDocument(int documentId)
+    throws IndexOutOfBoundsException {
+    try {
+      return (List<Binding>)webUtils.getObject(
+             getActionBaseUrl(ACTION_HITS_FOR_DOC_BIN),
+             "queryId", queryId, 
+             "documentId", Integer.toString(documentId));
+    } catch(IOException e) {
+      throw new RuntimeException(e);
+    } catch(ClassNotFoundException e) {
+      throw new RuntimeException("Was expecting a list of bindings, but got " +
+              "an unknown object type!", e);
+    }    
+  }
+
   public int getHitsCount() {
     try {
       return webUtils.getInt(getActionBaseUrl(ACTION_HIT_COUNT_BIN),
@@ -408,12 +428,10 @@
     } catch(ClassNotFoundException e) {
       throw new IndexException("Was expecting a String value, but got an " +
           "unknown object type!", e);
-    }  }
+    }
+  }
 
-
-
-
-
+  
   public void renderDocument(int documentId, Appendable out)
           throws IOException, IndexException {
     webUtils.getText(out, getActionBaseUrl(ACTION_RENDER_DOCUMENT),

Modified: mimir/trunk/mimir-core/src/gate/mimir/search/FederatedQueryRunner.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/FederatedQueryRunner.java      
2011-11-15 09:47:13 UTC (rev 14544)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/FederatedQueryRunner.java      
2011-11-15 10:40:35 UTC (rev 14545)
@@ -407,6 +407,15 @@
     }
   }
 
+  
+  @Override
+  public List<Binding> getHitsForDocument(int documentId)
+    throws IndexOutOfBoundsException {
+    int subQuery = documentId % subRunners.length;
+    int idWithinSubIndex = documentId / subRunners.length;
+    return subRunners[subQuery].getHitsForDocument(idWithinSubIndex);
+  }
+
   public void renderDocument(int documentId, Appendable out)
           throws IOException, IndexException {
     int subQuery = documentId % subRunners.length;

Modified: mimir/trunk/mimir-core/src/gate/mimir/search/QueryRunner.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/QueryRunner.java       
2011-11-15 09:47:13 UTC (rev 14544)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/QueryRunner.java       
2011-11-15 10:40:35 UTC (rev 14545)
@@ -153,6 +153,16 @@
       throws IndexOutOfBoundsException;
   
   /**
+   * Gets all the hits for a given document.
+   * @param documentId the ID of the document for which the hits are being 
+   * requested.
+   * @return a list of hits
+   * @throws IndexOutOfBoundsException
+   */
+  public List<Binding> getHitsForDocument(int documentId)
+      throws IndexOutOfBoundsException;
+  
+  /**
    * Render the content of the given document, with the hits for this query
    * highlighted.
    * @param documentId

Modified: mimir/trunk/mimir-core/src/gate/mimir/search/QueryRunnerImpl.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/QueryRunnerImpl.java   
2011-11-15 09:47:13 UTC (rev 14544)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/QueryRunnerImpl.java   
2011-11-15 10:40:35 UTC (rev 14545)
@@ -300,7 +300,7 @@
    * @param documentId the ID for the sought document
    * @return a {@link List} of {@link Binding} values.
    */
-  protected List<Binding> getHitsForDocument(int documentId){
+  public List<Binding> getHitsForDocument(int documentId){
     List<Binding> hits = new ArrayList<Binding>();
     int startIndex = 0;
     synchronized(documentStats) {

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-11-15 09:47:13 UTC (rev 14544)
+++ 
mimir/trunk/mimir-web/grails-app/controllers/gate/mimir/web/SearchController.groovy
 2011-11-15 10:40:35 UTC (rev 14545)
@@ -559,6 +559,40 @@
   }
   
   /**
+  * 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{
+      response.sendError(HttpServletResponse.SC_NOT_FOUND,
+          "Query ID ${queryId} not known!")
+    }
+  }
+  
+  /**
    * Gets the number of available hits as a binary representation of an int 
    * value.
    */

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


------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to