Revision: 16316
          http://gate.svn.sourceforge.net/gate/?rev=16316&view=rev
Author:   valyt
Date:     2012-11-22 13:24:37 +0000 (Thu, 22 Nov 2012)
Log Message:
-----------
Simple query operator that returns a constant set of document IDs.

Added Paths:
-----------
    mimir/trunk/mimir-core/src/gate/mimir/search/query/Const.java

Added: mimir/trunk/mimir-core/src/gate/mimir/search/query/Const.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/query/Const.java               
                (rev 0)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/query/Const.java       
2012-11-22 13:24:37 UTC (rev 16316)
@@ -0,0 +1,143 @@
+/*
+ *  Const.java
+ *
+ *  Copyright (c) 2007-2011, The University of Sheffield.
+ *
+ *  This file is part of GATE Mímir (see http://gate.ac.uk/family/mimir.html), 
+ *  and is free software, licenced under the GNU Lesser General Public License,
+ *  Version 3, June 2007 (also included with this distribution as file
+ *  LICENCE-LGPL3.html).
+ *
+ *  Valentin Tablan, 22 Nov 2012
+ *
+ *  $Id$
+ */
+package gate.mimir.search.query;
+
+import gate.mimir.search.QueryEngine;
+
+import it.unimi.dsi.big.mg4j.index.Index;
+import it.unimi.dsi.big.mg4j.search.visitor.DocumentIteratorVisitor;
+import it.unimi.dsi.fastutil.objects.ReferenceArraySet;
+import it.unimi.dsi.fastutil.objects.ReferenceSet;
+
+import java.io.IOException;
+
+/**
+ * A query that returns a pre-defined (constant) list of document IDs. This 
+ * query type does not support positions, so it returns no hits.
+ */
+public class Const implements QueryNode {
+  
+  /**
+   * Executor implementation for {@link ConstQuery}. It returns document IDs
+   * from the predefined list, and no positions.
+   */
+  public static class ConstQueryExecutor extends AbstractQueryExecutor {
+    
+    public ConstQueryExecutor(Const qNode, QueryEngine engine) {
+      super(engine, qNode);
+      this.documentIds = qNode.documentIds;
+      latestDocumentPosition = -1;
+    }
+    
+    /**
+     * The position in the constant list of document IDs of the latest returned
+     * document.
+     */
+    private int latestDocumentPosition;
+    
+    /**
+     * The predefined list of document IDs.
+     */
+    private long[] documentIds;
+    
+    private ReferenceSet<Index> indices;
+    
+    /* (non-Javadoc)
+     * @see gate.mimir.search.query.QueryExecutor#nextDocument(long)
+     */
+    @Override
+    public long nextDocument(long greaterThan) throws IOException {
+      do {
+        latestDocumentPosition++;
+      } while(latestDocumentPosition < documentIds.length && 
+              documentIds[latestDocumentPosition] <= greaterThan);
+      if(latestDocumentPosition < documentIds.length) {
+        latestDocument = documentIds[latestDocumentPosition];
+      } else {
+        latestDocument = -1;
+      }
+      return latestDocument;
+    }
+
+    /**
+     * This query executor type does not support positions, so it always 
returns
+     * null. 
+     * @see gate.mimir.search.query.QueryExecutor#nextHit()
+     */
+    @Override
+    public Binding nextHit() throws IOException {
+      return null;
+    }
+
+    /**
+     * Returns an empty set of indices.
+     * @see it.unimi.dsi.big.mg4j.search.DocumentIterator#indices()
+     */
+    @Override
+    public ReferenceSet<Index> indices() {
+      if(indices == null) {
+        indices = new ReferenceArraySet<Index>();
+      }
+      return indices;
+    }
+
+    /**
+     * Always returns null.
+     * @see 
it.unimi.dsi.big.mg4j.search.DocumentIterator#accept(it.unimi.dsi.big.mg4j.search.visitor.DocumentIteratorVisitor)
+     */
+    @Override
+    public <T> T accept(DocumentIteratorVisitor<T> visitor) throws IOException 
{
+      return null;
+    }
+
+    /**
+     * Always returns null
+     * @see 
it.unimi.dsi.big.mg4j.search.DocumentIterator#acceptOnTruePaths(it.unimi.dsi.big.mg4j.search.visitor.DocumentIteratorVisitor)
+     */
+    @Override
+    public <T> T acceptOnTruePaths(DocumentIteratorVisitor<T> visitor)
+      throws IOException {
+      return null;
+    }
+  }
+  
+  /* (non-Javadoc)
+   * @see 
gate.mimir.search.query.QueryNode#getQueryExecutor(gate.mimir.search.QueryEngine)
+   */
+  @Override
+  public QueryExecutor getQueryExecutor(QueryEngine engine) throws IOException 
{
+    return new ConstQueryExecutor(this, engine);
+  }
+  
+  
+  /**
+   * Creates a new Const query. 
+   * @param documentIds the document IDs (in ascending order) that should be 
+   * returned when this query is executed.
+   */
+  public Const(long[] documentIds) {
+    this.documentIds = documentIds;
+  }
+
+  private long[] documentIds;
+
+  /**
+   * @return the documentIds
+   */
+  public long[] getDocumentIds() {
+    return documentIds;
+  }
+  
+}


Property changes on: 
mimir/trunk/mimir-core/src/gate/mimir/search/query/Const.java
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

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
GATE-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to