Sorting Search Results

Search results displayed in the Search Results widget are ordered by relevance score (as calculated by the search engine) by default. With the Sort widget, users can control the order of returned results.

Warning

Search Blueprints can also add sorting to the search page. Make sure you understand how these blueprint-added sorts interact with the Sort widget’s configuration.

Add the widget to a Search Page to begin sorting results.

Out of the box, you can order results in these ways as an alternative to relevance sorting:

  • alphabetically by Title
  • by the Modified date (newest first by default, or choose oldest first)
  • by the Create date (newest first by default, or choose oldest first)
  • alphabetically by the User that created each matching asset
Important

Exploring the fields in the index is important when using the Sort widget. See Exploring Indexed Fields for more details.

Choose from one of the Sort widget’s pre-configured sorting strategies or configure your own. You can explore the indexed fields to discover additional sort options.

You can also delete unwanted sort options from the widget.

Adding the Sort Widget to a Page

To get started with the Sort widget,

  1. Open the Add menu (Add) for the page and expand the Widgets section.

  2. From the Search category, drag the Sort widget onto the page.

Configuring the Sort Widget

Note

The Sort widget’s configuration screen is updated in Liferay 7.4 DXP Update 29+/CE GA 29+. For a period of time you can choose to use the older configuration screen by clicking the link Switch to Classic View.

Toggle between the classic Sort configuration and the newer, more intuitive configuration screen.

The option to use the classic configuration view will be removed in a future Update/GA.

From the Sort widget’s Configuration screen, you can

  • Disable the default Relevance sort option.
  • Edit existing Sort options
  • Delete options
  • Add new options

Users can re-order search results with the Sort widget.

Note

Relevance can be turned on/off, but not removed completely. When relevance is enabled, the default search engine behavior is used: results are sorted in descending order of relevance (highest scores first).

To access the widget configuration screen, open the widget Options menu (Options) and click Configuration.

Note

Before Liferay DXP 2025.Q1, the Configuration option appeared in the widget’s top-right corner.

Each Sort option has three settings: Indexed Field, Display Label, and Order.

Indexed Field: Enter the fieldName of the indexed field to sort. Most of the time this is a keyword field. Other acceptable options are date and any numeric datatype. There’s even a way to coerce text fields into behaving with the Sort widget (see below).

Display Label: Set the displayed label for the type of sort being configured.

Order: Choose to sort in ascending or descending order. See Controlling the Sort Order in the Classic Configuration if you’re using the classic view or if you’re on an earlier Liferay version that does not contain the updated configuration UI.

From the Sort widget's configuration, add, edit, or remove Sort options.

Changing the Default Sort Behavior

Out of the box, the Relevance option is first in the Sort widget’s list, making it the default sort applied to the page. Therefore, results are sorted by relevance when a search is executed. Searching by relevance is the expected default behavior for most users, but you can exert a different sort strategy on default searches by changing the first option in the Sort widget configuration.

To change the default sort option,

  1. Start editing the page where the Sort widget has been deployed.

  2. Click Options (Widget Options icon) in the widget header → Configuration.

    Note

    Before Liferay DXP 2025.Q1, the Configuration option appeared in the widget’s top-right corner.

  3. Click Add Add below the Relevance option.

  4. Duplicate the current Relevance option’s values—this ensures that Relevance is the second option in the list.

  5. Now change the top option. If you choose one of the existing options, make sure you remove the duplicate by clicking its Remove Minus.

  6. Save the configuration. Enter a search and see the new sort applied.

Finding Sortable Fields

To find the fields available for use in the Sort widget, Users with the proper permissions can navigate to Control PanelConfigurationSearch. From there, open the Field Mappings tab and browse the mappings for each index. Scroll to the properties section of the mapping and find any keyword field, date field, or a field with a numeric data type. The type field is instructive:

"type" : "keyword"

"type" : "date"

"type" : "long"

If you really must sort by a text field, add a new version of the field to the index with the type keyword. From the field mappings screen mentioned above, look at the firstName field in the index called liferay-[companyID]:

"firstName" : {
    "type" : "text",
    "store" : true
},
"firstName_sortable" : {
    "type" : "keyword",
    "store" : true
},

There’s a corresponding field with the suffix _sortable, and of the correct type for sorting (keyword). The sortable field got there via a portal property:

index.sortable.text.fields=firstName,jobTitle,lastName,name,screenName,title

All the text fields listed here have a fieldName_sortable counterpart created automatically in the index. To add more, copy this property into a portal-ext.properties file into your Liferay Home folder, add any new field names you must sort by, and restart the server.

See Exploring Indexed Fields for more details.

Adding New Sort Options

To sort by the new field or an existing field of the proper type, click the Add Option button.

Tip

Make sure to use the fieldName_sortable version of a text field in the widget configuration.

To add a new sort option that’s already of the proper data type, use the plus symbol below any option’s Field configuration and fill in the fields. The order of options here in the configuration screen matches the order in the select list when configuring the widget for search.

Editing and Deleting Sort Options

To edit an existing option, edit the text in its configuration section.

To delete an existing option, use the trash icon.

Controlling the Sort Order in the Classic Configuration

To control the order for the sort option in the Classic configuration, add a plus or minus symbol after the fieldName. Look how it’s done for the existing sort options labeled Created and Created (oldest first) to understand how it works:

Label: Created Field: createDate-

The - sign following the field name indicates that the order is descending. Sorting this way brings search results created most recently to the top of the list.

Label: Created (oldest first) Field: createDate+

The + sign following the field name indicates that the order is ascending. Sorting this way brings the oldest (by creation date) results to the top of the list.

Capabilities

Product

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy