How do I sort a view by content type? I use a View to show search results (core Search module). In the view I have grouped the grid on the field "Content type". This works fine, each content type is shown under it's own title. 

But under "Sort" in the View I can only sort the content types by ASC or DESC. But I would like to use a custom sort order like "node type = product", followed by "node type = accessories" and so on.

How to do that? I have tried using hook_views_query_alter() and hook_search_api_query_alter() and a few other tings, with no luck.
If you're looking to arbitrarily order nodes, that is the use case of Weight module. The module lets you add a field to any node type with a customizable weight range. Once added to your node types, you can configure any View to use this field to sort your nodes.