掲示板

How search users by expando?

thumbnail
12年前 に Natalie D によって更新されました。

How search users by expando?

Junior Member 投稿: 55 参加年月日: 12/02/06 最新の投稿
Hi

Does somebody know how to write DynamicQuery that search through the database also by custom fields (AKA expando fields)?
My main problem is that custom fields aren't additional columns inside table that they are extending.

I do not even know whether it is possible or not. Any ideas folks?

Natalie
thumbnail
12年前 に André Bunse によって更新されました。

RE: How search users by expando? (回答)

Junior Member 投稿: 85 参加年月日: 12/03/16 最新の投稿
Hi Natalie,

i have no answer using "DynamicQuery", but "search users by expando" can be done with "ExpandoValueLocalServiceUtil"

here is a snippet to get all users with custom field "newsletter"

    //  Set search parameter    
    String customAttributeName = "newsletter";
    long companyId = PortalUtil.getDefaultCompanyId();
    long classNameId = ClassNameLocalServiceUtil.getClassNameId(User.class);
    
    List<expandovalue> values = ExpandoValueLocalServiceUtil.getColumnValues(
            companyId, 
            classNameId, 
            ExpandoTableConstants.DEFAULT_TABLE_NAME, 
            customAttributeName,
            -1,
            -1
            );
    
    // create an arraylist to store user objects
    List<user> users = new ArrayList<user>();
    // temp user object
    User user;       

    // iterate through list of ExpandoValues and for each
    // element try to find corresponding user object
    for(int i = 0; i &lt; values.size(); i++) {
      long userId = values.get(i).getClassPK();
      try {
        user = UserLocalServiceUtil.getUser(userId);
        users.add(user);
      } 
      catch(NoSuchUserException e) { 
         // user with this primary key was not found in DB           
      }
    }
</user></user></expandovalue>



HTH
André
thumbnail
12年前 に David H Nebinger によって更新されました。

RE: How search users by expando? (回答)

Liferay Legend 投稿: 14917 参加年月日: 06/09/02 最新の投稿
The user object is not bound w/ the expando objects directly, so you cannot build a DQ that would do what you're after.

Andre's answer is the one that you'll need to go with.
thumbnail
12年前 に Riccardo Ferrari によって更新されました。

RE: How search users by expando? (回答)

Regular Member 投稿: 139 参加年月日: 10/11/13 最新の投稿
Hi,

You can use DynamicQuery to search user by their Expando attributes. You can use DynamicQuery to develop query joins (it get translated into "select ... from (select ...)"), here is the post where I started from:
http://www.liferay.com/community/forums/-/message_boards/message/1817322

The drawback is that DynamicQuery on Expando attribute are very poor in performances (I think due to lack of index on ExpandoValue.data_)

Regards
thumbnail
12年前 に Natalie D によって更新されました。

RE: How search users by expando?

Junior Member 投稿: 55 参加年月日: 12/02/06 最新の投稿
All Your responses are extremely helpful.

I'll come back after Easter and share my experience trying both ways.

Regards!
Natalie
11年前 に Atul Patel によって更新されました。

RE: How search users by expando?

New Member 投稿: 18 参加年月日: 12/01/12 最新の投稿
Has anyone tried to search via the lucene index instead?

The idea is that if you know you may need to search for this attribute in the future, modify the userIndexer to add the attribute to lucene... and then use the lucene search mechanism instead of db query.

I'll try it when I get a chance but wanted to put this out there in case it helps someone before I get a chance to try this out.
11年前 に Alex Curtui によって更新されました。

RE: How search users by expando?

Junior Member 投稿: 30 参加年月日: 12/11/08 最新の投稿
Atul Patel:
Has anyone tried to search via the lucene index instead?

The idea is that if you know you may need to search for this attribute in the future, modify the userIndexer to add the attribute to lucene... and then use the lucene search mechanism instead of db query.

I'll try it when I get a chance but wanted to put this out there in case it helps someone before I get a chance to try this out.



Have you tried it? If so, please share the process.

Thank you!