Forums

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

UserSearchService not returning expected numbers

PD Sheehan
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.
October 12, 2020

Hi all

I'm a little perplexed by an issue I've been having since I tried to stop using UserManager.getAllUsers or UserManager.getAllApplicationUsers and replaced it with UserSearchService as recommended by the deprecation notice.

However, UserSearchService always seems to be coming up short.

See this example:2020-10-12 11_58_31-Script Console - https___projects.qad.com_plugins_servlet_scriptrunner_admin_con.png

My UserSearchParams includes InactiveUsers and excludes active. When I compare that to allApplicationUsers and then filter for inactive, I get different numbers.

When I manually (in the UI) search for each of the users missing from the search results,  they are coming up as expected.

Note I included an image of inactive user search. But I get the same with all users (difference of 206) or for active only search (difference of  157)

What am I missing? Is indexing involved in the UserSearchService?  If so, any thoughts on how to refresh this index without doing a full re-index?

Thanks

UPDATE: After a full locked re-index, the numbers almost match (off by one). So any idea how to re-index users only?

UPDATE2:

Ok, I thought I had found a potential way to re-index just the missing users...

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.bc.user.search.UserSearchParams
import org.apache.lucene.analysis.Analyzer
import org.apache.lucene.store.Directory
import org.apache.lucene.store.RAMDirectory
import com.atlassian.jira.bc.user.search.DirectoryUserIndexer
import com.atlassian.jira.bc.user.search.UserNameAnalyzer

def userManager = ComponentAccessor.userManager
def crowdService = ComponentAccessor.crowdService
def luceneDirectory = new RAMDirectory();
def luceneAnalyzer = new UserNameAnalyzer();
def indexer = new DirectoryUserIndexer(luceneDirectory, luceneAnalyzer);
def userSearchService = ComponentAccessor.getComponent(UserSearchService)

def reindexed = false
def userSearchParams = new UserSearchParams(true, true,true, false, null, null,null, 10000)
def searchedUsers = userSearchService.findUsers("", userSearchParams)

def allUsers = userManager.allUsers
log.info "AllUsers user count: ${allUsers.size()}"
log.info "UserSearchService user count: ${searchedUsers.size()}"
def missing = allUsers - searchedUsers
log.info "Missing user count: ${missing.size()}"

missing.each{user->
reindexed = true
indexer.replaceAllUsers{consumer ->
consumer.accept(crowdService.getUser(user.name))
}
}
if(reindexed){
searchedUsers = userSearchService.findUsers("", userSearchParams)
log.info "UserSearchService user count after indexing: ${searchedUsers.size()}"
} else {
log.info "Nothing to re-index"
}

But after running it, I still get different counts:

2020-10-12 16:06:52,194 INFO [runner.ScriptBindingsManager]: AllUsers user count: 7702 
2020-10-12 16:06:52,194 INFO [runner.ScriptBindingsManager]: UserSearchService user count: 7503
2020-10-12 16:07:12,841 INFO [runner.ScriptBindingsManager]: Missing user count: 206
2020-10-12 16:07:13,424 INFO [runner.ScriptBindingsManager]: UserSearchService user count after indexing: 7503

So I'm not sure if that method for re-indexing users is actually valid.

0 answers

Suggest an answer

Log in or Sign up to answer