Revision: 15942
          http://gate.svn.sourceforge.net/gate/?rev=15942&view=rev
Author:   valyt
Date:     2012-07-16 15:26:06 +0000 (Mon, 16 Jul 2012)
Log Message:
-----------
More work on Terms queries:
- Support for getting the set of terms in a given document.

Modified Paths:
--------------
    
mimir/trunk/mimir-core/src/gate/mimir/index/mg4j/MimirDirectIndexBuilder.java
    mimir/trunk/mimir-core/src/gate/mimir/search/IndexReaderPool.java
    mimir/trunk/mimir-core/src/gate/mimir/search/QueryEngine.java
    mimir/trunk/mimir-core/src/gate/mimir/search/query/AnnotationQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractTermsQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsQuery.java
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsResultSet.java
    mimir/trunk/mimir-core/src/gate/mimir/util/MG4JTools.java

Added Paths:
-----------
    mimir/trunk/mimir-core/src/gate/mimir/search/terms/DocumentTermsQuery.java

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/index/mg4j/MimirDirectIndexBuilder.java
===================================================================
--- 
mimir/trunk/mimir-core/src/gate/mimir/index/mg4j/MimirDirectIndexBuilder.java   
    2012-07-16 12:26:43 UTC (rev 15941)
+++ 
mimir/trunk/mimir-core/src/gate/mimir/index/mg4j/MimirDirectIndexBuilder.java   
    2012-07-16 15:26:06 UTC (rev 15942)
@@ -48,7 +48,7 @@
   
   protected String inputSubindexBasename;
   
-  protected static final String BASENAME_SUFFIX = "-dir";
+  public static final String BASENAME_SUFFIX = "-dir";
   
   /**
    * @param indexDirectory the top level directory for the Mímir index being

Modified: mimir/trunk/mimir-core/src/gate/mimir/search/IndexReaderPool.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/IndexReaderPool.java   
2012-07-16 12:26:43 UTC (rev 15941)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/IndexReaderPool.java   
2012-07-16 15:26:06 UTC (rev 15942)
@@ -14,10 +14,16 @@
  */
 package gate.mimir.search;
 
+import it.unimi.dsi.big.io.FileLinesCollection;
+import it.unimi.dsi.big.mg4j.index.DiskBasedIndex;
 import it.unimi.dsi.big.mg4j.index.Index;
 import it.unimi.dsi.big.mg4j.index.IndexReader;
+import it.unimi.dsi.big.util.ImmutableExternalPrefixMap;
+import it.unimi.dsi.lang.MutableString;
 
+import java.io.File;
 import java.io.IOException;
+import java.net.URI;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -26,6 +32,32 @@
  */
 public class IndexReaderPool {
   
+  private class IndexDictionary extends ImmutableExternalPrefixMap {
+
+    private static final long serialVersionUID = 3350171413268036811L;
+
+    public IndexDictionary(Iterable<? extends CharSequence> terms)
+      throws IOException {
+      super(terms);
+    }
+
+    /**
+     * A mutable string used internally. 
+     */
+    private MutableString ms = new MutableString();
+
+    /**
+     * Gets the term string for a given term ID. This method is synchronised to
+     * protect the shared mutable string instance.
+     * @param termId the ID for the term being sought.
+     * @return the string for the given term.
+     */
+    public synchronized String getTerm(long termId) {
+      return super.getTerm(termId, ms).toString();
+    }
+    
+  }
+  
   private static final int DEFAULT_CAPACITY = 100000;
   
   /**
@@ -41,25 +73,39 @@
    */
   private Index index;
   
+  
   /**
+   * A URI representing the index basename (the template index file name, 
+   * without any extension). 
+   */
+  private URI indexURI;
+  
+  /**
    * The current size of the pool.
    */
   private AtomicInteger size;
   
   /**
+   * An external map that holds the index terms. Allows the retrieval of a 
+   * term's text given a term ID.
+   */
+  private IndexDictionary dictionary;
+  
+  /**
    * The actual pool.
    */
   private ConcurrentLinkedQueue<IndexReader> pool;
 
-  public IndexReaderPool(Index index, int capacity) {
+  public IndexReaderPool(Index index, int capacity, URI indexUri) {
     this.capacity = capacity;
     this.index = index;
+    this.indexURI = indexUri;
     pool = new ConcurrentLinkedQueue<IndexReader>();
     size = new AtomicInteger(0);
   }
   
-  public IndexReaderPool(Index index) {
-    this(index, DEFAULT_CAPACITY);
+  public IndexReaderPool(Index index, URI indexUri) {
+    this(index, DEFAULT_CAPACITY, indexUri);
   }
   
   /**
@@ -99,6 +145,22 @@
     return index;
   }
   
+  /**
+   * Gets the string term for a given term ID.
+   * @param termId
+   * @return
+   * @throws IOException
+   */
+  public String getTerm(long termId) throws IOException {
+    if(dictionary == null) {
+      FileLinesCollection dictionaryLines = new FileLinesCollection(
+        new File(URI.create(indexURI.toString() + 
+          DiskBasedIndex.TERMS_EXTENSION)).getAbsolutePath(), "UTF-8");
+      dictionary = new IndexDictionary(dictionaryLines);
+    }
+    return dictionary.getTerm(termId);
+  }
+  
   public void close() throws IOException {
     IndexReader aReader = pool.poll();
     size.decrementAndGet();

Modified: mimir/trunk/mimir-core/src/gate/mimir/search/QueryEngine.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/QueryEngine.java       
2012-07-16 12:26:43 UTC (rev 15941)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/QueryEngine.java       
2012-07-16 15:26:06 UTC (rev 15942)
@@ -23,6 +23,7 @@
 import gate.mimir.index.IndexException;
 import gate.mimir.index.Indexer;
 import gate.mimir.index.mg4j.MentionsIndexBuilder;
+import gate.mimir.index.mg4j.MimirDirectIndexBuilder;
 import gate.mimir.index.mg4j.TokenIndexBuilder;
 import gate.mimir.index.mg4j.zipcollection.DocumentCollection;
 import gate.mimir.index.mg4j.zipcollection.DocumentData;
@@ -125,6 +126,12 @@
    * configuration).
    */
   protected IndexReaderPool[] indexReaderPools;
+  
+  /**
+   * Array containing the direct indexes (if enabled) for the Mímir composite
+   * index.
+   */
+  protected IndexReaderPool[] directIndexReaderPools;
 
   /**
    * The zipped document collection from MG4J (built during the indexing of the
@@ -350,6 +357,19 @@
   }
 
   /**
+   * Returns the set of direct indexes (if enabled) in the Mimir composite 
+   * index. The array contains first the token indexes (in the same order as 
+   * listed in the index configuration), followed by the mentions indexes 
+   * (in the same order as listed in the index configuration). In other words,
+   * this array is parallel to the one returned by {@link #getIndexes()}.
+   * 
+   * @return an array of {@link Index} objects.
+   */
+  public IndexReaderPool[] getDirectIndexes() {
+    return directIndexReaderPools;
+  }  
+  
+  /**
    * Gets the list of document sizes from one underlying MG4J index (all 
    * sub-indexes should have the same sizes).
    * @return
@@ -375,6 +395,27 @@
   }
 
   /**
+   * Returns the <strong>direct</strong> index that stores the data for a 
+   * particular feature of token annotations. 
+   * 
+   * NB: direct indexes are used to search for term IDs given
+   * a document ID. For standard searches (getting documents given search 
terms)
+   * use the default (inverted) index returned by: 
+   * {@link #getTokenIndex(String)}.
+   * 
+   * @param featureName
+   * @return
+   */
+  public IndexReaderPool getTokenDirectIndex(String featureName) {
+    for(int i = 0; i < indexConfig.getTokenIndexers().length; i++) {
+      
if(indexConfig.getTokenIndexers()[i].getFeatureName().equals(featureName)) {
+        return directIndexReaderPools[i]; 
+      }
+    }
+    return null;
+  }  
+  
+  /**
    * Returns the index that stores the data for a particular semantic 
annotation
    * type.
    * 
@@ -383,17 +424,41 @@
    */
   public IndexReaderPool getAnnotationIndex(String annotationType) {
     for(int i = 0; i < indexConfig.getSemanticIndexers().length; i++) {
-      for(String aType : indexConfig.getSemanticIndexers()[i]
-                                                           
.getAnnotationTypes()) {
-        if(aType.equals(annotationType)) { return indexReaderPools[indexConfig
-                                                          
.getTokenIndexers().length
-                                                          + i]; }
+      for(String aType : 
+          indexConfig.getSemanticIndexers()[i].getAnnotationTypes()) {
+        if(aType.equals(annotationType)) { 
+          return indexReaderPools[indexConfig.getTokenIndexers().length + i]; 
+        }
       }
     }
     return null;
   }
 
   /**
+   * Returns the <strong>direct</strong> index that stores the data for a 
+   * particular semantic annotation type.
+   * 
+   * NB: direct indexes are used to search for term IDs given
+   * a document ID. For standard searches (getting documents given search 
terms)
+   * use the default (inverted) index returned by: 
+   * {@link #getAnnotationIndex(String)}.
+   * 
+   * @param annotationType
+   * @return
+   */
+  public IndexReaderPool getAnnotationDirectIndex(String annotationType) {
+    for(int i = 0; i < indexConfig.getSemanticIndexers().length; i++) {
+      for(String aType : 
+          indexConfig.getSemanticIndexers()[i].getAnnotationTypes()) {
+        if(aType.equals(annotationType)) { 
+          return directIndexReaderPools[indexConfig.getTokenIndexers().length 
+ i]; 
+        }
+      }
+    }
+    return null;
+  }  
+  
+  /**
    * @return the index configuration for this index
    */
   public IndexConfig getIndexConfig() {
@@ -762,6 +827,17 @@
       }
     }
     indexReaderPools = null;
+
+    for(IndexReaderPool aPool : directIndexReaderPools) {
+      try {
+        if(aPool != null) aPool.close();
+      } catch(IOException e) {
+        // log and ignore
+        logger.error("Exception while closing direct index reader pool.", e);
+      }
+    }
+    directIndexReaderPools = null;
+    
   }
 
   /**
@@ -771,9 +847,14 @@
    * @throws IndexException
    */
   protected void initMG4J() throws IOException, IndexException {
-    indexReaderPools =
-      new IndexReaderPool[indexConfig.getTokenIndexers().length
-                + indexConfig.getSemanticIndexers().length];
+    indexReaderPools = new IndexReaderPool[
+        indexConfig.getTokenIndexers().length + 
+        indexConfig.getSemanticIndexers().length];
+    
+    directIndexReaderPools = new IndexReaderPool[
+        indexConfig.getTokenIndexers().length +
+        indexConfig.getSemanticIndexers().length];
+    
     try {
       File mg4JIndexDir = new File(indexDir, Indexer.MG4J_INDEX_DIRNAME);
       // Load the token indexes as memory mapped, if possible
@@ -783,6 +864,14 @@
                   + TokenIndexBuilder.TOKEN_INDEX_BASENAME + "-" + i);
         URI indexURI = indexBasename.toURI();
         indexReaderPools[i] = openOneSubIndex(indexURI);
+        directIndexReaderPools[i] = null;
+        if(indexConfig.getTokenIndexers()[i].isDirectIndexEnabled()) {
+          indexBasename = new File(mg4JIndexDir, 
+              Indexer.MG4J_INDEX_BASENAME + "-" + 
+              TokenIndexBuilder.TOKEN_INDEX_BASENAME + "-" + i + 
+              MimirDirectIndexBuilder.BASENAME_SUFFIX);
+            directIndexReaderPools[i] = openOneSubIndex(indexBasename.toURI());
+        }
       }
       // load the mentions indexes
       for(int i = 0; i < indexConfig.getSemanticIndexers().length; i++) {
@@ -793,6 +882,15 @@
         URI indexURI = indexBasename.toURI();
         indexReaderPools[indexConfig.getTokenIndexers().length + i] =
           openOneSubIndex(indexURI);
+        directIndexReaderPools[indexConfig.getTokenIndexers().length + i] = 
null;
+        if(indexConfig.getSemanticIndexers()[i].isDirectIndexEnabled()) {
+          indexBasename = new File(mg4JIndexDir, 
+              Indexer.MG4J_INDEX_BASENAME + "-" + 
+              MentionsIndexBuilder.MENTIONS_INDEX_BASENAME + "-" + i +
+              MimirDirectIndexBuilder.BASENAME_SUFFIX);
+          indexReaderPools[indexConfig.getTokenIndexers().length + i] = 
+              openOneSubIndex(indexBasename.toURI());
+        }
       }
       // open the zipped document collection
       documentCollection = new DocumentCollection(indexDir);
@@ -833,7 +931,7 @@
     // see if the index needs upgrading
     MG4JTools.upgradeIndex(indexUri);
     Index theIndex = MG4JTools.openMg4jIndex(indexUri);
-    return new IndexReaderPool(theIndex);
+    return new IndexReaderPool(theIndex, indexUri);
   }
   
   /**

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/search/query/AnnotationQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/query/AnnotationQuery.java     
2012-07-16 12:26:43 UTC (rev 15941)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/query/AnnotationQuery.java     
2012-07-16 15:26:06 UTC (rev 15942)
@@ -82,10 +82,10 @@
           SemanticAnnotationHelper.Mode.DOCUMENT);
       // get the mention URIs
       TermsResultSet trs = new AnnotationTermsQuery(query).execute(engine);
-      if(trs.terms != null && trs.terms.length > 0 && 
+      if(trs.termStrings != null && trs.termStrings.length > 0 && 
          trs.termLengths != null) {
-        QueryNode[] disjuncts = new QueryNode[trs.terms.length];
-        for(int index = 0; index < trs.terms.length; index++) {
+        QueryNode[] disjuncts = new QueryNode[trs.termStrings.length];
+        for(int index = 0; index < trs.termStrings.length; index++) {
           // create a term query for the mention URI
           disjuncts[index] = new TermQuery(query.annotationType, 
                   trs.termIds[index], trs.termLengths[index]);

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractTermsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractTermsQuery.java  
2012-07-16 12:26:43 UTC (rev 15941)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/AbstractTermsQuery.java  
2012-07-16 15:26:06 UTC (rev 15942)
@@ -21,34 +21,27 @@
   
   protected boolean stringsEnabled;
   
-  protected boolean idsEnabled;
-  
   protected boolean countsEnabled;
 
-  
+  public static final int NO_LIMIT = -1;
   /**
    * The maximum number of results to be returned.
    */
   protected final int limit;  
   
-  public AbstractTermsQuery(boolean idsEnabled, boolean stringsEnabled,
-                            boolean countsEnabled, int limit) {
-    this.idsEnabled = idsEnabled;
+  public AbstractTermsQuery(boolean stringsEnabled, boolean countsEnabled, 
+                            int limit) {
     this.stringsEnabled = stringsEnabled;
     this.countsEnabled = countsEnabled;
     this.limit = limit;
   }
   
-  public AbstractTermsQuery(boolean idsEnabled, boolean stringsEnabled,
-                            boolean countsEnabled) {
-    this.idsEnabled = idsEnabled;
-    this.stringsEnabled = stringsEnabled;
-    this.countsEnabled = countsEnabled;
-    this.limit = -1;
+  public AbstractTermsQuery(boolean stringsEnabled, boolean countsEnabled) {
+    this(stringsEnabled, countsEnabled, NO_LIMIT);
   }  
   
   public AbstractTermsQuery() {
-    this(true, false, false);
+    this(false, false, NO_LIMIT);
   }
   
 }

Modified: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java
===================================================================
--- 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java    
    2012-07-16 12:26:43 UTC (rev 15941)
+++ 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/AnnotationTermsQuery.java    
    2012-07-16 15:26:06 UTC (rev 15942)
@@ -35,9 +35,8 @@
 public class AnnotationTermsQuery extends AbstractTermsQuery {
   
   public AnnotationTermsQuery(AnnotationQuery annotationQuery, 
-      boolean idsEnabled, boolean stringsEnabled, boolean countsEnabled,
-      int limit) {
-    super(idsEnabled, stringsEnabled, countsEnabled, limit);
+      boolean stringsEnabled, boolean countsEnabled, int limit) {
+    super(stringsEnabled, countsEnabled, limit);
     this.annotationQuery = annotationQuery;
   }
   

Added: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/DocumentTermsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/DocumentTermsQuery.java  
                        (rev 0)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/DocumentTermsQuery.java  
2012-07-16 15:26:06 UTC (rev 15942)
@@ -0,0 +1,181 @@
+/*
+ *  DocumentTermQuery.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, 16 Jul 2012
+ *
+ *  $Id$
+ */
+package gate.mimir.search.terms;
+
+import java.io.IOException;
+
+import it.unimi.dsi.big.mg4j.index.BitStreamIndex;
+import it.unimi.dsi.big.mg4j.index.Index;
+import it.unimi.dsi.big.mg4j.index.IndexIterator;
+import it.unimi.dsi.big.mg4j.index.IndexReader;
+import it.unimi.dsi.big.mg4j.search.DocumentIterator;
+import it.unimi.dsi.big.util.StringMap;
+import it.unimi.dsi.fastutil.ints.IntArrayList;
+import it.unimi.dsi.fastutil.longs.LongArrayList;
+import it.unimi.dsi.fastutil.objects.ObjectArrayList;
+import gate.mimir.index.mg4j.MimirDirectIndexBuilder;
+import gate.mimir.search.IndexReaderPool;
+import gate.mimir.search.QueryEngine;
+
+import static gate.mimir.search.QueryEngine.IndexType;
+
+/**
+ * A {@link TermsQuery} that returns the terms occurring in a document.
+ */
+public class DocumentTermsQuery extends AbstractTermsQuery {
+  
+  /**
+   * The ID of the document for which the terms are being sought.
+   */
+  protected final long documentId;
+  
+  /**
+   * The name of the subindex in which the terms are sought. Each Mímir 
+   * index includes multiple sub-indexes (some storing tokens, other storing 
+   * annotations), identified by a name. For token indexes, the index name is
+   * the name of the token feature being indexed; for annotation indexes, the
+   * index name is the annotation type. 
+   */
+  protected final String indexName; 
+
+  protected final IndexType indexType;
+  
+  
+  /**
+   * Creates a new document term query.
+   * 
+   * @param documentId the ID of the document for which the terms are sought
+   * 
+   * @param indexName the name of the sub-index to be searched. Each Mímir 
+   * index includes multiple sub-indexes (some storing tokens, other storing 
+   * annotations), identified by a name. For token indexes, the index name is
+   * the name of the token feature being indexed; for annotation indexes, the
+   * index name is the annotation type.
+   * 
+   * @param idsEnabled should term IDs be returned.
+   * 
+   * @param stringsEnabled should term Strings be returned.
+   * 
+   * @param countsEnabled should term counts be returned.
+   * 
+   * @param limit the maximum number of results to be returned.
+   */
+  public DocumentTermsQuery(long documentId, String indexName, 
+      IndexType indexType, boolean stringsEnabled, boolean countsEnabled, 
+      int limit) {
+    super(stringsEnabled, countsEnabled, limit);
+    this.documentId = documentId;
+    this.indexName = indexName;
+    this.indexType = indexType;
+  }
+
+  /**
+   * Creates a new document term query.
+   * The returned result set will contain term IDs and term counts, but not
+   * term strings. The number of results returned is not limited. If a 
+   * different result set configuration is required, use the
+   * {@link #DocumentTermQuery(long, String, boolean, boolean, boolean)} 
+   * constructor variant.
+   * 
+   * @param documentId the ID of the document for which the terms are sought
+   * 
+   * @param indexName the name of the sub-index to be searched. Each Mímir 
+   * index includes multiple sub-indexes (some storing tokens, other storing 
+   * annotations), identified by a name. For token indexes, the index name is
+   * the name of the token feature being indexed; for annotation indexes, the
+   * index name is the annotation type.
+   * 
+   * @param indexType the type of the index being searched.
+   */
+  public DocumentTermsQuery(long documentId, String indexName, 
+      IndexType indexType) {
+    this(documentId, indexName, indexType, false, true, NO_LIMIT);
+  }
+
+  /**
+   * Creates a new document term query.
+   * The returned result set will contain term IDs and term counts, but not
+   * term strings. If a different result set configuration is required, use the
+   * {@link #DocumentTermQuery(long, String, boolean, boolean, boolean)} 
+   * constructor variant.
+   * 
+   * @param documentId the ID of the document for which the terms are sought
+   * 
+   * @param indexName the name of the sub-index to be searched. Each Mímir 
+   * index includes multiple sub-indexes (some storing tokens, other storing 
+   * annotations), identified by a name. For token indexes, the index name is
+   * the name of the token feature being indexed; for annotation indexes, the
+   * index name is the annotation type.
+   * 
+   * @param indexType the type of the index being searched.
+   * 
+   * @param limit the maximum number of results to be returned.
+   */
+  public DocumentTermsQuery(long documentId, String indexName, 
+      IndexType indexType, int limit) {
+    this(documentId, indexName, indexType, false, true, limit);
+  }
+  
+  /* (non-Javadoc)
+   * @see gate.mimir.search.terms.TermQuery#execute()
+   */
+  @Override
+  public TermsResultSet execute(QueryEngine engine) throws IOException {
+    IndexReaderPool directIndexPool = null;
+    IndexReaderPool indirectIndexPool = null;
+    IndexReader indexReader = null;
+    try{
+      switch(indexType){
+        case ANNOTATIONS:
+          directIndexPool = engine.getAnnotationDirectIndex(indexName);
+          indirectIndexPool = engine.getAnnotationIndex(indexName);
+          break;
+        case TOKENS:
+          directIndexPool = engine.getTokenDirectIndex(indexName);
+          indirectIndexPool = engine.getTokenIndex(indexName);
+          break;
+        default:
+          throw new IllegalArgumentException("Invalid index type: " + 
+              indexType.toString());
+      }
+      
+      // prepare local data
+      LongArrayList termIds = new LongArrayList();
+      ObjectArrayList<String> termStrings = stringsEnabled ? 
+          new ObjectArrayList<String>() : null;
+      IntArrayList termCounts = countsEnabled ? new IntArrayList() : null;
+      // start the actual search
+      indexReader = directIndexPool.borrowReader();
+      IndexIterator results = indexReader.documents(
+        MimirDirectIndexBuilder.longToTerm(documentId));
+      long termId = results.nextDocument();
+      while(termId != DocumentIterator.END_OF_LIST && termId != -1) {
+        termIds.add(termId);
+        if(countsEnabled) termCounts.add(results.count());
+        if(stringsEnabled) termStrings.add(indirectIndexPool.getTerm(termId));
+        termId = results.nextDocument();
+      }
+      // construct the result
+      return new TermsResultSet(termIds.toLongArray(),
+        stringsEnabled ? termStrings.toArray(new String[termStrings.size()]) : 
null,
+        null,
+        countsEnabled ? termCounts.toIntArray() : null);      
+    } finally {
+      if(indexReader != null) {
+        directIndexPool.returnReader(indexReader);  
+      }
+    }
+  }
+}


Property changes on: 
mimir/trunk/mimir-core/src/gate/mimir/search/terms/DocumentTermsQuery.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native

Modified: mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsQuery.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsQuery.java  
2012-07-16 12:26:43 UTC (rev 15941)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsQuery.java  
2012-07-16 15:26:06 UTC (rev 15942)
@@ -14,6 +14,8 @@
  */
 package gate.mimir.search.terms;
 
+import java.io.IOException;
+
 import gate.mimir.search.QueryEngine;
 
 /**
@@ -25,7 +27,8 @@
    * Runs the term query (in the calling thread) and returns the matched terms.
    * @return a {@link TermsResultSet} containing the matched terms.
    * @param engine the {@link QueryEngine} used to execute the search.
+   * @throws IOException 
    */
-  public TermsResultSet execute(QueryEngine engine);
+  public TermsResultSet execute(QueryEngine engine) throws IOException;
   
 }

Modified: mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsResultSet.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsResultSet.java      
2012-07-16 12:26:43 UTC (rev 15941)
+++ mimir/trunk/mimir-core/src/gate/mimir/search/terms/TermsResultSet.java      
2012-07-16 15:26:06 UTC (rev 15942)
@@ -21,7 +21,7 @@
   
   /**
    * The term IDs, as retrieved from the index. Array parallel with 
-   * {@link #terms} and {@link #counts}.
+   * {@link #termStrings} and {@link #termCounts}.
    */
   public final long[] termIds;
   
@@ -32,23 +32,23 @@
   
   /**
    * The strings for the terms. Array parallel with 
-   * {@link #termIds} and {@link #counts}.
+   * {@link #termIds} and {@link #termCounts}.
    */
-  public final String[] terms;
+  public final String[] termStrings;
   
   
   /**
    * The counts (numbers of occurrences) for the terms. Array parallel with 
-   * {@link #terms} and {@link #termIds}.
+   * {@link #termStrings} and {@link #termIds}.
    */
-  public final int[] counts;
+  public final int[] termCounts;
 
   public TermsResultSet(long[] termIds, String[] terms,int[] termLengths, 
int[] counts) {
     super();
     this.termIds = termIds;
-    this.terms = terms;
+    this.termStrings = terms;
     this.termLengths = termLengths;
-    this.counts = counts;
+    this.termCounts = counts;
   }
   
   /**

Modified: mimir/trunk/mimir-core/src/gate/mimir/util/MG4JTools.java
===================================================================
--- mimir/trunk/mimir-core/src/gate/mimir/util/MG4JTools.java   2012-07-16 
12:26:43 UTC (rev 15941)
+++ mimir/trunk/mimir-core/src/gate/mimir/util/MG4JTools.java   2012-07-16 
15:26:06 UTC (rev 15942)
@@ -152,10 +152,7 @@
       if(aFile.exists()) {
         size += aFile.length();
       } else {
-        // no index file!
-        throw new IllegalArgumentException(
-                "Could not locate the index file at " + aFile.getAbsolutePath()
-                + "!");
+        // probably a direct index with no positions
       }
       String options = "?" + (size <= QueryEngine.MAX_IN_MEMORY_INDEX ? 
           UriKeys.INMEMORY.toString().toLowerCase() + "=1" : 

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


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to