Sorting by multiple keys
Managed by | Updated .
It is sometimes desirable to sort the search results by more than one key. For example you may wish to sort by type then alphabetically by title.
Unfortunately Funnelback only supports result sorting on a single key. This article provides a workaround that explains how sorting can be achieved by more than one key.
Because Funnelback only allows sorting on a single key the only way to achieve sorting by more than one key is to pre-generate a sort field within the metadata. This field needs to concatenate the values of the two keys that need to be sorted on with the primary sort field being concatenated to the secondary sort field.
This can be achieved in a number of different ways. Ideally the field should be generated and added to the source content downloaded by Funnelback. If indexing data from a database or CMS it's usually quite straightforward to configure the source system to generate an additional metadata or database field that is a concatenation of the two fields.
If you don't have control over the data source then it is possible to write a filter that extracts the two fields from the source data and generates a third field.
If you wish to sort on more than one key then you'll need to generate a sort field that concatenates the fields you wish to sort on together (in a way that will sort alphabetically) in your metadata and sort on that. If exporting from a DB it's usually quite straightforward to generate an extra sort field in the DB view that you are indexing.
Once the sort field is generated ensure that this field is included in the metamap (type 0 is sufficient) and configure the search to sort on this new field.
A similar philosophy or generating a sort field can be applied if you wish to apply some special rules to you alphabetical search such as ensuring numbers within a string a sorted correctly, or the sort ignores a leading The.
Example: sort by type and title
Consider the following data
|Book||Harry Potter and the Goblet of Fire|
|DVD||Harry Potter and the Goblet of Fire|
To sort by type then title would require a third field, sortKey to be generated:
|Book||Great Expectations||BookGreat Expectations|
|Book||Harry Potter and the Goblet of Fire||BookHarry Potter and the Goblet of Fire|
|Book||The BFG||BookThe BFG|
|DVD||Harry Potter and the Goblet of Fire||DVDHarry Potter and the Goblet of Fire|
|DVD||Star Wars||DVDStar Wars|
The following would then be added to the metamap.cfg
And sorting would then be achieved by adding