Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do I search for a certain part of a Label?

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?

2 answers

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?

 

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).

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......

 

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. 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

Announcing Team Calendars in Confluence Data Center

Hi Community! We're thrilled to share that Team Calendars for Confluence is now a built-in feature for Confluence Data Center releases 7.11 and beyond.  A long time favorite,  Team Cale...

177 views 0 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you