Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Confluence Adding status field to CQL

Suhas P
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 15, 2018

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 votes
Answer accepted
Suhas P
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 16, 2018

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 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?

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 15, 2018

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

Suhas P
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 16, 2018

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
TAGS
AUG Leaders

Atlassian Community Events