Java Code Examples for org.netbeans.spi.quicksearch.SearchRequest#getText()
The following examples show how to use
org.netbeans.spi.quicksearch.SearchRequest#getText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResultsModel.java From netbeans with Apache License 2.0 | 6 votes |
private String highlightSubstring (String text, SearchRequest sRequest) { if (text.startsWith(HTML)) { // provider handles highliting itself, okay return text; } // try to find substring String searchedText = sRequest.getText(); int index = text.toLowerCase(Locale.ENGLISH).indexOf(searchedText.toLowerCase(Locale.ENGLISH)); if (index == -1) { return HTML + safeEscape(text); } // found, bold it int endIndex = index + searchedText.length(); StringBuilder sb = new StringBuilder(HTML); if (index > 0) { sb.append(safeEscape(text.substring(0, index))); } sb.append("<b>"); sb.append(safeEscape(text.substring(index, endIndex))); sb.append("</b>"); if (endIndex < text.length()) { sb.append(safeEscape(text.substring(endIndex, text.length()))); } return sb.toString(); }
Example 2
Source File: SearchProviderImpl.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void evaluate(SearchRequest request, SearchResponse response) { String text = request.getText(); if (text == null) { return; } if (!Utilities.isHudsonSupportActive()) { return; } work(text, response); }
Example 3
Source File: MavenRepoProvider.java From netbeans with Apache License 2.0 | 4 votes |
/** * Method is called by infrastructure when search operation was requested. * Implementors should evaluate given request and fill response object with * appropriate results * * @param request Search request object that contains information what to search for * @param response Search response object that stores search results. Note that it's important to react to return value of SearchResponse.addResult(...) method and stop computation if false value is returned. */ @Override public void evaluate(final SearchRequest request, final SearchResponse response) { final ArtifactNodeSelector s = Lookup.getDefault().lookup(ArtifactNodeSelector.class); if (s == null) { return; } final String q = request.getText(); if (q == null || q.trim().isEmpty()) { //#205552 return; } final List<RepositoryInfo> loadedRepos = RepositoryQueries.getLoadedContexts(); if (loadedRepos.isEmpty()) { return; } List<NBVersionInfo> infos = new ArrayList<NBVersionInfo>(); final List<NBVersionInfo> tempInfos = new ArrayList<NBVersionInfo>(); final RequestProcessor.Task searchTask = RP.post(new Runnable() { @Override public void run() { try { Result<NBVersionInfo> result = RepositoryQueries.findResult(getQuery(q), loadedRepos); synchronized (tempInfos) { tempInfos.addAll(result.getResults()); } } catch (BooleanQuery.TooManyClauses exc) { // query too general, just ignore it synchronized (tempInfos) { tempInfos.clear(); } } catch (OutOfMemoryError oome) { // running into OOME may still happen in Lucene despite the fact that // we are trying hard to prevent it in NexusRepositoryIndexerImpl // (see #190265) // in the bad circumstances theoretically any thread may encounter OOME // but most probably this thread will be it synchronized (tempInfos) { tempInfos.clear(); } } } }); try { // wait maximum 5 seconds for the repository search to complete // after the timeout tempInfos should contain at least partial results // we are not waiting longer, repository index download may be running on the background // because NexusRepositoryIndexerImpl.getLoaded() might have returned also repos // which are not available for the search yet searchTask.waitFinished(5000); } catch (InterruptedException ex) { } synchronized (tempInfos) { infos.addAll(tempInfos); } searchTask.cancel(); Collections.sort(infos); Set<String> artifacts = new HashSet<String>(); String ql = q.toLowerCase(Locale.ENGLISH); for (final NBVersionInfo art : infos) { String label = art.getGroupId() + " : " + art.getArtifactId(); if (!artifacts.add(label)) { continue; // ignore older versions } if (!label.toLowerCase(Locale.ENGLISH).contains(ql)) { String projectName = art.getProjectName(); String projectDescription = art.getProjectDescription(); if (projectName != null && projectName.toLowerCase(Locale.ENGLISH).contains(ql)) { label += " (" + projectName + ")"; } else if (projectDescription != null && projectDescription.toLowerCase(Locale.ENGLISH).contains(ql)) { label += " \"" + projectDescription + "\""; } } if (!response.addResult(new Runnable() { @Override public void run() { s.select(art); } }, label)) { return; } } }