Best way to query posts and order by relevancy to query

I don’t think this can be cleanly expressed in WP query API. YOu can query for posts matching all of terms in a set or any of terms in a set, but there is no concept of how many terms matched.

You would need to write either:

  1. Very custom SQL for the query you want which will implement the counting.
  2. Query loosely everything that matches and do the coun on PHP side after getting results.