Blog

  • 2024
  • 2023
  • 2022
  • 2021
  • 2020
  • 2019
  • 2018
  • 2017
  • 2016
  • 2015
  • 2014
  • 2013
  • 2012




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:

 

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:

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:

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!
:-)


Link

Link

Posts