When creating solutions based on SharePoint search, you best always define the source ID of the Local SharePoint results source with each call. By providing that source ID with each request, you make sure that the results you expect for your solutions are always the same.
The Local SharePoint results source ID you are looking for is:
The “how” depends on the type of solution you are building. For instance, if you are using CSOM or REST APIs, this would be different.
In a REST API, it would look as follows:
If your building custom solutions for environments, you do not control. It could mean that the results you were expecting are not the ones that SharePoint return. In most cases, the reason is that an admin changed the default result source, but that is not always the case.
Last week we ran into an interesting situation where results were different for app-only calls versus user calls to search. During a quick troubleshooting session with Mikael Svenson, we found that the quick fix was to include this source ID.
Be sure to always use it. That way, you keep control because the Local SharePoint results source cannot be changed.
Keep on searching