留言板

How to get rows ordered by a localized field

thumbnail
Santiago Pérez de la Cámara,修改在6 年前。

How to get rows ordered by a localized field

Junior Member 帖子: 53 加入日期: 12-3-23 最近的帖子
How to get rows ordered by a localized field.

My service.xml file defines an entity called ‘InstitutionType’, which defines a localized string field named ‘name’, as it can be seen below, and I wonder how I should proceed to get the entity’s instances ordered by this localized field.

<entity name="InstitutionType" local-service="true" remote-service="false">
             <column name="institutionTypeId" type="long" primary="true" convert-null="false"></column>
             <column name="name" type="String" localized="true"></column>
             <order by="asc">
                    <order-column name="name"></order-column>
             </order>
</entity>


On one hand, the methods automatically generated by Service Builder only have a “locale” parameter in the persistence object, but not in the InstitutionTypeLocalServiceUtil class.

On the other hand, the returned list of the method "InstitutionTypeLocalServiceUtil.getInstitutionTypes(start, end)" is ordered by ”Name” field, but according to Name field’s xml-content, and without taking into account the localized values of the xml content.

Does anyone know if Liferay provides some kind of utility that deals with this issue? Or, should I have to implement my own “wrapped” methods to get the result list and then create a second list ordered by the localized values of the initial list?

Thanks,
Santiago
thumbnail
Jorge Díaz,修改在6 年前。

RE: How to get rows ordered by a localized field (答复)

Liferay Master 帖子: 753 加入日期: 14-1-9 最近的帖子
That behavior is a limitation of current localization implementation using xmls.

Future Liferay 7.1 will add a new localization implementation using an additional table. (xml will be also available)

In Liferay 6.2 and 7.0 you have to apply a workaround:
- For example Liferay code usually index the localized data in elasticsearch/solr/lucene (with an indexer) and it queries that index instead of database.
- If you don't want to use the index, you have to sort data after quering the database, but be careful with throughout!
thumbnail
Santiago Pérez de la Cámara,修改在6 年前。

RE: How to get rows ordered by a localized field

Junior Member 帖子: 53 加入日期: 12-3-23 最近的帖子
Thanks Jorge!