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

Efficient way to count label usage within a space?

Stefan Ernst
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.
November 30, 2015

I'm trying to retrieve the number of pages with a given label from a space. Unfortunately, using the labelManager it seems a bit inefficient.

This:

List<ContentEntityObject> results = labelManager.getContentInSpaceForLabel(0, 30000, spaceKey, labelManager.getLabel(label)).getList();

totalcount += results.size();

 

is really slow, it takes 11 seconds for 16000 results. Does anyone know a better way?

 

Thanks in advance

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

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.
December 1, 2015

Labels are indexed by the internal Lucene search (under labelText), so if you can use a search (with SearchManager?), then you should be able to return all results of pages with any combination of and/or that you need within 1 sec.

Stefan Ernst
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 1, 2015

Hey Stephen, I tried this, however all my implementations return 0 results. First one SearchQuery inSpaceQuery = new InSpaceQuery(spaceKey); SearchQuery labelQuery = new LabelQuery(label); SearchQuery andQuery = BooleanQuery.andQuery(inSpaceQuery,labelQuery); ContentSearch search = new ContentSearch(andQuery, new ModifiedSort(SearchSort.Order.DESCENDING), SiteSearchPermissionsSearchFilter.getInstance(), 0, 30000); try { SearchResults searchResults = searchManager.search(search); totalcount += searchResults.getUnfilteredResultsCount(); } catch (InvalidSearchException e) { log.error(e.getMessage()); } second one: DefaultPredefinedSearchBuilder predefinedSearchBuilder = new DefaultPredefinedSearchBuilder(); SearchQueryParameters searchQueryParameters = new SearchQueryParameters(); searchQueryParameters.setSpaceKey(spaceKey); HashSet<String> labelSet = new HashSet<String>(); labelSet.add(label); searchQueryParameters.setLabels(labelSet); searchQueryParameters.setContentType(ContentTypeEnum.PAGE); ISearch search = predefinedSearchBuilder.buildSiteSearch(searchQueryParameters,0,30000); try { SearchResults searchResults = searchManager.search(search); totalcount += searchResults.getUnfilteredResultsCount(); } catch (InvalidSearchException e) { log.error(e.getMessage()); }

1 vote
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.
November 30, 2015

Hi Stefan,

Not sure if it makes any difference but have you tried:

totalcount += labelManager.getContentInSpaceForLabel(0, 30000, spaceKey, labelManager.getLabel(label)).getCount();

 

 

Stefan Ernst
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.
November 30, 2015

Hey Volodymyr, it does help some. I got it down to 7 seconds. However I was hoping for a way to get it < 1 sec I will probably look at how getContentInSpaceForLabel is implemented, maybe it will give me a clue :)

Stefan Ernst
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.
November 30, 2015

Ok this method gets the results directly from DAO so I guess theres no optimizing there. I was hoping for a method to retrieve it from the search index

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.
November 30, 2015

Stefan, I guess that currently you are calling the getContentInSpaceForLabel for few space in loop and separate queries are fired against the db. I see there is getContentInSpacesForAllLabels that should do the job in single query.

Stefan Ernst
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.
November 30, 2015

Hey Volodymyr, Javadoc says: Retrieve current ContentEntityObjects in the given space which are labelled with ALL provided labels. which means it would only yield pages with label A AND B not A OR B. I need the latter, I need to find all pages with one of the provided labels

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.
November 30, 2015

I thought you are iterating spaces but I see you are looping labels. Looks like no method for you :-(.

TAGS
AUG Leaders

Atlassian Community Events