Sorting

You may define the sorting method in the plugin configuration. Available options are relevance, title and date. More options may be added through third party extensions (see below Adding your own sorting options).

There are two sorting method options, one if a searchword was given and one if only filters have been used without a searchword. The reason for that is without a search word, you don't have a relevance ranking.

Default sorting is relevance descending if a searchword has been given and date descending if no search word has been given.

Sorting plugin options

You may also activate the "frontend sorting" feature. This allows the visitor to decide for a sorting method.

Sorting links in frontend

You may then choose the fields you want to allow sorting for. By default these are relevancy, date and title.

Adding your own sorting options

If you want other sorting options than relevance, date or title, you will have to

  • Extend the table tx_kesearch_index by the fields you want to use for sorting (for example mysortfield) (ext_tables.sql, TCA configuration). Note: Don't use an underscore _ in the field name and use a string type (TEXT, VARCHAR) as field type.
  • Register your sorting fields by hook registerAdditionalFields, so that they are written to the database.
  • Write your own indexer or extend an existing one that fills your new field during the indexing process.

You can find an example in the extension ke_search_hooks: https://extensions.typo3.org/extension/ke_search_hooks

// in ext_localconf.php:

// Register hook to register additional fields in the index table
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['registerAdditionalFields'][] =
   \MyVendor\KeSearchHooks\AdditionalIndexerFields::class;
Copied!
<?php
namespace MyVendor\KeSearchHooks;

/**
 * Class AdditionalIndexerFields
 * @package MyVendor\KeSearchHooks
 */
class AdditionalIndexerFields {
   public function registerAdditionalFields(&$additionalFields) {
      $additionalFields[] = 'mysorting';
   }
}
Copied!

Your new database field will automatically appear in the backend selection of sorting fields.

For the frontend sorting links you will have to add a label for your new sorting field.

The key of the field is the same as the field name, prepended with oderlink_, so in this case it would be orderlink_mysorting.

You can add the label in your extension's locallang file for locallang_searchbox.xlf as described in Multilangual support.