Forum Discussion
Oct 08, 2020
exclude from site search but allow library search
I have a site with several libraries. One has legacy content, a few others have current content.
I want the "Search this site" search to exclude the legacy library, but I also need to be able t...
- Oct 09, 2020
Found it. It's a bit fiddly to set up. I configured the Result Sources for the site ( not the site collection or the tenant) this way:
- Site Settings > Search > Result Sources (don't use Search Result Sources under Site Collection Administration!)
- New Result Source
- Query transform uses
{searchTerms} Path:"https://thetenant.sharepoint.com/sites/thesite/thelibrary"
The crucial bit here is that the URL needs to be in double quotes. The search builder is very unhelpful, because it doesn't indicate that and doesn't put the quotes in. - Save and in the list of result sources, select the dropdown of the new source and set it as the default.
According to the KQL syntax reference, it is possible to add multiple conditions for the same property, so I can include several libraries -- and by including only some, at the same time exclude others like this
{searchTerms} Path:"https://thetenant.sharepoint.com/sites/thesite/LibraryA" OR Path:"https://thetenant.sharepoint.com/sites/thesite/LibraryB" OR Path:"https://thetenant.sharepoint.com/sites/thesite/LibraryC"
MAssarlind
Mar 27, 2025Copper Contributor
Do I understand it correctly that with your solution
- You can search in the excluded library by standing in the document library and searching.
- Documents in the excluded library do no show up when searching via
a) the search box for the site, nor
b) the global tenant search box.
Thanks!