Search can only sort and filter on
resources that actually have a database
column. Zotonic’s resources are stored in a serialized form. This
allows you to very easily add any property to any resource but
you cannot sort or filter on them until you make database columns
for these properties.

The way to take this on is using the “custom pivot” feature. A custom
pivot table is an extra database table with columns in which the props
you define are copied, so you can filter and sort on them.

Say you want to sort on a property of the resource called requestor.

Create (and export!) an init/1 function in your site where you define a custom pivot table:

This will fill the ‘requestor’ property for every entry in your
database, when the resource is pivoted.

Recompile your site and restart it (so the init function is called)
and then in the admin under ‘System’ -> ‘Status’ choose ‘Rebuild
search indexes’. This will gradually fill the new pivot table. Enable
the logging module and choose “log” in the admin menu to see the pivot
progress. Once the table is filled, you can use the pivot table to do
sorting and filtering.

Or you can filter on it. The pivot tables are aliassed with a number
in order of their occurrence, with the first pivot table aliassed as
pivot1. This allows you to do filtering on custom fields like
this: