public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { List<Ancestor> l = req.getAncestors(); for (int i = l.size() - 1; i >= 0; i--) { Ancestor a = l.get(i); if (a.getObject() instanceof SearchableModelObject) { SearchableModelObject smo = (SearchableModelObject) a.getObject(); SearchIndex index = smo.getSearchIndex(); String query = req.getParameter("q"); if (query != null) { SuggestedItem target = find(index, query); if (target != null) { // found rsp.sendRedirect2(a.getUrl() + target.getUrl()); return; } } } } // no exact match. show the suggestions rsp.setStatus(SC_NOT_FOUND); req.getView(this, "search-failed.jelly").forward(req, rsp); }