Confluence Adding status field to CQL Edited

Hello,

I am trying to add "Status" field to CQL using Search extractor in Script Runner. However, I am getting it work. I used following code,

import com.atlassian.confluence.pages.Page
import org.apache.lucene.document.Field
import org.apache.lucene.document.TextField


if (searchable instanceof Page) {
Page page = searchable as Page
String status = page.contentEntityObject.getEntity().getProperties().getStringProperty("Status") as String
document.add(new TextField("status", status, Field.Store.YES))
}

 

 

Am I doing anything wrong here?

 

I know there is Atlassian KB for developing a plugin https://developer.atlassian.com/server/confluence/adding-a-field-to-cql/

but I don't want to develop a separate plugin. I believe it should be achievable by ScriptRunner.

 

2 answers

1 accepted

0 vote

Problem is fixed after deleting all cache folders such as plugins-cache, plugins-osgi-cache, plugins-temp, journal and index. Restart the application. Rebuilt Content Index after restart. 

1 vote
Stephen Deutsch Community Champion Jan 15, 2018

Hi Suhas,

it sounds like you're trying to build a SearchExtractor. It seems like you're on the right track, but the line 

String status = page.contentEntityObject.getEntity().getProperties().getStringProperty("Status") as String

could probably be simplified to 

String status = page.getProperties().getStringProperty("Status") as String

since page inherits methods from ContentEntityObject.

 

I think there's three things you need to make sure about:

1. Is the content I'm looking for actually stored in the "status" property?

2. Have I re-built the search index after inserting the script?

3. Do I get results when searching with the recommended syntax ( status : whatever ) in a normal text search?

You may also have to change

document.add(new TextField("status", status, Field.Store.YES))

to

document.add(new StringField("status", status, Field.Store.YES))

and

import org.apache.lucene.document.TextField

to

import org.apache.lucene.document.StringField

Hi Stephen,

Thanks for the inputs.

Yeah, you are right, I will make changes you suggested for simplifying the code.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

840 views 2 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you