silverstripe / silverstripe-search-service

A service-agnostic search module for Silverstripe CMS
BSD 3-Clause "New" or "Revised" License
5 stars 18 forks source link

If adding this module with no configuration, the Search Service admin is broken #83

Open GuySartorelli opened 1 year ago

GuySartorelli commented 1 year ago

After adding this module to a fresh installation of Silverstripe CMS 4.13, and not adding any specific configuration, accessing /admin/search-service/ gives the following error:

Uncaught LogicException: GridField doesn't have a modelClassName, so it doesn't know the columns of this grid.

This is because buildIndexedDocumentsList() doesn't add anything to the list if there are no indexed, which means the ArrayList doesn't ever set its data class.

Possible Solutions

Option 1

This is the most straight forward: Call $list->setDataClass(IndexedDocumentsResult::class); on the empty ArrayList as soon as it's created. That way, whether there are any indexes configured or not, the user won't get an unhelpful error.

Option 2

If the list is empty, throw a meaningful exception indicating that no indexes have been configured. This is a little less straight forward because you have to decide on the exact wording, but it does make it a lot clearer that the developer needs to perform some action.

Option 3

I don't recommend this solution, but it is one of the options available so I'll mention it anyway. If there are no indexes configured, hide the Search Service admin altogether.

michalkleiner commented 1 year ago

Option 1 with a conditional notice above the GF with a link to docs on how to configure the index.