Customized search result sources (Site settings > Search result sources) are one of the ways to customize search results shown in search web parts on your site. It allows to add additional search conditions which will be added to the search keywords entered by user in search textbox. Another way to do it is to change query in Content by search web parts’ properties one by one, but in this case changes will affect only single web part. While if you use customized search result source for site collection, all search web parts will use it by default (it will still possible to override search result source for particular web parts).
When create customized search result source, MS recommends to copy one of existing OTB search result sources and then change its properties:
Note that “Local SharePoint Results” source is set as default.
Here is the code which shows how we can copy “Local SharePoint Results” source programmatically to “Local SharePoint Results (customized)” and change its query text:
The method getSearchServiceApplicationProxy(), used in the example above is the following:
Note line 9 from the first example above where we call federationManager.UpdateDefaultSource() method. It sets customized search result source as default, which means all search web parts on the site will use it by default. After this search result sources will look like this in our site collection:
Everything is fine and our search web parts started to use new customized search result source. The problems begin when we will try to connect to catalog for using cross site publishing on our site collection.
Let’s assume that we have another site collection with News sub site and we want to publish Pages doclib on this sub site as catalog so content from this doclib will be available on other site collections and web applications. After we published it as catalog and made full crawl of the site which contains this doclib, appropriate catalog connection should appear in Site settings > Manage catalog connections on other site collections. However if we will go in this page on our site collection with customized default result source, there won’t be any connection available:
I.e. there are no catalog connections visible at all (if you have several sources published as catalog, no one will be shown). What is the problem?
First of all if you will create new OTB site collection and check catalog connections from there, you will find them:
So my hypothesis was that catalog connections disappear when we copy OTB result source to customized. But as it turned out the reason is not exactly in the copying. Catalog connections disappear when we set customized result source as default. They disappear not only from UI, it is also not possible to get them programmatically after that. The following code which gets catalog connection settings by name will return null: