Search in sources :

Example 1 with QueryExpression

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

the class FSLuceneSearcherTest 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);
}
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 2 with QueryExpression

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

the class FSLuceneSearcherTest method excludesFilesFromIndexWithFilter.

@Test
public void excludesFilesFromIndexWithFilter() throws Exception {
    VirtualFileSystem virtualFileSystem = virtualFileSystem();
    VirtualFile folder = virtualFileSystem.getRoot().createFolder("folder");
    folder.createFile("xxx.txt", TEST_CONTENT[2]);
    folder.createFile("yyy.txt", TEST_CONTENT[2]);
    folder.createFile("zzz.txt", TEST_CONTENT[2]);
    when(filter.accept(withName("yyy.txt"))).thenReturn(true);
    searcher.init(virtualFileSystem);
    List<String> paths = searcher.search(new QueryExpression().setText("be")).getFilePaths();
    assertEquals(newArrayList("/folder/xxx.txt", "/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)

Example 3 with QueryExpression

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

the class FSLuceneSearcherTest method searchesByWordFragment.

@Test
public void searchesByWordFragment() throws Exception {
    VirtualFileSystem virtualFileSystem = virtualFileSystem();
    VirtualFile folder = virtualFileSystem.getRoot().createFolder("folder");
    folder.createFile("xxx.txt", TEST_CONTENT[0]);
    searcher.init(virtualFileSystem);
    List<String> paths = searcher.search(new QueryExpression().setText("*stone*")).getFilePaths();
    assertEquals(newArrayList("/folder/xxx.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)

Example 4 with QueryExpression

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

the class FSLuceneSearcherTest method updatesSingleFileInIndex.

@Test
public void updatesSingleFileInIndex() 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("should")).getFilePaths();
    assertTrue(paths.isEmpty());
    file.updateContent(TEST_CONTENT[1]);
    searcher.update(file);
    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 5 with QueryExpression

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

the class FSLuceneSearcherTest method searchFileByName.

@Test(dataProvider = "searchByName")
public void searchFileByName(String fileName, String searchedFileName) throws Exception {
    VirtualFileSystem virtualFileSystem = virtualFileSystem();
    VirtualFile folder = virtualFileSystem.getRoot().createFolder("parent/child");
    VirtualFile folder2 = virtualFileSystem.getRoot().createFolder("folder2");
    folder.createFile(NameGenerator.generate(null, 10), TEST_CONTENT[3]);
    folder.createFile(fileName, TEST_CONTENT[2]);
    folder.createFile(NameGenerator.generate(null, 10), TEST_CONTENT[1]);
    folder2.createFile(NameGenerator.generate(null, 10), TEST_CONTENT[2]);
    folder2.createFile(NameGenerator.generate(null, 10), TEST_CONTENT[2]);
    searcher.init(virtualFileSystem);
    List<String> paths = searcher.search(new QueryExpression().setName(searchedFileName)).getFilePaths();
    assertEquals(newArrayList("/parent/child/" + fileName), 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