use of org.eclipse.che.api.vfs.VirtualFileSystem in project che by eclipse.
the class MemoryLuceneSearcherTest method deletesSingleFileFromIndex.
@Test
public void deletesSingleFileFromIndex() throws Exception {
VirtualFileSystem virtualFileSystem = virtualFileSystem();
VirtualFile file = virtualFileSystem.getRoot().createFolder("aaa").createFile("aaa.txt", TEST_CONTENT[2]);
searcher.init(virtualFileSystem);
List<String> paths = searcher.search(new QueryExpression().setText("be")).getFilePaths();
assertEquals(newArrayList(file.getPath().toString()), paths);
searcher.delete(file.getPath().toString(), file.isFile());
paths = searcher.search(new QueryExpression().setText("be")).getFilePaths();
assertTrue(paths.isEmpty());
}
use of org.eclipse.che.api.vfs.VirtualFileSystem in project che by eclipse.
the class MemoryLuceneSearcherTest method generatesQueryExpressionForRetrievingNextPageOfResults.
@Test
public void generatesQueryExpressionForRetrievingNextPageOfResults() throws Exception {
VirtualFileSystem virtualFileSystem = virtualFileSystem();
for (int i = 0; i < 100; i++) {
virtualFileSystem.getRoot().createFile(String.format("file%02d", i), TEST_CONTENT[i % TEST_CONTENT.length]);
}
searcher.init(virtualFileSystem);
SearchResult result = searcher.search(new QueryExpression().setText("spaceflight").setMaxItems(7));
assertEquals(25, result.getTotalHits());
Optional<QueryExpression> optionalNextPageQueryExpression = result.getNextPageQueryExpression();
assertTrue(optionalNextPageQueryExpression.isPresent());
QueryExpression nextPageQueryExpression = optionalNextPageQueryExpression.get();
assertEquals("spaceflight", nextPageQueryExpression.getText());
assertEquals(7, nextPageQueryExpression.getSkipCount());
assertEquals(7, nextPageQueryExpression.getMaxItems());
}
use of org.eclipse.che.api.vfs.VirtualFileSystem in project che by eclipse.
the class MemoryLuceneSearcherTest method addsFileTreeInIndex.
@Test
public void addsFileTreeInIndex() throws Exception {
VirtualFileSystem virtualFileSystem = virtualFileSystem();
searcher.init(virtualFileSystem);
VirtualFile folder = virtualFileSystem.getRoot().createFolder("folder");
folder.createFile("xxx.txt", TEST_CONTENT[2]);
folder.createFile("zzz.txt", TEST_CONTENT[1]);
searcher.add(virtualFileSystem.getRoot());
List<String> paths = searcher.search(new QueryExpression().setText("be")).getFilePaths();
assertEquals(newArrayList("/folder/xxx.txt"), paths);
paths = searcher.search(new QueryExpression().setText("should")).getFilePaths();
assertEquals(newArrayList("/folder/zzz.txt"), paths);
}
use of org.eclipse.che.api.vfs.VirtualFileSystem in project che by eclipse.
the class MemoryLuceneSearcherTest method closesLuceneIndexWriterWhenSearcherClosed.
@Test
public void closesLuceneIndexWriterWhenSearcherClosed() throws Exception {
VirtualFileSystem virtualFileSystem = virtualFileSystem();
searcher.init(virtualFileSystem);
searcher.close();
assertTrue(searcher.isClosed());
assertFalse(searcher.getIndexWriter().isOpen());
}
use of org.eclipse.che.api.vfs.VirtualFileSystem in project che by eclipse.
the class MemoryLuceneSearcherTest method addsSingleFileInIndex.
@Test
public void addsSingleFileInIndex() throws Exception {
VirtualFileSystem virtualFileSystem = virtualFileSystem();
searcher.init(virtualFileSystem);
VirtualFile file = virtualFileSystem.getRoot().createFolder("aaa").createFile("aaa.txt", TEST_CONTENT[1]);
searcher.add(file);
List<String> paths = searcher.search(new QueryExpression().setText("should")).getFilePaths();
assertEquals(newArrayList(file.getPath().toString()), paths);
}
Aggregations