Sort search results alphabetically

I want search results to be sorted alphabetically to keep similar titles and records together. I've seen this topic on both Codex and other posts, but I'm still confused. I understand that I need to add sorting parameters sort_field and sort_dir, but I'm not sure which file to put this code and where. Also, the php code seems specific to browsing, not search results. Can anyone help me out on this? Thank you!

The thread you linked to is out of date, and doesn't include the two different searches available. One is the item-specific search, which uses the browse page, and the other is the site-wide search on many record types. I'm guessing that you are talking about the site-wide search?

If so, this simple plugin should do the job. Just save this code in a new Sort folder in your plugin directory:

class SortPlugin extends Omeka_Plugin_AbstractPlugin
    protected $_filters = array('search_texts_browse_params');

    public function filterSearchTextsBrowseParams($params)
        $params['sort_field'] = 'title';
        $params['sort_dir'] = 'a';
        return $params;

Yes, a site-wide search. I passed this along to my coworker in IT, but the search results still are not alphabetized. Do I add this code to another file, or is this it?


There are two mechanisms to search items: the simple (header search box) and the advanced (on a dedicated page). Patrick's code works for the simple search if you create the plugin has he wrote (a folder Sort, and a file named SortPlugin.php with the code.


Daniel Berthereau
Infodoc & Knowledge management

Thank you both for your help. We got it to work!