Skip to content

Commit

Permalink
CHE-6046. Provide correct data for search results of Find text feature
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
  • Loading branch information
RomanNikitenko committed Sep 15, 2017
1 parent 857010f commit c9af56c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
9 changes: 9 additions & 0 deletions wsagent/che-core-api-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>wsagent-local</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.text</groupId>
<artifactId>org.eclipse.text</artifactId>
</dependency>
<dependency>
<groupId>org.everrest</groupId>
<artifactId>everrest-websockets</artifactId>
Expand Down Expand Up @@ -180,6 +184,11 @@
<artifactId>che-core-commons-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.equinox</groupId>
<artifactId>common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.everrest</groupId>
<artifactId>everrest-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
}
}
Expand Down

0 comments on commit c9af56c

Please sign in to comment.