Order By Post Type ThenBy Taxonomy

Assuming I have these custom post types:

  1. Product
  2. Video
  3. Article

And for Product (WooCommerce Product), we have many Categories, one of which is called "Parts".

I have this situation where I need to sort my search query using the following rule:

  1. Product (that is not Parts), then
  2. Product (Parts), then
  3. Video, then
  4. Article

That means if I search a keyword, say "engine", Products should come out first (with main products coming out before parts). Then Video and Article should come later.

Is it possible to capture such a use case?

I’ve solved the issue with "Sort By Post Type", referring to this post: Sort search results by post type

What puzzles me is, how can we sort by Post Type and then by Taxonomy, but only in the case if the post_type is Product.

Any idea?