Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Aldi Tirane
Indexed Search on Custom Attribute
March 20, 2013 4:08 AM
Answer

Aldi Tirane

Rank: Junior Member

Posts: 25

Join Date: October 23, 2012

Recent Posts

Hello to everyone,

I have a large number of organizations and a custom attribute callled 'NIPT' on the liferay Organization entity. I want to make a search n this attribute. For now i am using a linear research scanning one by one all the list of organizations. All i want is to perform a indexed search on this attribute. Here is my actual code:

 1
 2List<Organization> listResult = new ArrayList<Organization>();
 3List<Organization> all_Organizations = OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
 4                   
 5for(int i = 0; i< all_Organizations.size(); i++)
 6{
 7        if(searchTerms.getKeywords() != null)
 8         {
 9        Object tempValue =  all_Organizations.get(i).getExpandoBridge().getAttribute("Nipt");
10        if(tempValue != null)
11        {
12            String niptValue = tempValue.toString();
13            if(niptValue != null &&
14                    niptValue.toLowerCase().contains(searchTerms.getKeywords().toLowerCase()))
15            {
16                listResult.add(all_Organizations.get(i));
17            }
18        }
19    }
20}


Any help would be appreciated.
Aldi Tirane
RE: Indexed Search on Custom Attribute
March 21, 2013 1:25 AM
Answer

Aldi Tirane

Rank: Junior Member

Posts: 25

Join Date: October 23, 2012

Recent Posts

Anyone that have had a similiar problem?

Thanks.

Aldi Tirane:
Hello to everyone,

I have a large number of organizations and a custom attribute callled 'NIPT' on the liferay Organization entity. I want to make a search n this attribute. For now i am using a linear research scanning one by one all the list of organizations. All i want is to perform a indexed search on this attribute. Here is my actual code:

 1
 2List<Organization> listResult = new ArrayList<Organization>();
 3List<Organization> all_Organizations = OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
 4                   
 5for(int i = 0; i< all_Organizations.size(); i++)
 6{
 7        if(searchTerms.getKeywords() != null)
 8         {
 9        Object tempValue =  all_Organizations.get(i).getExpandoBridge().getAttribute("Nipt");
10        if(tempValue != null)
11        {
12            String niptValue = tempValue.toString();
13            if(niptValue != null &&
14                    niptValue.toLowerCase().contains(searchTerms.getKeywords().toLowerCase()))
15            {
16                listResult.add(all_Organizations.get(i));
17            }
18        }
19    }
20}


Any help would be appreciated.
Rahul Pande
RE: Indexed Search on Custom Attribute
March 21, 2013 11:54 PM
Answer

Rahul Pande

Rank: Regular Member

Posts: 218

Join Date: July 6, 2010

Recent Posts

Hi Aldi,

Default organization search in Liferay uses indexer search method and it internally searches organization custom attributes as well. You can find all the methods in OrganizationLocalServiceImpl.java class


Thanks
Rahul
Oliver Bayer
RE: Indexed Search on Custom Attribute
March 22, 2013 2:25 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 829

Join Date: February 18, 2009

Recent Posts

Hi Aldi,

if I understand your requirement correctly you don't want to retrieve all organizations and then search the list for a given custom attribute right? Then you can search the other way round. You can create a custom query or you can use the Expando*LocalServiceUtil classes to retrieve the data this way.

HTH Oli
Aldi Tirane
RE: Indexed Search on Custom Attribute
March 30, 2013 2:04 AM
Answer

Aldi Tirane

Rank: Junior Member

Posts: 25

Join Date: October 23, 2012

Recent Posts

Thanks for your answer.

Probably you are talking about this method
1OrganizationLocalServiceUtil.search(companyId, parentOrganizationId, keywords, params, start, end, sort)


where in "params" you put the pair customAttribute/attributeValue. But this seems it doesn't work.

Anyway thanks for your response.
Aldi Tirane
RE: Indexed Search on Custom Attribute
March 30, 2013 2:14 AM
Answer

Aldi Tirane

Rank: Junior Member

Posts: 25

Join Date: October 23, 2012

Recent Posts

Hi Oliver, and thanks for your answer,

Oliver Bayer:
Hi Aldi,

if I understand your requirement correctly you don't want to retrieve all organizations and then search the list for a given custom attribute right?

HTH Oli


Yes that is what i want.

Oliver Bayer:

Then you can search the other way round. You can create a custom query or you can use the Expando*LocalServiceUtil classes to retrieve the data this way.
HTH Oli


Can you explain a little bit more.

Thanks
Aldi Tirane
RE: Indexed Search on Custom Attribute
March 30, 2013 3:57 AM
Answer

Aldi Tirane

Rank: Junior Member

Posts: 25

Join Date: October 23, 2012

Recent Posts

The way i resolve this issue using "ExpandoValueLocalServiceUtil". Now the result comes very fast and there is no need to scan the organizations list.

 1                  List<Organization> listResult = new ArrayList<Organization>();
 2            
 3                    String customAttributeName = "Nipt";
 4                   
 5                    long classNameId = ClassNameLocalServiceUtil.getClassNameId(Organization.class);
 6                    List<ExpandoValue> values = ExpandoValueLocalServiceUtil.getColumnValues(
 7                               companyId,
 8                               classNameId,
 9                                 ExpandoTableConstants.DEFAULT_TABLE_NAME,
10                             customAttributeName,
11                             searchTerms.getKeywords(),
12                            -1,
13                            -1
14                            );
15                   
16               
17                    Organization org;      
18               
19                    for(int i = 0; i < values.size(); i++) {
20                        long userId = values.get(i).getClassPK();
21                        try {
22                            org = OrganizationLocalServiceUtil.getOrganization(userId);
23                            listResult.add(org);
24                        }
25                        catch(NoSuchOrganizationException e) {
26                        }
27                    }
28   


Thanks for your answers.

Aldi