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
Community moderators have prevented the ability to post new answers.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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-
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.