Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Aldi Tirane
Indexed Search on Custom Attribute
20 marzo 2013 4.08
Risposta

Aldi Tirane

Punteggio: Junior Member

Messaggi: 25

Data di Iscrizione: 23 ottobre 2012

Messaggi recenti

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
21 marzo 2013 1.25
Risposta

Aldi Tirane

Punteggio: Junior Member

Messaggi: 25

Data di Iscrizione: 23 ottobre 2012

Messaggi recenti

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
21 marzo 2013 23.54
Risposta

Rahul Pande

Punteggio: Regular Member

Messaggi: 220

Data di Iscrizione: 6 luglio 2010

Messaggi recenti

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
22 marzo 2013 2.25
Risposta

Oliver Bayer

Punteggio: Liferay Master

Messaggi: 867

Data di Iscrizione: 18 febbraio 2009

Messaggi recenti

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
30 marzo 2013 2.04
Risposta

Aldi Tirane

Punteggio: Junior Member

Messaggi: 25

Data di Iscrizione: 23 ottobre 2012

Messaggi recenti

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
30 marzo 2013 2.14
Risposta

Aldi Tirane

Punteggio: Junior Member

Messaggi: 25

Data di Iscrizione: 23 ottobre 2012

Messaggi recenti

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
30 marzo 2013 3.57
Risposta

Aldi Tirane

Punteggio: Junior Member

Messaggi: 25

Data di Iscrizione: 23 ottobre 2012

Messaggi recenti

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