cancel
Showing results for 
Search instead for 
Did you mean: 

Search users with lucene

chicco0386
Champ on-the-rise
Champ on-the-rise
Hi all,
I must to search the user by first and last name and after assign to him a workflow, so assign to bpm:assignee variable the node that return me the lucene search, this lifecycle is correct?

I've this piece of code:
function getUsername(firstName, lastName) {
   logger.log("getUsername, entrato");
   var users = search.luceneSearch("+@cm\\:firstName:\"" + firstName + "\" +@cm\\:lastName:\"" + lastName + "\"");
   for ( var i = 0; i < users.length; i++) {
      logger.log("getUsername, utente "+i+" = "+users.userName);
   }
   logger.log("getUsername, uscito");
}
getUsername("firstName", "lastName");
It returns nothing, but if I change the query with "TEXT:alfresco" it returns some result.

Can you help me please?
Thank you
3 REPLIES 3

amitabhandari1
Champ in-the-making
Champ in-the-making
Hi chicco0386 ,

Can you check the same query using NodeBrowser ?

Thanks,

chicco0386
Champ on-the-rise
Champ on-the-rise
I try to execute it inside the node browser in the alfrescoUserStore and SpaceStore, but it doesn't work…
Can you suggest me something? For example a new query?

THANK YOU

chicco0386
Champ on-the-rise
Champ on-the-rise
For the moment I use this lucene query:
+@cm\:firstName:firstNam* +@cm\:lastName:lastName*
It works, but for example if I must to search "Valentina Rossi", so use this query:
+@cm\:firstName:valentin* +@cm\:lastName:ross*
it can be return the user "Valentino Rosso" (or others combinations) and this is not perfect.

This is the updated javascript function:
function getUsername(firstName, lastName) {
   logger.log("getUsername, entrato");
   var userName = null;
   var firstNameToSearch = firstName.substring(0,firstName.length-1).concat("*").toLowerCase();
   var lastNameToSearch = lastName.substring(0,lastName.length-1).concat("*").toLowerCase();
   var luceneQuery = "+@cm\\:firstName:" + firstNameToSearch + " +@cm\\:lastName:" + lastNameToSearch;
   logger.log("getUsername, eseguo la query ["+luceneQuery+"]");
   var users = search.luceneSearch(luceneQuery);
   if (users.length > 0) {
      var userName = users[0].properties["cm:userName"];
      logger.log("getUsername, utente " + firstName + "," + lastName + " = " + userName);
   } else {
      logger.log("getUsername, nessun utente " + firstName + "," + lastName + " trovato");
   }
   logger.log("getUsername, uscito");
   return userName;
}