Fórumok

Indexed Search on Custom Attribute

Aldi Tirane, módosítva 11 év-val korábban

Indexed Search on Custom Attribute

Junior Member Bejegyzések: 25 Csatlakozás dátuma: 2012.10.23. Legújabb bejegyzések
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:


List<organization> listResult = new ArrayList<organization>();
List<organization> all_Organizations = OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
					
for(int i = 0; i&lt; all_Organizations.size(); i++)
{
        if(searchTerms.getKeywords() != null)
         {
		Object tempValue =  all_Organizations.get(i).getExpandoBridge().getAttribute("Nipt");
		if(tempValue != null)
		{
			String niptValue = tempValue.toString();
			if(niptValue != null &amp;&amp; 
					niptValue.toLowerCase().contains(searchTerms.getKeywords().toLowerCase()))
			{
				listResult.add(all_Organizations.get(i));
			}
		}
	}
}</organization></organization></organization>


Any help would be appreciated.
Aldi Tirane, módosítva 11 év-val korábban

RE: Indexed Search on Custom Attribute

Junior Member Bejegyzések: 25 Csatlakozás dátuma: 2012.10.23. Legújabb bejegyzések
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:


List<organization> listResult = new ArrayList<organization>();
List<organization> all_Organizations = OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
					
for(int i = 0; i&lt; all_Organizations.size(); i++)
{
        if(searchTerms.getKeywords() != null)
         {
		Object tempValue =  all_Organizations.get(i).getExpandoBridge().getAttribute("Nipt");
		if(tempValue != null)
		{
			String niptValue = tempValue.toString();
			if(niptValue != null &amp;&amp; 
					niptValue.toLowerCase().contains(searchTerms.getKeywords().toLowerCase()))
			{
				listResult.add(all_Organizations.get(i));
			}
		}
	}
}</organization></organization></organization>


Any help would be appreciated.
thumbnail
Rahul Pande, módosítva 11 év-val korábban

RE: Indexed Search on Custom Attribute

Expert Bejegyzések: 310 Csatlakozás dátuma: 2010.07.07. Legújabb bejegyzések
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
Aldi Tirane, módosítva 11 év-val korábban

RE: Indexed Search on Custom Attribute

Junior Member Bejegyzések: 25 Csatlakozás dátuma: 2012.10.23. Legújabb bejegyzések
Thanks for your answer.

Probably you are talking about this method
OrganizationLocalServiceUtil.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.
Oliver Bayer, módosítva 11 év-val korábban

RE: Indexed Search on Custom Attribute

Liferay Master Bejegyzések: 894 Csatlakozás dátuma: 2009.02.18. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Indexed Search on Custom Attribute

Junior Member Bejegyzések: 25 Csatlakozás dátuma: 2012.10.23. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Indexed Search on Custom Attribute

Junior Member Bejegyzések: 25 Csatlakozás dátuma: 2012.10.23. Legújabb bejegyzések
The way i resolve this issue using "ExpandoValueLocalServiceUtil". Now the result comes very fast and there is no need to scan the organizations list.

			      List<organization> listResult = new ArrayList<organization>();
			
					String customAttributeName = "Nipt";
					
					long classNameId = ClassNameLocalServiceUtil.getClassNameId(Organization.class);
					List<expandovalue> values = ExpandoValueLocalServiceUtil.getColumnValues(
					           companyId, 
					           classNameId, 
				          	   ExpandoTableConstants.DEFAULT_TABLE_NAME, 
							 customAttributeName,
							 searchTerms.getKeywords(),
							-1,
							-1
							);
					
				
					Organization org;       
				
					for(int i = 0; i &lt; values.size(); i++) {
						long userId = values.get(i).getClassPK();
						try {
							org = OrganizationLocalServiceUtil.getOrganization(userId);
							listResult.add(org);
						} 
						catch(NoSuchOrganizationException e) { 
						}
					}
	</expandovalue></organization></organization>


Thanks for your answers.

Aldi