Linking directly to search queries
Haven't you wondered how we can link to a query from a template, or link a JSP from a custom page or plugin page? In this recipe, we will see how we can create a link programmatically and otherwise to use in various places.
How to do it…
Let us first look at creating a search link programmatically. Perform the following steps:
Create the
Query
object usingJqlQueryBuilder
, as we have seen in the previous recipe.Get an instance of the
SearchService
class. It could be injected in the constructor of your plugin using a dependency injection, or it can be retrieved from theComponentAccessor
class as follows:SearchService searchService = ComponentAccessor.getComponent(SearchService.class);
Retrieve the query string from the
Query
object usingSearchService
, shown as follows:String queryString = searchService.getQueryString(user, query);
Construct the link using the context path. In JSPs, you can do it as shown in the following lines of code:
<a href="<%= request...