This shot provides a short hint on how to use labels in a Lucene search with Confluence.
Adding labels to a Confluence search using SearchQueryParameters seems straightforward:
...
Code Block | ||
---|---|---|
| ||
final SearchQueryParameters searchQueryParams = |
...
new SearchQueryParameters(queryString); |
...
searchQueryParams.setLabels( |
...
Collections.singleton("mylabel")); |
...
Unfortunately this search does not match documents labelled with mylabel
.
After some searching the solution adding the labels manually to the Lucene search works:
...
Code Block | ||
---|---|---|
| ||
String queryStringWithLabel = |
...
"labelText:\"mylabel\" AND (" + queryString + ')'; |
...
final SearchQueryParameters searchQueryParams = |
...
new SearchQueryParameters(queryStringWithLabel); |
...
But what I should have done instead is adding the "global" prefix to my label like this:
...
Code Block | ||
---|---|---|
| ||
final SearchQueryParameters searchQueryParams = |
...
new SearchQueryParameters(queryString); |
...
searchQueryParams.setLabels( |
...
Collections.singleton("global:mylabel"); |
...
Conclusion
The API's intended solution is not always obvious at first sight. Often the API documentation could give hint. But if it doesn't it is just a couple of working hours away ... Hope this post will reduce the working time for you!
:-)