Over a million developers have joined DZone.

Searching NetBeans Zone Inside NetBeans IDE

DZone's Guide to

Searching NetBeans Zone Inside NetBeans IDE

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

The new NetBeans Quick Search API gives you an entry point into NetBeans IDE's new Quick Search feature, which will be part of 6.5 from M1 onwards. By default, the Quick Search feature lets you search for actions (i.e., the things that are invoked via menu items, toolbar buttons, and keyboard shortcuts) and types (i.e., interfaces and classes) which can then be invoked/opened when selected.

As a result, in the case of actions, the user does not need to know the location in the menu bar or toolbar of the action in question. For example, don't know where to go to invoke the "Help" action? Type "help" in the Quick Search and then you'll get a list of actions and types that match the search string:

Then the Help pops up when you select Help above, without requiring you to go to the Help menu. Even if you know where that menu item is found, being able to invoke all your actions from the same place saves a lot of time. Imagine if you want to, for example, open the Projects window after you've opened the Help. In the past you'd need to move from one menu item (or toolbar button) to another, whereas now you'll simply type a new search string and then click the relevant result. A real time saver. After making use of it, the invoked action (or type) is added to the Recent Search list, making it even easier to find next time round:

However, thanks to the API, the Quick Search feature isn't simply a feature. It is a framework, providing you with a user interface, a filtering mechanism, and the related search algorithms, so that all you need to provide is the content.

Simple example. Let's integrate the tutorials from platform.netbeans.org/tutorials into the Quick Search feature:

That's pretty handy. Now, you can see the tutorials that relate to the actions and types that you're searching for. And vice versa. In the same way, let's incorporate the titles of NetBeans Zone articles into the Quick Search feature:

When clicked, the related article opens in the browser. In the code below (which is ALL the code you will need for the integration shown above) you can see that JTidy is used for parsing purposes, but you could use any approach you like instead:

public class NetBeansZoneSearchProvider implements SearchProvider {

public void evaluate(SearchRequest request, SearchResponse response) {
try {

//The URL that we are providing a search for:
URL url = new URL("http://netbeans.dzone.com");

//Stuff needed by Tidy:
Tidy tidy = new Tidy();

//Get the org.w3c.dom.Document from Tidy:
Document doc = tidy.parseDOM(url.openStream(), null);

//Get all "a" elements:
NodeList list = doc.getElementsByTagName("a");

//Get the number of elements:
int length = list.getLength();

//Loop through all the "a" elements:
for (int i = 0; i < length; i++) {

String href = null;
if (null != list.item(i).getAttributes().getNamedItem("href")) {
//Get the "href" attribute from the current "a" element:
href = list.item(i).getAttributes().getNamedItem("href").getNodeValue();

//Get the "title" attribute from the current "a" element:
if (null != list.item(i).getAttributes().getNamedItem("title")) {
String title = list.item(i).getAttributes().getNamedItem("title").getNodeValue();

//If the title matches the requested text:
if (title.toLowerCase().indexOf(request.getText().toLowerCase()) != -1) {

//Add the runnable and the title to the response
//and return if nothing is added:
if (!response.addResult(new OpenFoundArticle(href), title)) {




} catch (IOException ex) {

private static class OpenFoundArticle implements Runnable {

private String article;

public OpenFoundArticle(String article {
this.article = article;

public void run() {
try {
URLDisplayer.getDefault().showURL(new URL("http://netbeans.dzone.com" + article));
} catch (MalformedURLException ex) {
Logger.getLogger(NetBeansZoneSearchProvider.class.getName()).log(Level.SEVERE, null, ex);



Here's another example, via the code above, pointing to netbeans.dzone.com, that shows the usefulness of this extension of the Quick Search feature:

Here's how to register it in the layer.xml file:

<folder name="QuickSearch">
<folder name="NetBeansZone">
<attr name="SystemFileSystem.localizingBundle"
<attr name="command" stringvalue="G"/>
<attr name="position" intvalue="1"/>
<file name="org-nb-nbzonesearch-NetBeansZoneSearchProvider.instance"/>

There's also a template (from 6.5 Milestone 2 onwards), which generates the layer entries, the relevant dependency, and a stub Java class, as explained in my blog.

Finally, imagine how cool it would be if a Quick Search extension were to be created for a site like the NetBeans User FAQ! The user would be able to find the solutions to their problems right inside the IDE, together with all the related actions and types. But these scenarios are just the tip of the iceberg. And even if you were to have a dozen or so different search categories, it would be fairly trivial to include customization settings so that the user would be able to determine which/how many searches are actually performed. Plus, maybe instead of searching titles (as done above), one could search the META tags in the HTML file, for example. That's completely up to the implementor. Also, bear in mind that here the Quick Search feature and its API are discussed in the context of NetBeans IDE, though everything said here applies equally to ANY application created on top of the NetBeans Platform, where this functionality might be equally useful. In short, the Quick Search API opens the IDE (and any other NetBeans Platform application) up to a vast integration of cross-referenced searches for as many related items as your users want. That's a pretty cool development.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.


Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}