You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
We are using a custom search query with ScriptRunner followed by this article :
https://developer.atlassian.com/server/confluence/searching-using-the-v2-search-api/
The problem we have is that the query returns a lot of information we dont need or its duplicate, like the Content of the page is displayed with 3 different properties (resultExcerpt, content, sanitisedContent).
Our goal is:
1. To make the SearchManager return only the fields/properties we specify, title and content.
2. Optionally, reduce the content length to about 500 characters.
Looking in to the SearchManager interface javadoc, I see there is a method to return only the fields requested
search (ISearch search, Set<String> requestedFields)
Perform a search with a given criteria, the returns searchResults only have the fields requested in the projection filled out, no other fields are valid in the searchResult.
I could not figure out how I can make the proper
Set<String> requestedFields
I tried to make it work in many ways, but I always get:
com.atlassian.confluence.search.v2.ProjectedSearchResult
When I do .getClass I am getting the default
class com.atlassian.confluence.search.v2.DefaultSearchResults
Here is my pity attempt to make it work, from the Console
import com.atlassian.seraph.auth.DefaultAuthenticatorimport com.atlassian.confluence.user.UserAccessorimport com.atlassian.confluence.user.AuthenticatedUserThreadLocalimport com.atlassian.confluence.spaces.SpaceManagerimport com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.search.service.ContentTypeEnumimport com.atlassian.confluence.search.v2.SearchManagerimport com.atlassian.confluence.search.v2.searchfilter.SiteSearchPermissionsSearchFilterimport com.atlassian.confluence.search.v2.ContentSearchimport com.atlassian.confluence.search.v2.DefaultSearchResults
import com.atlassian.confluence.search.v2.query.*import com.atlassian.confluence.search.v2.sort.RelevanceSortimport com.atlassian.confluence.search.v2.SearchSort
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegateimport groovy.json.JsonBuilderimport groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMapimport javax.ws.rs.core.Responseimport org.codehaus.jackson.map.ObjectMapper
import java.util.HashSet
def searchManager = ComponentLocator.getComponent(SearchManager)
def paramQueryString = "ArticleThatWillBeDeleted"
def query = BooleanQuery.andQuery(new TextQuery(paramQueryString));def sort = new RelevanceSort();def searchFilter = SiteSearchPermissionsSearchFilter.getInstance();def searchContent = new ContentSearch(query, sort, searchFilter, 0, 100);
Set<String> requestedFields = new HashSet<String>();requestedFields.add("displayTitle");
def searchresult = searchManager.search(searchContent,requestedFields)
return searchresult.getAll()
Here is a sample of the output I am getting (when I use the JSON builder and call the API directly, because I dont know how to expand the return in the Console
{
"resultExcerpt": "",
"explain": {
"present": false,
"empty": true
},
"resultExcerptWithHighlights": "",
"extraFields": {
},
"displayTitleWithHighlights": ""
}
Without trying to use the requestedFields, the output looks something like this (I have only paste the first letters of the values)
displayTitle : A
handle : @
lastUpdateDescription :
ownerTitle :
spaceName : E
creatorUser : @
e
resultExcerpt : t
ownerType :
lastModifier : v
urlPath : /
resultExcerptWithHighlights : t
explain : @
lastModifierUser : @
e
extraFields : @
lastModificationDate : 2
type : p
content :
t
creationDate : 2
personalLabels : {
status : c
spaceKey : W
contentVersion : 1
creator : v
displayTitleWithHighlights : A
homePage : F
sanitisedContent : t
I allow the fact that I could have understand that all wrong, so I am open for suggestions to the problem I wanna solve.
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...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events