I implemented the functionality of allowing the
admin to delete solr index recently. The code can be seen here.
Solr provides a simple way of deleting indexing using
SolrClient::deleteByQuery. I have provided two types of deleting index:
Deleting the complete index in one-go.
Deleteing index modularily. (For example, deleting index for records belonging to
The idea was to make the
admin select the delete option:
All or let the
admin choose the modules. I made these options available to the
admin through Moodle Quick Forms. Here is a code snippet:
checkbox: all the
$client->deleteByQuery('*:*') is executed, deleting the entire solr index.
If, on the other hand the
admin chooses only some modules to delete their index, the name of the modules are concatenated together separated by a string, stored as a
stdClass $data->module and passed as a parameter into the
search_delete_index function, thus executing
That for the first part: deletion.
After deletion, I need to handle the the config settings, so that the
admin is able to re-index. This is done by re-setting the values in the
config_plugin table. This is done through the below simple code:
$mods will be a simple array containing the names of all modules or only those modules whose index was selected for deletion.