Foren

How search users by expando?

thumbnail
Natalie D, geändert vor 12 Jahren.

How search users by expando?

Junior Member Beiträge: 55 Beitrittsdatum: 06.02.12 Neueste Beiträge
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
André Bunse, geändert vor 12 Jahren.

RE: How search users by expando? (Antwort)

Junior Member Beiträge: 85 Beitrittsdatum: 16.03.12 Neueste Beiträge
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
David H Nebinger, geändert vor 12 Jahren.

RE: How search users by expando? (Antwort)

Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
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
Riccardo Ferrari, geändert vor 12 Jahren.

RE: How search users by expando? (Antwort)

Regular Member Beiträge: 139 Beitrittsdatum: 13.11.10 Neueste Beiträge
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
Natalie D, geändert vor 12 Jahren.

RE: How search users by expando?

Junior Member Beiträge: 55 Beitrittsdatum: 06.02.12 Neueste Beiträge
All Your responses are extremely helpful.

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

Regards!
Natalie
Atul Patel, geändert vor 11 Jahren.

RE: How search users by expando?

New Member Beiträge: 18 Beitrittsdatum: 12.01.12 Neueste Beiträge
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.
Alex Curtui, geändert vor 11 Jahren.

RE: How search users by expando?

Junior Member Beiträge: 30 Beitrittsdatum: 08.11.12 Neueste Beiträge
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!