Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Luis Toubes
Search Organizations with custom attributes
March 8, 2010 1:37 AM
Answer

Luis Toubes

Rank: New Member

Posts: 6

Join Date: January 7, 2010

Recent Posts

I need to find organizations through custom attributes. It is posible like users?

I tried to make a method, but always get an empty result

There is the code

 1
 2public Organization findOrganizationByMyId(Long companyId, String customId) throws PortalException, SystemException{
 3//There is not implemented function that find organizations by custom attributes
 4//I will implement one
 5Boolean active = true;
 6BooleanQuery fullQuery = BooleanQueryFactoryUtil.create();
 7BooleanQuery contextQuery = BooleanQueryFactoryUtil.create();
 8BooleanQuery customAttQuery = BooleanQueryFactoryUtil.create();
 9
10contextQuery.addRequiredTerm(Field.PORTLET_ID, PortletKeys.ENTERPRISE_ADMIN_ORGANIZATIONS);
11contextQuery.addRequiredTerm("active", active);
12       
13String customIdName = "customId";       
14ExpandoBridge expandoBridge = new ExpandoBridgeImpl(Organization.class.getName(), 0);
15UnicodeProperties properties = expandoBridge.getAttributeProperties(customIdName);
16
17if (GetterUtil.getBoolean(properties.getProperty(ExpandoBridgeIndexer.INDEXABLE))) {
18    int type = expandoBridge.getAttributeType(customIdName);
19
20    if ((type == ExpandoColumnConstants.STRING) &&    (Validator.isNotNull(orgLoeId))) {
21        customAttQuery.addRequiredTerm(customIdName, customId, true);
22    }
23}
24       
25fullQuery.add(contextQuery, BooleanClauseOccur.MUST);
26fullQuery.add(customAttQuery, BooleanClauseOccur.MUST);
27       
28       
29Sort sort = new Sort(orgLoeIdName, Sort.STRING_TYPE, Boolean.TRUE);
30       
31Hits hits = SearchEngineUtil.search(companyId, fullQuery, sort, 0, 20);
32       
33List<Document> hitsList = hits.toList();
34       
35if (hitsList.size() > 0){ //Get the first
36    long organizationId = GetterUtil.getLong(hitsList.get(0).get(PropertiesKeys.FIELD_ORGANIZATION_ID));
37
38return OrganizationLocalServiceUtil.getOrganization(organizationId);            
39}else {
40   return null;
41}


Any help??

Thanks
Gaurav Jain
RE: Search Organizations with custom attributes
November 2, 2011 12:25 AM
Answer

Gaurav Jain

Rank: Regular Member

Posts: 143

Join Date: January 31, 2011

Recent Posts

check ExpandoIndexer. It will help you.

It adds key in Query like this: "expando/custom attributes/{attribute name}"