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

How can I read/fetch content properties over java search api?

Martin Wiegand December 7, 2015

Hi, Iam doing search requests via the Confluence Java search api. My content properties I added to a BlogPosts are not in the search results. How can I achieve that?

 

Code to add content property:

JsonString properties = new JsonString("{\"displaytemplate\":\"imageonly\"}");


JsonContentProperty property = JsonContentProperty.builder().content(blogPostContent)
                            .key("pd_stream_plugin_data").value(properties).build();


contentPropertyService.create(property);

 

My content extractor:

<content-property-index-schema key="prodyna-stream-index-schema-module-key">
		<key property-key="pd_stream_plugin_data">
			<extract path="displaytemplate" type="string" />
		</key>
	</content-property-index-schema>

My search code (simplyfied):

String resultQuery = "type:blogpost";
SearchQueryParameters params = new SearchQueryParameters();
params.setSort(MODIFIED_SORT);
params.setQuery(resultQuery);

ISearch search = predefinedSearchBuilder.buildSiteSearch(params, start, limit);
 
SearchResults searchResults = this.searchManager.search(search);


List<SearchResult> results = searchResults.getAll();
 
// !!! my search blog post are in 'results', but not the content property 
// "content-property-pd_stream_plugin_data-displaytemplate", wich I can 
// see in the index when opening with luke tool. What Iam doing wrong? I 
// tried to add the content-property fields as requestedFields param, 
// but this also does not work. !!!
Regards,
Martin 

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Martin Wiegand January 3, 2016

Hi Alex,

I found out that it is working with the Confluence REST search API. For instance this is a working request of my plugin:

/rest/api/content/search?cql=content.property[pd_stream_plugin_data].displaytemplate = imageonly

Programmatically I did not continued with my plugin but I think I'm using the wrong API. I think the API from my first post does not accept CQL (Confluence Query Language) which supports content property queries.

0 votes
Volodymyr Krupach
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 3, 2016

Hi Martin,

The search results always return content objects and does not return properties tied to the content objects.

When you get results you can iterate content objects and retrieve the properties as answered by @Alex Yasurek.

0 votes
Alex Yasurek
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 2, 2016

 

I ran into the same issue and found that by getting the id of each page I was able to create a ContentEntityObject. From there I was able to retrieve the custom content properties for each page. I assume it should work the same for blog posts. The next issue I ran into was getting the ID of each page but was able to easily get that if I use the Rest API instead. I am still not sure how to retrieve the page ID from a SearchResults object though

 

Here is a sample of the code I used:

private ContentEntityManager contentEntityManager;

private ContentPropertyManager contentPropertyManager;

............

(this would go in the execute method of the macro)

ContentEntityObject page  = contentEntityManager.getById(1605639); //id of page

contentPropertyManager.getTextProperty(page, "com.custom.property"); //replace "com.custom.property" with whatever you named the custom property

............

public void setContentPropertyManager(ContentPropertyManager contentPropertyManager){
this.contentPropertyManager = contentPropertyManager;
}

public void setContentEntityManager(ContentEntityManager contentEntityManager){
this.contentEntityManager = contentEntityManager;
}

 

Hopes this helps.

Volodymyr Krupach
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 3, 2016

Hi Alex, for locating the page please see methods in PageManager. Particularly you may be interested in getting pages by space: https://docs.atlassian.com/confluence/latest/com/atlassian/confluence/pages/PageManager.html#getPages-com.atlassian.confluence.spaces.Space-boolean-

Alex Yasurek
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 4, 2016

HI, Thanks but issue I was also having is that I needed to use logical operators, like only retrieve pages that have label a OR Label b. Those methods don't allow for that so I had to use a search.

0 votes
Midori
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.
December 8, 2015

Martin, this is just wild guessing, but have you tried to update the index after you added the content, but before you run the search?

I could very easily imagine that simply adding a content property wouldn't automatically update the index, but this is something you explicitly have to take care of.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events