Sorting using localizable and indexable fields from structure is not working
How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!
While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.
Legacy Article
You are viewing an article from our legacy "FastTrack"
publication program, made available for informational purposes. Articles
in this program were published without a requirement for independent
editing or verification and are provided"as is" without
guarantee.
Before using any information from this article, independently verify its
suitability for your situation and project.
Issue
- When trying to get a search result, sorted by some localizable and indexable fields defined in a structure, the configured Sort widget does not work properly.
- The issue can be reproduced with these steps:
- Configure a site with two locales. For example, Spanish (default) and English.
- Define a structure with some localizable and indexable fields. For example, these following fields:
articleName
price
The structure ID might be, for example, 1184008.
- Configure a Custom Filter (search widget) to filter by structure. Following our example, configure it for the structure with ID 1184008.
- Configure a Sort (search widget) including the previous structure fields. For example:
Label: Name
Field: ddm__keyword__1184008__articleName_es_ES
Label: Price ASC
Field: ddm__keyword__1184008__price_es_ES+
Label: Price DESC
Field: ddm__keyword__1184008__price_es_ES-
- Execute a search using the default locale.The expected and observed behavior is that the results are correctly sorted, both for predefined Sort widget fields (
relevance, title, modified+, modified-, createDate+, createDate-, userName) and the added ones (ddm__keyword__1184008__articleName_es_ES, ddm__keyword__1184008__price_es_ES+ , ddm__keyword__1184008__price_es_ES-).
- Change the site locale and repeat the search. The observed behavior is that the results are correctly sorted only for the predefined Sort widget fields but no for the added ones.
Resolution
- There are two key points to take into account:
- When configuring the Sort widget, the field values must be defined without any suffixed locale. In our example:
Label: Name
Field: ddm__keyword__1184008__articleName
Label: Price ASC
Field: ddm__keyword__1184008__price+
Label: Price DESC
Field: ddm__keyword__1184008__price-
- Every field defined as localizable in the structure must be filled with a value on each locale translation. If you want a field to be sorted using the same value for every locale then the field must not be defined as localizable.
- The root cause is that the sort operation adds a locale for every localizable field defined in the Sort widget configuration so it is not necessary to add one.
Did this article resolve your issue ?