use of org.eclipse.che.api.vfs.search.Searcher in project che by eclipse.
the class AbstractLuceneSearcherProvider method close.
@Override
public void close() throws ServerException {
Searcher searcher = searcherReference.get();
if (searcher != null) {
searcher.close();
}
searcherReference.set(null);
}
use of org.eclipse.che.api.vfs.search.Searcher in project che by eclipse.
the class AbstractLuceneSearcherProvider method getSearcher.
@Override
public Searcher getSearcher(VirtualFileSystem virtualFileSystem, boolean create) throws ServerException {
Searcher cachedSearcher = searcherReference.get();
if (cachedSearcher == null && create) {
LuceneSearcher searcher = createLuceneSearcher(() -> searcherReference.set(null));
if (searcherReference.compareAndSet(null, searcher)) {
searcher.initAsynchronously(executor, virtualFileSystem);
}
cachedSearcher = searcherReference.get();
}
return cachedSearcher;
}
use of org.eclipse.che.api.vfs.search.Searcher in project che by eclipse.
the class ProjectService method search.
@GET
@Path("/search/{path:.*}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Search for resources", notes = "Search for resources applying a number of search filters as query parameters", response = ItemReference.class, responseContainer = "List")
@ApiResponses({ @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 403, message = "User not authorized to call this operation"), @ApiResponse(code = 404, message = "Not found"), @ApiResponse(code = 409, message = "Conflict error"), @ApiResponse(code = 500, message = "Internal Server Error") })
public List<ItemReference> search(@ApiParam(value = "Path to resource, i.e. where to search?", required = true) @PathParam("path") String path, @ApiParam(value = "Resource name") @QueryParam("name") String name, @ApiParam(value = "Search keywords") @QueryParam("text") String text, @ApiParam(value = "Maximum items to display. If this parameter is dropped, there are no limits") @QueryParam("maxItems") @DefaultValue("-1") int maxItems, @ApiParam(value = "Skip count") @QueryParam("skipCount") int skipCount) throws NotFoundException, ForbiddenException, ConflictException, ServerException {
final Searcher searcher;
try {
searcher = projectManager.getSearcher();
} catch (NotFoundException e) {
LOG.warn(e.getLocalizedMessage());
return Collections.emptyList();
}
if (skipCount < 0) {
throw new ConflictException(String.format("Invalid 'skipCount' parameter: %d.", skipCount));
}
final QueryExpression expr = new QueryExpression().setPath(path.startsWith("/") ? path : ('/' + path)).setName(name).setText(text).setMaxItems(maxItems).setSkipCount(skipCount);
final SearchResult result = searcher.search(expr);
final List<SearchResultEntry> searchResultEntries = result.getResults();
final List<ItemReference> items = new ArrayList<>(searchResultEntries.size());
final FolderEntry root = projectManager.getProjectsRoot();
for (SearchResultEntry searchResultEntry : searchResultEntries) {
final VirtualFileEntry child = root.getChild(searchResultEntry.getFilePath());
if (child != null && child.isFile()) {
items.add(injectFileLinks(asDto((FileEntry) child)));
}
}
return items;
}
use of org.eclipse.che.api.vfs.search.Searcher in project che by eclipse.
the class FSLuceneSearcherProviderTest method resetsSearcherInProviderAfterClosingSearcher.
@Test
public void resetsSearcherInProviderAfterClosingSearcher() throws Exception {
VirtualFileSystem virtualFileSystem = mockVirtualFileSystem();
Searcher searcher = fsLuceneSearcherProvider.getSearcher(virtualFileSystem, true);
assertNotNull(searcher);
searcher.close();
assertNull(fsLuceneSearcherProvider.getSearcher(virtualFileSystem, false));
}
use of org.eclipse.che.api.vfs.search.Searcher in project che by eclipse.
the class FSLuceneSearcherProviderTest method closesSearcherWhenProviderIsClosed.
@Test
public void closesSearcherWhenProviderIsClosed() throws Exception {
Searcher searcher = mock(Searcher.class);
fsLuceneSearcherProvider.searcherReference.set(searcher);
fsLuceneSearcherProvider.close();
verify(searcher).close();
}
Aggregations