You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
In Confluence, I am trying to search all pages that have a certain text inside of labels.
For example,
Label: project-GM
Ideal search : GM or label : GM
I've so far tried using ScriptRunner and using there guide to do a Label Search Extractor but there isn't much information on the subject on how to custimze and fit it to my needs.
Any recomdations please?
Hi Nadav,
This should work in a standard search:
labelText:/.*GM.*/
Great answer thanks!
And how can I get all the documents/pages as a variable in-script?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A few caveats:
I don't have scriptrunner installed, so I couldn't test it. I'm not an expert in Groovy, and I don't know so much about extractors. That said, this might work (adapted from the example on https://scriptrunner.adaptavist.com/latest/confluence/SearchExtractors.html):
import com.atlassian.confluence.labels.Label
import com.atlassian.confluence.pages.Page
import org.apache.lucene.document.Field
import org.apache.lucene.document.StringField
if (searchable instanceof Page) {
Page page = (Page) searchable
String labelText = "gm"
String labels = page.getLabels().inject("") { acc, val -> acc + val.getName() + " " }
if (labels.contains(labelText)) {
document.add(new StringField("labelContains", labelText, Field.Store.YES))
}
}
then you would search for "labelContains : gm" (note that labels are always lowercase).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome ! really helpful, last question is how do I do it for any kind of text so it can work on many sorts of labels (project-gm, project-bee.....), and in that way I can search whatever sub-text I want ( labelContains : XXXX) and it will work......
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately, I'm not sure about that one; by making this search extractor, you're creating an alias in the lucene index, so in order to match any value, you would have to create permutations for every possible value in order to match exactly (i.e. for project you would search for pr, pro, proj, proje, ro, roj, roje, ect.). If you are only going to use "project-xxx" to match, then something like this might work (as I said, I have no way of testing):
import com.atlassian.confluence.labels.Label
import com.atlassian.confluence.pages.Page
import org.apache.lucene.document.Field
import org.apache.lucene.document.StringField
if (searchable instanceof Page) {
Page page = (Page) searchable
String projects = page.getLabels().findAll { it.getName().contains('project-') }.inject("") { acc, val -> acc + val.getName().replace("project-", "") + " " }.trim()
if (projects) {
document.add(new StringField("project", projects, Field.Store.YES))
}
}
then you should be able to search for "project : gm" or "project : bee" or whatever.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
đŸ‘‹ Hi there, a few of us at Atlassian would love to learn about how you use "space settings" functionality in Confluence. A facelift to the space settings is long overdue and we want to start with im...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.