Suppose that we have custom Sharepoint list with custom content type bound to it (let’s call this CT Book). In our CT there is managed metadata field Country, used for targeting books for particular country in search results. Country term set may be hierarchical and look like this:
We want to show books targeted for China only on Chinese site, for Germany on German, etc. How to do it with Sharepoint?
In order to do it we will use KQL. We may define appropriate search query rules directly in Content by search web parts, but it will be needed to be done for each web part separately. Instead we will use another approach: we will create custom search result source and will configure query rules there. With this approach we will need to do it only once and search web parts will use it by default. In one of the previous posts I showed how to create custom search result source: Problem with missing catalog connections when use customized search result source in Sharepoint 2013.
In order to filter results by appropriate country we need to use the following KQL:
With this query search results will only show those books which are targeted to Germany or to all EMEA countries.