This week I started off starting the Search API functions for Global Search. The idea is to code 3 functions for each module. These will be written in the module’s
The former two functions are used while indexing records while the last one is used to check user permissions for displaying the search results. The admin has the option to enable a particular module/resource for supporting Global Search through settings. You may view the code here.
The first function
_get_iterator($from=0) will return a recordset. I’ve already covered it in Updating Solr Index in Global Search.
The second function
_search_get_documents($id) creates a
SolrInputDocument by including data from the database by specifying fields. An example is shown below:
The tricky part is to correctly structure our indexed records. For example, for the
_get_iterator() will return the record of a particular chapter. Hence, each chapter will be a separate
SolrInputDocument having solr field
The third function maintains security by checking Moodle caps and restricting access to prohibited search results. I’ve already discussed about Global Search security in Handling security in Global Search.