Index: TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/function/tigersearch/TIGERSearch.java
===================================================================
--- TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/function/tigersearch/TIGERSearch.java	(revision 3779)
+++ TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/function/tigersearch/TIGERSearch.java	(revision 3780)
@@ -246,7 +246,8 @@
 				pQuery = new TIGERQuery("root(#n1)"); //$NON-NLS-1$
 			}
 			
-			tsresult = tscorpus.query(pQuery.getQueryString());
+			// tsresult = tscorpus.query(pQuery.getQueryString());
+			tsresult = TIGERSearchEngine.getInstance().queryTIGER(this.getCorpus(), pQuery);
 			tsresult.getFirst();
 			
 			pIndex = 0;
Index: TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TSCorpus.java
===================================================================
--- TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TSCorpus.java	(revision 3779)
+++ TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TSCorpus.java	(revision 3780)
@@ -71,7 +71,7 @@
 	boolean initok = false;
 	
 	/** The results. */
-	HashMap<Integer, TSResult> results = new HashMap<>();
+	HashMap<String, TSResult> results = new HashMap<>();
 	
 	// Additional data for corpus alignment with TXM base corpus (CQP corpus)
 	RandomAccessFile offsetsRAFile = null;
@@ -303,11 +303,13 @@
 	 * @throws Exception
 	 */
 	public TSResult query(String query, int sent_min, int sent_max, int match_max) throws Exception {
-		if (results.containsKey(query.hashCode()))
-			return results.get(query.hashCode());
+		String skey = query+ " "+sent_min+" "+sent_max+" "+match_max;
+		if (results.containsKey(skey)) {
+			return results.get(skey);
+		}
 		
 		TSResult rez = new TSResult(query, this, sent_min, sent_max, match_max);
-		results.put(query.hashCode(), rez);
+		results.put(skey, rez);
 		return rez;
 	}
 	
Index: TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TIGERSearchEngine.java
===================================================================
--- TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TIGERSearchEngine.java	(revision 3779)
+++ TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TIGERSearchEngine.java	(revision 3780)
@@ -1,7 +1,6 @@
 package org.txm.searchengine.ts;
 
 import java.io.File;
-import java.io.FileFilter;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.PrintWriter;
@@ -10,7 +9,6 @@
 import java.nio.MappedByteBuffer;
 import java.nio.channels.FileChannel;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -27,6 +25,7 @@
 import org.txm.searchengine.core.Query;
 import org.txm.searchengine.core.SearchEngine;
 import org.txm.searchengine.core.SearchEngineProperty;
+import org.txm.searchengine.core.SearchEnginesManager;
 import org.txm.searchengine.core.Selection;
 import org.txm.searchengine.cqp.AbstractCqiClient;
 import org.txm.searchengine.cqp.CQPSearchEngine;
@@ -62,6 +61,7 @@
 	HashMap<CorpusBuild, TSCorpus> corpora = null;
 
 	public TSCorpus getTSCorpus(CorpusBuild corpus) {
+		
 		CorpusBuild root = corpus.getRootCorpusBuild();
 		TSCorpus tscorpus = corpora.get(root);
 		if (tscorpus != null) {
@@ -183,6 +183,18 @@
 	public Selection query(CorpusBuild corpus, IQuery query, String name, boolean saveQuery) throws Exception {
 
 		TSCorpus tcorpus = this.getTSCorpus(corpus);
+		TSResult result = queryTIGER(corpus, query);
+		
+		if (result == null) { // no result
+			return new EmptySelection(query);
+		}
+
+		return fromTIGERMatchToSelection(tcorpus, result, query, corpus);
+	}
+	
+	public TSResult queryTIGER(CorpusBuild corpus, IQuery query) throws Exception {
+
+		TSCorpus tcorpus = this.getTSCorpus(corpus);
 		TSResult result = null;
 		if (corpus == corpus.getRootCorpusBuild() || !(corpus instanceof CQPCorpus)) { // root corpus or something not a CQPCorpus
 			result = tcorpus.query(query.getQueryString().replace("\n", " "));
@@ -192,20 +204,27 @@
 			AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
 			List<? extends Match> matches = cqpCorpus.getMatches();
 			if (matches.size() == 0) {
-				return new EmptySelection(query);
+				return result;
 			}
 			int[] cpos = { matches.get(0).getStart(), matches.get(matches.size() - 1).getEnd() };
-			int[] structs = CQI.cpos2Struc(cqpCorpus.getStructuralUnit("s").getProperty("n").getQualifiedName(), cpos);
-			if (structs.length == 0) {
-				return new EmptySelection(query);
+			
+			int[] starts = tcorpus.getSentenceStartPositions();
+			int sent_max = starts.length;
+			int sent_min = 0;
+			for (int i = 0 ; i < starts.length ; i++) {
+				if (starts[i] < cpos[0]) {
+					sent_min = i;
+				} else if (starts[i] > cpos[1]) {
+					sent_max = i;
+					break;
+				}
 			}
-			int sent_min = structs[0];
-			int sent_max = structs[structs.length - 1];
+			
 			Log.finest("QUERYING sentences: " + sent_min + " -> " + sent_max);
-			result = tcorpus.query(query.getQueryString().replace("\n", " "), sent_min, sent_max + 1, -1);
+			result = tcorpus.query(query.getQueryString().replace("\n", " "), sent_min, sent_max, -1);
 		}
 
-		return fromTIGERMatchToSelection(tcorpus, result, query, corpus);
+		return result;
 	}
 
 	public static Selection fromTIGERMatchToSelection(TSCorpus tcorpus, TSResult result, IQuery query, CorpusBuild corpus) throws IndexException {
@@ -621,4 +640,8 @@
 		}
 		return null;
 	}
+
+	public static TIGERSearchEngine getInstance() {
+		return (TIGERSearchEngine) SearchEnginesManager.getTIGERSearchEngine();
+	}
 }
Index: TXM/trunk/bundles/org.txm.treesearch.rcp/src/org/txm/treesearch/rcp/tester/TreeSearchTester.java
===================================================================
--- TXM/trunk/bundles/org.txm.treesearch.rcp/src/org/txm/treesearch/rcp/tester/TreeSearchTester.java	(revision 3779)
+++ TXM/trunk/bundles/org.txm.treesearch.rcp/src/org/txm/treesearch/rcp/tester/TreeSearchTester.java	(revision 3780)
@@ -1,10 +1,9 @@
 package org.txm.treesearch.rcp.tester;
 
-import java.io.File;
 import java.util.List;
 
 import org.eclipse.core.expressions.PropertyTester;
-import org.txm.searchengine.cqp.corpus.MainCorpus;
+import org.txm.searchengine.cqp.corpus.CQPCorpus;
 import org.txm.treesearch.command.ComputeTreeSearch;
 
 /**
@@ -39,10 +38,10 @@
 			}
 			
 			receiver = l.get(0);
-			if (!(receiver instanceof MainCorpus)) return false;
+			if (!(receiver instanceof CQPCorpus)) return false;
 			
-			MainCorpus corpus = (MainCorpus) receiver;
-			if (!(receiver instanceof MainCorpus)) {
+			CQPCorpus corpus = (CQPCorpus) receiver;
+			if (!(receiver instanceof CQPCorpus)) {
 				return false;
 			}
 			
