diff --git a/wsagent/che-core-api-project/pom.xml b/wsagent/che-core-api-project/pom.xml
index 9ad79076047..f998da40222 100644
--- a/wsagent/che-core-api-project/pom.xml
+++ b/wsagent/che-core-api-project/pom.xml
@@ -131,6 +131,10 @@
org.eclipse.che.core
wsagent-local
+
+ org.eclipse.text
+ org.eclipse.text
+
org.everrest
everrest-websockets
@@ -180,6 +184,11 @@
che-core-commons-test
test
+
+ org.eclipse.equinox
+ common
+ test
+
org.everrest
everrest-core
diff --git a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/vfs/search/impl/LuceneSearcher.java b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/vfs/search/impl/LuceneSearcher.java
index be31dc4db17..03c441496b3 100644
--- a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/vfs/search/impl/LuceneSearcher.java
+++ b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/vfs/search/impl/LuceneSearcher.java
@@ -21,7 +21,6 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-import java.util.Scanner;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import org.apache.lucene.analysis.Analyzer;
@@ -65,6 +64,9 @@
import org.eclipse.che.api.vfs.search.SearchResult;
import org.eclipse.che.api.vfs.search.SearchResultEntry;
import org.eclipse.che.api.vfs.search.Searcher;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -269,22 +271,20 @@ public SearchResult search(QueryExpression query) throws ServerException {
float res = queryScorer.getTokenScore();
if (res > 0.0F && startOffset <= endOffset) {
- String tokenText = txt.substring(startOffset, endOffset);
- Scanner sc = new Scanner(txt);
- int lineNum = 0;
- long len = 0;
- String foundLine = "";
- while (sc.hasNextLine()) {
- foundLine = sc.nextLine();
- lineNum++;
- len += foundLine.length();
- if (len > startOffset) {
- break;
- }
+ try {
+ IDocument document = new org.eclipse.jface.text.Document(txt);
+ int lineNum = document.getLineOfOffset(startOffset);
+ IRegion lineInfo = document.getLineInformation(lineNum);
+ String foundLine = document.get(lineInfo.getOffset(), lineInfo.getLength());
+ String tokenText = document.get(startOffset, endOffset - startOffset);
+
+ offsetData.add(
+ new OffsetData(
+ tokenText, startOffset, endOffset, docId, res, lineNum, foundLine));
+ } catch (BadLocationException e) {
+ LOG.error(e.getLocalizedMessage(), e);
+ throw new ServerException("Can not provide data for token " + termAtt.toString());
}
- offsetData.add(
- new OffsetData(
- tokenText, startOffset, endOffset, docId, res, lineNum, foundLine));
}
}
}