Search in sources :

Example 36 with VirtualFileSystem

use of org.eclipse.che.api.vfs.VirtualFileSystem in project che by eclipse.

the class FSLuceneSearcherTest method closesLuceneIndexWriterWhenSearcherClosed.

@Test
public void closesLuceneIndexWriterWhenSearcherClosed() throws Exception {
    VirtualFileSystem virtualFileSystem = virtualFileSystem();
    searcher.init(virtualFileSystem);
    searcher.close();
    assertTrue(searcher.isClosed());
    assertFalse(searcher.getIndexWriter().isOpen());
}
Also used : VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) MemoryVirtualFileSystem(org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem) Test(org.testng.annotations.Test)

Example 37 with VirtualFileSystem

use of org.eclipse.che.api.vfs.VirtualFileSystem in project che by eclipse.

the class FSLuceneSearcherTest 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());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) MemoryVirtualFileSystem(org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem) QueryExpression(org.eclipse.che.api.vfs.search.QueryExpression) Test(org.testng.annotations.Test)

Example 38 with VirtualFileSystem

use of org.eclipse.che.api.vfs.VirtualFileSystem in project che by eclipse.

the class FSLuceneSearcherTest method deletesFileTreeFromIndex.

@Test
public void deletesFileTreeFromIndex() throws Exception {
    VirtualFileSystem virtualFileSystem = virtualFileSystem();
    VirtualFile folder = virtualFileSystem.getRoot().createFolder("folder");
    folder.createFile("xxx.txt", TEST_CONTENT[2]);
    folder.createFile("zzz.txt", TEST_CONTENT[1]);
    searcher.init(virtualFileSystem);
    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);
    searcher.delete("/folder", false);
    paths = searcher.search(new QueryExpression().setText("be")).getFilePaths();
    assertTrue(paths.isEmpty());
    paths = searcher.search(new QueryExpression().setText("should")).getFilePaths();
    assertTrue(paths.isEmpty());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) MemoryVirtualFileSystem(org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem) QueryExpression(org.eclipse.che.api.vfs.search.QueryExpression) Test(org.testng.annotations.Test)

Example 39 with VirtualFileSystem

use of org.eclipse.che.api.vfs.VirtualFileSystem in project che by eclipse.

the class FSLuceneSearcherTest 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);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) MemoryVirtualFileSystem(org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem) QueryExpression(org.eclipse.che.api.vfs.search.QueryExpression) Test(org.testng.annotations.Test)

Example 40 with VirtualFileSystem

use of org.eclipse.che.api.vfs.VirtualFileSystem in project che by eclipse.

the class FSLuceneSearcherTest method retrievesSearchResultWithPages.

@Test
public void retrievesSearchResultWithPages() 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 firstPage = searcher.search(new QueryExpression().setText("spaceflight").setMaxItems(8));
    assertEquals(8, firstPage.getFilePaths().size());
    QueryExpression nextPageQueryExpression = firstPage.getNextPageQueryExpression().get();
    nextPageQueryExpression.setMaxItems(100);
    SearchResult lastPage = searcher.search(nextPageQueryExpression);
    assertEquals(17, lastPage.getFilePaths().size());
    assertTrue(Collections.disjoint(firstPage.getFilePaths(), lastPage.getFilePaths()));
}
Also used : VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) MemoryVirtualFileSystem(org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem) SearchResult(org.eclipse.che.api.vfs.search.SearchResult) QueryExpression(org.eclipse.che.api.vfs.search.QueryExpression) Test(org.testng.annotations.Test)

Aggregations

VirtualFileSystem (org.eclipse.che.api.vfs.VirtualFileSystem)63 MemoryVirtualFileSystem (org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem)32 Test (org.junit.Test)29 QueryExpression (org.eclipse.che.api.vfs.search.QueryExpression)28 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)27 Test (org.testng.annotations.Test)18 FolderEntry (org.eclipse.che.api.project.server.FolderEntry)9 Searcher (org.eclipse.che.api.vfs.search.Searcher)7 SearchResult (org.eclipse.che.api.vfs.search.SearchResult)6 ServerException (org.eclipse.che.api.core.ServerException)5 Path (java.nio.file.Path)3 SearcherProvider (org.eclipse.che.api.vfs.search.SearcherProvider)3 IOException (java.io.IOException)2 AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 File (java.io.File)1 InputStream (java.io.InputStream)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ProjectImporter (org.eclipse.che.api.project.server.importer.ProjectImporter)1