Search in sources :

Example 21 with QueryExpression

use of org.eclipse.che.api.vfs.search.QueryExpression in project che by eclipse.

the class MemoryLuceneSearcherTest method searchesByTextAndPathAndFileName.

@Test
public void searchesByTextAndPathAndFileName() throws Exception {
    VirtualFileSystem virtualFileSystem = virtualFileSystem();
    VirtualFile folder1 = virtualFileSystem.getRoot().createFolder("folder1/a/b");
    VirtualFile folder2 = virtualFileSystem.getRoot().createFolder("folder2/a/b");
    folder1.createFile("xxx.txt", TEST_CONTENT[2]);
    folder1.createFile("yyy.txt", TEST_CONTENT[2]);
    folder2.createFile("zzz.txt", TEST_CONTENT[2]);
    searcher.init(virtualFileSystem);
    List<String> paths = searcher.search(new QueryExpression().setText("be").setPath("/folder1").setName("xxx.txt")).getFilePaths();
    assertEquals(newArrayList("/folder1/a/b/xxx.txt"), paths);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) MemoryVirtualFileSystem(org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) QueryExpression(org.eclipse.che.api.vfs.search.QueryExpression) Test(org.junit.Test)

Example 22 with QueryExpression

use of org.eclipse.che.api.vfs.search.QueryExpression in project che by eclipse.

the class MemoryLuceneSearcherTest method limitsNumberOfSearchResultsWhenMaxItemIsSet.

@Test
public void limitsNumberOfSearchResultsWhenMaxItemIsSet() 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("mission").setMaxItems(5));
    assertEquals(25, result.getTotalHits());
    assertEquals(5, result.getFilePaths().size());
}
Also used : MemoryVirtualFileSystem(org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) SearchResult(org.eclipse.che.api.vfs.search.SearchResult) QueryExpression(org.eclipse.che.api.vfs.search.QueryExpression) Test(org.junit.Test)

Example 23 with QueryExpression

use of org.eclipse.che.api.vfs.search.QueryExpression in project che by eclipse.

the class MemoryLuceneSearcherTest 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) MemoryVirtualFileSystem(org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) QueryExpression(org.eclipse.che.api.vfs.search.QueryExpression) Test(org.junit.Test)

Example 24 with QueryExpression

use of org.eclipse.che.api.vfs.search.QueryExpression in project che by eclipse.

the class MemoryLuceneSearcherTest 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 : MemoryVirtualFileSystem(org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) SearchResult(org.eclipse.che.api.vfs.search.SearchResult) QueryExpression(org.eclipse.che.api.vfs.search.QueryExpression) Test(org.junit.Test)

Example 25 with QueryExpression

use of org.eclipse.che.api.vfs.search.QueryExpression in project che by eclipse.

the class FSLuceneSearcherTest method initializesIndexForExistedFiles.

@Test
public void initializesIndexForExistedFiles() 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("think")).getFilePaths();
    assertEquals(newArrayList("/folder/zzz.txt"), 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)

Aggregations

QueryExpression (org.eclipse.che.api.vfs.search.QueryExpression)30 VirtualFileSystem (org.eclipse.che.api.vfs.VirtualFileSystem)28 MemoryVirtualFileSystem (org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem)28 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)22 Test (org.testng.annotations.Test)15 Test (org.junit.Test)13 SearchResult (org.eclipse.che.api.vfs.search.SearchResult)7 SearchResultEntry (org.eclipse.che.api.vfs.search.SearchResultEntry)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 PrefixQuery (org.apache.lucene.search.PrefixQuery)1 Query (org.apache.lucene.search.Query)1